phpcs-import-detection
phpcs-import-detection copied to clipboard
PHP8 Nullsafe operator triggers RequireImports.Symbol
I'm trying to use the PHP8 nullsafe operator but I'm getting an issue from PHP Code Sniffer as ImportDetection.Imports.RequireImports.Symbol.
So in the context of a class method this is fine:
$this->property;
but I get an issue for this:
$this?->property;
claiming Found unimported symbol 'property'.
The same is happening outside of a class method context too, when trying to access a property of an object using the ?-> operator.
This is happening with php_codesniffer v3.6.0 and phpcs-import-detection v1.3.1.
Please let me know if I'm doing something wrong or if you need more info from me!
Thanks for the report! This is likely happening because the sniff is not aware of the nullsafe operator syntax in php 8. That can be fixed.
I just opened this same bug (https://github.com/squizlabs/PHP_CodeSniffer/issues/3374) on PHP CodeSniffer by mistake. Just linking here for reference.
Thanks. Sorry I haven't had a chance to get to this yet. It's on my list.