PHP_CodeSniffer
PHP_CodeSniffer copied to clipboard
False positive on `Generic.PHP.ForbiddenFunctions.FoundWithAlternative`
Describe the bug
This sniff incorrectly reports an error while using in my case \Psl\Str\join
function and reports forbidden use of the native PHP function
Code sample
src/a.php
<?php
use function Psl\Str\join;
class A {
public function get(): string
{
$a = ['bar', 'baz', 'foo'];
return join($a, ',');
}
}
phpcs.xml
<?xml version="1.0"?>
<ruleset
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd"
>
<arg name="basepath" value="."/>
<arg name="cache" value=".phpcs-cache"/>
<rule ref="Generic.PHP.ForbiddenFunctions">
<properties>
<property name="forbiddenFunctions" type="array">
<element key="join" value="implode"/>
</property>
</properties>
</rule>
<file>src</file>
</ruleset>
Expected behavior
No errors
Versions (please complete the following information)
PHP version | 8.3 |
PHP_CodeSniffer version | 3.9 & master |
Standard | Generic |
Please confirm:
- [x] I have searched the issue list and am not opening a duplicate issue.
- [x] I confirm that this bug is a bug in PHP_CodeSniffer and not in one of the external standards.
- [x] I have verified the issue still exists in the
master
branch of PHP_CodeSniffer.