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

Add phpcs rule to detect unused variables; Fix existing issues #17300

Conversation

jorgefilipecosta
Copy link
Member

Description

This PR adds a PHP rule to detect unused PHP variables. And fixes the problems detected by this rule.

The fact we have many existing problems is a small proof that this rule is useful.

How has this been tested?

I executed composer lint.
I verified no lint error were detected.

@jorgefilipecosta jorgefilipecosta added the [Type] Code Quality Issues or PRs that relate to code quality label Sep 2, 2019
@jorgefilipecosta jorgefilipecosta force-pushed the add/phpcs-rule-to-detect-unused-variable-fix-existing-problems branch 3 times, most recently from c7c3977 to d316a00 Compare September 2, 2019 16:58
@jorgefilipecosta jorgefilipecosta changed the title Add phpcs rule to detect unused variable; Fix existing problems. Add phpcs rule to detect unused variables; Fix existing problems. Sep 2, 2019
@gziolo gziolo requested a review from a team September 16, 2019 03:56
phpcs.xml.dist Outdated
@@ -10,6 +10,11 @@
<rule ref="WordPress.WP.I18n"/>
<config name="text_domain" value="gutenberg,default"/>

<rule ref="VariableAnalysis.CodeAnalysis.VariableAnalysis">
<properties>
<property name="allowUnusedFunctionParameters" value="true"/>
Copy link
Member

Choose a reason for hiding this comment

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

What about using allowUnusedParametersBeforeUsed instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hi @swissspidy, the rule was causing problems when we need in a class to overload a function defined in the base class without necessarily using all the parameters.
But on second thought these cases are rare and we should not optimize for them, so I followed your suggestion and disabled the rule on the specific cases where it was problematic.

@jorgefilipecosta jorgefilipecosta force-pushed the add/phpcs-rule-to-detect-unused-variable-fix-existing-problems branch 2 times, most recently from 0bb31b0 to af896cb Compare September 18, 2019 16:23
* @return WP_Error|bool True if the request has permission, WP_Error object otherwise.
*
* This function is overloading a function defined in WP_REST_Controller so it should have the same parameters.
Copy link
Contributor

Choose a reason for hiding this comment

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

Little confused by the comment as the $request param has been removed in the pr.

I also couldn't see permissions_check defined in WP_REST_Controller. Instead there are individual methods (get_items_permissions_check, get_item_permissions_check, create_item_permissions_check ... ).

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice catch the disable is not needed here I removed it 👍

@jorgefilipecosta jorgefilipecosta force-pushed the add/phpcs-rule-to-detect-unused-variable-fix-existing-problems branch from af896cb to 36188a8 Compare September 24, 2019 10:06
@jorgefilipecosta jorgefilipecosta force-pushed the add/phpcs-rule-to-detect-unused-variable-fix-existing-problems branch from 36188a8 to 06e606b Compare September 25, 2019 09:19
@jorgefilipecosta jorgefilipecosta changed the title Add phpcs rule to detect unused variables; Fix existing problems. Add phpcs rule to detect unused variables; Fix existing issues Sep 25, 2019
@jorgefilipecosta jorgefilipecosta merged commit a56daeb into master Sep 25, 2019
@jorgefilipecosta jorgefilipecosta deleted the add/phpcs-rule-to-detect-unused-variable-fix-existing-problems branch September 25, 2019 09:44
@youknowriad youknowriad added this to the Gutenberg 6.6 milestone Sep 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Code Quality Issues or PRs that relate to code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants