Page MenuHomePhabricator

ExtendClassUsageSniff is buggy because it maintains state in the sniff
Closed, ResolvedPublic

Description

The ExtendClassUsageSniff has two private member variables that it uses to maintain state inside the sniff. This is unreliable in PHPCS 3.0+ and should be avoided.

I can reliably reproduce this on the Translate extension:

km@km-pt ~/g/m/c/e/Translate> composer test
> parallel-lint . --exclude vendor --exclude node_modules --exclude extensions
PHP 7.1.10 | 10 parallel jobs
............................................................  60/248 (24 %)
............................................................ 120/248 (48 %)
............................................................ 180/248 (72 %)
............................................................ 240/248 (96 %)
........                                                     248/248 (100 %)


Checked 248 files in 1.3 seconds
No syntax error found
> phpcs -p -s
............................................................  60 / 248 (24%)
............................................................ 120 / 248 (48%)
..........................................W................. 180 / 248 (73%)
............................................................ 240 / 248 (97%)
........                                                     248 / 248 (100%)



FILE: .../km/gerrit/mediawiki/core/extensions/Translate/utils/ToolBox.php
----------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
----------------------------------------------------------------------
 30 | WARNING | Should use function $this->msg() rather than function
    |         | wfMessage() .
    |         | (MediaWiki.Usage.ExtendClassUsage.FunctionVarUsage)
----------------------------------------------------------------------

Time: 18.46 secs; Memory: 20Mb

While doing ./vendor/bin/phpcs utils/ToolBox.php individually has no issue, pointing to a state problem.

Event Timeline

Change 400243 had a related patch set uploaded (by Umherirrender; owner: Umherirrender):
[mediawiki/tools/codesniffer@master] Rework ExtendClassUageSniff to avoid private class member

https://gerrit.wikimedia.org/r/400243

Umherirrender triaged this task as Medium priority.

Change 400243 merged by jenkins-bot:
[mediawiki/tools/codesniffer@master] Rework ExtendClassUageSniff to avoid private class member

https://gerrit.wikimedia.org/r/400243