phpcs-import-detection icon indicating copy to clipboard operation
phpcs-import-detection copied to clipboard

PHP8 Nullsafe operator triggers RequireImports.Symbol

Open BenceSzalai opened this issue 4 years ago • 3 comments

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!

BenceSzalai avatar May 03 '21 13:05 BenceSzalai

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.

sirbrillig avatar May 03 '21 16:05 sirbrillig

I just opened this same bug (https://github.com/squizlabs/PHP_CodeSniffer/issues/3374) on PHP CodeSniffer by mistake. Just linking here for reference.

underdpt avatar Jun 09 '21 16:06 underdpt

Thanks. Sorry I haven't had a chance to get to this yet. It's on my list.

sirbrillig avatar Jun 10 '21 21:06 sirbrillig