Parent as a method name causes false positive
afilina opened this issue · comments
Bug Description
Parent as a method name is causing two false positives.
Given the following reproduction Scenario
The issue happens when running this command:
phpcs -ps file.php --standard=PHPCompatibility --runtime-set testVersion 8.1
... over a file containing this code:
class PHP4DOMTree {
function &parent() {
$parent =& PHP4DOMTree::from_DOMDocument($this->_element->parent());
return $parent;
}
}
I'd expect the following behaviour
No errors or warnings.
Instead this happened
Flags an issue:
- PHPCompatibility.Classes.RemovedOrphanedParent.Deprecated
Environment
Environment | Answer |
---|---|
PHP version | 8.2.3 |
PHP_CodeSniffer version | 3.5.3 |
PHPCompatibility version | (not sure how to check inside PHPCO, lastest as of 2023-04-11) |
Install type | PHPCO |
Tested Against develop
branch?
- I have verified the issue still exists in the
develop
branch of PHPCompatibility.
@afilina Thanks for reporting this. Looks like the underlying issue is related to a PHPCS tokenizer issue (parent
in the function declaration being tokenized as T_PARENT
instead of T_STRING
).
Having said that, I can only reproduce one of the issues:
FILE: phpcompat-1489.php
------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
------------------------------------------------------------------------------------------------------------------------------------------------------
4 | ERROR | Using "parent" inside a class without parent is deprecated since PHP 7.4 and removed since PHP 8.0
| | (PHPCompatibility.Classes.RemovedOrphanedParent.Removed)
------------------------------------------------------------------------------------------------------------------------------------------------------
I cannot seem to get the PHPCompatibility.FunctionNameRestrictions.RemovedPHP4StyleConstructors.Found
error.
Could you double-check and if necessary provide additional information on how to reproduce that one ?
PR squizlabs/PHP_CodeSniffer#3797 addresses the upstream tokenizer issue.
Loosely related: PR PHPCSStandards/PHPCSUtils#452
@afilina FYI: I have lined up a fix for the RemovedOrphanedParent
sniff, which will be pulled & merged before the 10.0.0 release.
@jrfnl You're right. The other issue had nothing to do with this example. I misinterpreted it in a much bigger context. There's only the RemovedOrphanedParent
issue. Thanks!