Problem/motivation
phpstan helps finding code issues. Increasing the scan level increases its scrutiny.
Proposed resolution
Raise phpstan level 0 -> 1
Issue fork linkit-3615428
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
idebr commentedThe merge request contains the changes for #3613044: Fix phpcs / phpstan findings in latest pipeline and fixes the new findings for level 1:
See https://git.drupalcode.org/project/linkit/-/jobs/11396556
Comment #4
csakiistvanComment #5
csakiistvanEnvironment
This is a static analysis change, so there is nothing to reproduce in the browser. Verification is done by running PHPStan against the module.
Prerequisites
drupal/linkit:7.x-devinstalled andmglaman/phpstan-drupalavailable.phpstan.neon(this keeps the level under test coming from the module itself).Create
linkit-phpstan-run.neonin the project root:Steps
[OK] No errorsat the current level 0:level: 1inweb/modules/contrib/linkit/phpstan.neon, re-run the command above and observe the new findings. Restore the file afterwards.$default_allowedin the Linkit field widget, inject the entity type manager instead of a single storage handler in the CKEditor 5 plugin, relax theOverviewFormproperty visibility, and drop a stray blank line in the entity matcher deriver test.ddev drush crExpected results
variable.undefinederrors insrc/Plugin/Field/FieldWidget/LinkitWidget.php.Actual results
As expected. On unmodified 7.x the analysis is clean at level 0, and raising the level to 1 surfaces exactly the two findings listed in the issue:
Variable $default_allowed might not be defined.atLinkitWidget.phplines 151 and 194. After applying MR !180 the same command runs at level 1 and returns[OK] No errors. The unit and kernel suites pass with 43 tests and 402 assertions; the reported deprecations come from Drupal core and Symfony on PHP 8.5 and are unrelated to this change.Testing produced with the assistance of an LLM.
Comment #6
mark_fullmer1+ for RTBC from me!
Comment #8
idebr commentedCommitted to 7.x