-
-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,33 @@ | ||||||||||||||||||||||
<?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" | ||||||||||||||||||||||
> | ||||||||||||||||||||||
<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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||
]]> | ||||||||||||||||||||||
</standard> | ||||||||||||||||||||||
<code_comparison> | ||||||||||||||||||||||
<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 ); | ||||||||||||||||||||||
Comment on lines
+12
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 $post_data = array(
'title' => 'My title',
'content' => 'My content',
'ID' => 123
);
<em>echo $post_data['title'];</em> The There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||||||||||||||||||||||
]]> | ||||||||||||||||||||||
</code> | ||||||||||||||||||||||
<code title="Invalid: use `extract()` function"> | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||
<![CDATA[ | ||||||||||||||||||||||
$var_array = array( | ||||||||||||||||||||||
"title" => "My title", | ||||||||||||||||||||||
"content" => "My content", | ||||||||||||||||||||||
"ID" => 123 | ||||||||||||||||||||||
); | ||||||||||||||||||||||
Comment on lines
+24
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
The code samples should comply with WPCS (aside from the issue being demonstrated). WPCS would flag the unnecessary use of double quotes here. |
||||||||||||||||||||||
extract( $var_array, EXTR_OVERWRITE ); | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
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 |
||||||||||||||||||||||
]]> | ||||||||||||||||||||||
</code> | ||||||||||||||||||||||
</code_comparison> | ||||||||||||||||||||||
</documentation> |
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.