Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds documentation for PregQuoteDelimiter #2487

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions WordPress/Docs/PHP/PregQuoteDelimiterStandard.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0"?>
<documentation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://phpcsstandards.github.io/PHPCSDevTools/phpcsdocs.xsd"
title="Preg Quote Delimiter"
>
<standard>
<![CDATA[
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<![CDATA should be aligned with <standard>. Here is an example of a recently added documentation: https://github.com/rodrigoprimo/WordPress-Coding-Standards/blob/694bdf514d518004cefc0a22923fedeb0091eaca/WordPress/Docs/WP/GetMetaSingleStandard.xml#L7

Here and in the other places where <![CDATA is used.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aligned items.

Passing the $delimiter parameter to preg_quote() is strongly recommended to ensure the delimiter required by the PCRE functions are escaped.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to ensure the delimiter required by the PCRE functions are escaped.

I haven't looked deeply into this so I might be missing something, but I'm not sure this is the reason to recommend that the $delimiter parameter is passed.

I got this from the issue where this sniff was introduced:

Verify that the optional second parameter $delimiter of preg_quote() is always passed.
Too often I come across code where it is missing and unless it is passed, the default / delimiters are presumed, which is often wrong.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the description and changed the example valid code to be one from WordPress core.

]]>
</standard>

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This newline is not necessary.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed unnecessary newlines.

<code_comparison>
<code title="Valid: The delimiter is included.">
<![CDATA[
preg_quote( $str, '/' );
]]>
</code>
<code title="Invalid: The delimiter is not included.">
<![CDATA[
preg_quote( $str );
]]>
</code>
</code_comparison>
</documentation>
Loading