New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unsafe usage of new static() errors #136
Comments
For reference: phpstan/phpstan#2773 |
Any clues how to avoid these errors? |
No idea how phpstan works, but if it was hookable, the extension could check whether this is either a ContainerInjectionInterface or ContainerFactoryPluginInterface, and pass the check in that case; which should cover most such cases. |
Following this, since as far as I know, new static is intentional solution. Changing it to new self would mean that every child class would have to override While I agree with @fgm I don't think there is no other function than |
We need to alter the |
In mglaman#136 we accidentally ignored all errors instead of just the one error: "Unsafe usage of new static()." This results in drupal-check failing with the following message: -- -------------------------------------------------------------------------- Error -- -------------------------------------------------------------------------- Ignored error #Unsafe usage of new static()# has an unescaped '()' which leads to ignoring all errors. Use '\(\)' instead. -- --------------------------------------------------------------------------
Note that the failing tests hid this error:
I opened a PR to fix this in #191. |
How is drupal-check installed?
Environment:
Describe the bug
Getting errors with standard Drupal plugin code which implements the \Drupal\Core\DependencyInjection\ContainerInjectionInterface::create() method:
The code is usually implemented in the following way:
Should this error be excluded from drupal-check runs? Changing all of our code to use
new self
instead ofnew static
means we have a lot of replacement to do, and fixing a lot of core code...Console output
vendor/bin/drupal-check -a web/modules/custom
The text was updated successfully, but these errors were encountered: