-
-
Notifications
You must be signed in to change notification settings - Fork 488
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
DontExtractStandard.xml file creation #2456
base: develop
Are you sure you want to change the base?
Conversation
my_extract( $var_array, EXTR_OVERWRITE ); | ||
]]> | ||
</code> | ||
<code title="Invalid: "> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line seems incomplete?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you're right, I fixed the description of invalid code sample
fix incomplete description of invalid use case description
<code title="Valid: Similarly named functions or methods are fine"> | ||
<![CDATA[ | ||
$var_array = array( | ||
"title" => "My title", | ||
"content" => "My content", | ||
"ID" => 123 | ||
); | ||
my_extract( $var_array, EXTR_OVERWRITE ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than giving a valid example as being "Use a similarly name function", I'd suggest demonstrating how to use keys from the $var_array
directly. I'd also suggest renaming the variable to something a little more contextual.
$post_data = array(
'title' => 'My title',
'content' => 'My content',
'ID' => 123
);
<em>echo $post_data['title'];</em>
The <em>
</em>
is used here as that's the bit we're emphasising. It should be added around the extract()
call in the Invalid section too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @GaryJones' remark here. The "Valid" example should show the correct way of doing it, not what's "tolerated" to prevent false positives.
When updating the code sample, please also update the "Valid" description.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aiolachiara Thank you for working on this!
I agree with the remark @GaryJones left previously and have added a few more nitpick comments inline.
I look forward to seeing the next iteration of the PR!
<?xml version="1.0"?> | ||
<documentation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="https://phpcsstandards.github.io/PHPCSDevTools/phpcsdocs.xsd" | ||
title="Don't exctract" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
title="Don't exctract" | |
title="Don't extract" |
> | ||
<standard> | ||
<![CDATA[ | ||
Restricts the usage of `extract()` php function. It makes code harder to debug and harder to understand and may cause conflicts on variables names. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Restricts the usage of `extract()` php function. It makes code harder to debug and harder to understand and may cause conflicts on variables names. | |
Forbids the usage of the PHP native `extract()` function. Using `extract()` makes code harder to debug, harder to understand and may cause unexpected behaviour when variables names conflict. |
"content" => "My content", | ||
"ID" => 123 | ||
); | ||
extract( $var_array, EXTR_OVERWRITE ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extract( $var_array, EXTR_OVERWRITE ); | |
extract( $var_array ); |
The second parameter is optional and rarely passed, so no need to include it in the example.
Another reason to remove it, is that it could be confusing to people - "but the example says it is only forbidden when used with EXTR_OVERWRITE
...".
$var_array = array( | ||
"title" => "My title", | ||
"content" => "My content", | ||
"ID" => 123 | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$var_array = array( | |
"title" => "My title", | |
"content" => "My content", | |
"ID" => 123 | |
); | |
$var_array = array( | |
'title' => 'My title', | |
'content' => 'My content', | |
'ID' => 123 | |
); |
The code samples should comply with WPCS (aside from the issue being demonstrated). WPCS would flag the unnecessary use of double quotes here.
my_extract( $var_array, EXTR_OVERWRITE ); | ||
]]> | ||
</code> | ||
<code title="Invalid: use `extract()` function"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<code title="Invalid: use `extract()` function"> | |
<code title="Invalid: Using the `extract()` function."> |
<code title="Valid: Similarly named functions or methods are fine"> | ||
<![CDATA[ | ||
$var_array = array( | ||
"title" => "My title", | ||
"content" => "My content", | ||
"ID" => 123 | ||
); | ||
my_extract( $var_array, EXTR_OVERWRITE ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @GaryJones' remark here. The "Valid" example should show the correct way of doing it, not what's "tolerated" to prevent false positives.
When updating the code sample, please also update the "Valid" description.
Related to #1722