After I ran updates for core and contrib modules, i tested the custom coding using PHPCS.
The test received multiple errors for the create function:
The code:
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('image.factory')
);
}
Warnings received:
[exec] 59 | WARNING | Unused static variable $container.
[exec] 59 | WARNING | Unused static variable $configuration.
[exec] 59 | WARNING | Unused static variable $plugin_id.
[exec] 59 | WARNING | Unused static variable $plugin_definition.
[exec] 61 | WARNING | Redeclaration of function parameter $configuration as static variable.
[exec] 62 | WARNING | Redeclaration of function parameter $plugin_id as static variable.
[exec] 63 | WARNING | Redeclaration of function parameter $plugin_definition as static variable.
[exec] 64 | WARNING | Redeclaration of function parameter $container as static variable.
These warnings can be fixed if you return a new self object instead of a static object, but this will lead to a PHPSTAN error - as the create() function does only accept a static object.
I tried to find information about the reason why this happends - but I was out of luck. Does anyone has more information about this issue?
Comments
Comment #2
arkener commentedThis issue is caused by an issue upstream in the latest release of the PHP_CodeSniffer VariableAnalysis package.
As a workaround you can lock this package to version 2.11.4 using:
composer require sirbrillig/phpcs-variable-analysis "<=2.11.4"Or applying the attached patch to
sirbrillig/phpcs-variable-analysisComment #3
marcellinostroosnijder commented@Arkener
Thanks! Your patch works!
Comment #4
arkener commentedThis issue has been fixed upstream in
sirbrillig/phpcs-variable-analysisversion 2.11.6Thanks @MarcellinoStroosnijder for creating this issue!
Comment #5
marcellinostroosnijder commentedThanks for the fix @Arkener!
Comment #6
br0kenStill having this problem with
sirbrillig/phpcs-variable-analysis:2.11.6. Am I missing something?Coder 8.3.15
PHP_CodeSniffer version 3.7.1
Comment #7
arkener commented@BR0kEN, are you able to provide an example of the code where this issue occurs for you and the output of the sniff?
Comment #8
br0kenBasically, any anonymous static function with parameters produces this.
Comment #9
arkener commentedYou're right, it seems to still be broken on static arrow functions. I've created an issue upstream and created a PR to fix this issue. The attached patch, applied on
sirbrillig/phpcs-variable-analysis:2.11.6should fix this issue.Comment #10
br0kenYup, the patch works. Thanks.
Btw, did you know you can add
.diffor.patchto any Github PR or even commit to get the applicable patch file?Comment #11
arkener commented@BR0kEN Yes, I tend to copy the patch here as well for users that aren't used to this feature, though you're correct that we can just as well place the link to the GitHub patch here.
This issue has been fixed upstream in
sirbrillig/phpcs-variable-analysis:2.11.7Comment #12
arkener commented