Problem/Motivation
phpstan detects many inconsistencies in the code. Would be great to have all reported errors by phpstan fixed.
Current problems (run phpstan because this would probably quickly outdated)
------ -------------------------------------------------------------------
Line node_authlink.install
------ -------------------------------------------------------------------
41 Variable $messenger in isset() always exists and is not nullable.
------ -------------------------------------------------------------------
------ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Line node_authlink.module
------ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
31 Call to an undefined method Drupal\node\Entity\NodeType::getEntity().
152 Cannot call method fetchCol() on Drupal\Core\Database\StatementInterface|null.
177 Cannot call method fetchCol() on Drupal\Core\Database\StatementInterface|null.
205 Cannot call method fetchField() on Drupal\Core\Database\StatementInterface|int|string|null.
249 Function node_authlink_get_url() should return Drupal\Core\Url|null but returns false.
252 Call to an undefined method object::id().
422 Parameter #2 $value of method Drupal\Core\Database\Query\ConditionInterface::condition() expects array|Drupal\Core\Database\Query\SelectInterface|string|null, int|string|null given.
423 Parameter #2 $value of method Drupal\Core\Database\Query\ConditionInterface::condition() expects array|Drupal\Core\Database\Query\SelectInterface|string|null, (float|int) given.
424 Cannot call method fetchCol() on Drupal\Core\Database\StatementInterface|null.
482 Cannot call method toString() on Drupal\Core\Url|null.
486 Cannot call method toString() on Drupal\Core\Url|null.
490 Cannot call method toString() on Drupal\Core\Url|null.
------ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Line src/Access/NodeAuthlinkGroupContentAccessControlHandler.php
------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
16 Class Drupal\node_authlink\Plugin\NodeAuthlinkGroupContentAccessControlHandler extends unknown class Drupal\group\Plugin\GroupContentAccessControlHandler.
💡 Learn more at https://phpstan.org/user-guide/discovering-symbols
22 \Drupal calls should be avoided in classes, use dependency injection instead
30 Drupal\node_authlink\Plugin\NodeAuthlinkGroupContentAccessControlHandler::entityAccess() calls parent::entityAccess() but Drupal\node_authlink\Plugin\NodeAuthlinkGroupContentAccessControlHandler does not extend any class.
------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------ ------------------------------------------------------------------------------
Line src/Access/NodeAuthlinkNodeAccessControlHandler.php
------ ------------------------------------------------------------------------------
22 \Drupal calls should be avoided in classes, use dependency injection instead
26 \Drupal calls should be avoided in classes, use dependency injection instead
------ ------------------------------------------------------------------------------
------ ------------------------------------------------------------------------------------------
Line src/Access/NodeRevisionAccessCheck.php
------ ------------------------------------------------------------------------------------------
42 Variable $requirements in PHPDoc tag @var does not match assigned variable $requirement.
43 Parameter #2 $string of function explode expects string, string|null given.
57 Call to an undefined method Drupal\Core\Access\AccessResultInterface::cachePerUser().
------ ------------------------------------------------------------------------------------------
------ -----------------------------------------------------------------------------------------------------------------------
Line src/Form/NodeAuthlinkNodeForm.php
------ -----------------------------------------------------------------------------------------------------------------------
35 Access to an undefined property Drupal\node_authlink\Form\NodeAuthlinkNodeForm::$entityTypeManager.
💡 Learn more: https://phpstan.org/blog/solving-phpstan-access-to-undefined-property
36 Access to an undefined property Drupal\node_authlink\Form\NodeAuthlinkNodeForm::$linkGenerator.
💡 Learn more: https://phpstan.org/blog/solving-phpstan-access-to-undefined-property
37 Access to an undefined property Drupal\node_authlink\Form\NodeAuthlinkNodeForm::$dateFormatter.
💡 Learn more: https://phpstan.org/blog/solving-phpstan-access-to-undefined-property
44 Unsafe usage of new static().
💡 See: https://phpstan.org/blog/solving-phpstan-error-unsafe-usage-of-new-static
77 Access to an undefined property Drupal\node_authlink\Form\NodeAuthlinkNodeForm::$entityTypeManager.
💡 Learn more: https://phpstan.org/blog/solving-phpstan-access-to-undefined-property
78 Access to an undefined property Drupal\node_authlink\Form\NodeAuthlinkNodeForm::$linkGenerator.
💡 Learn more: https://phpstan.org/blog/solving-phpstan-access-to-undefined-property
79 Access to an undefined property Drupal\node_authlink\Form\NodeAuthlinkNodeForm::$dateFormatter.
💡 Learn more: https://phpstan.org/blog/solving-phpstan-access-to-undefined-property
81 Parameter #6 $bundle_grants of class Drupal\node_authlink\Form\NodeFormManager constructor expects array, true given.
136 Cannot call method bundle() on Drupal\node\Entity\Node|null.
136 Cannot call method bundle() on Drupal\node\Entity\Node|null.
136 Cannot call method bundle() on Drupal\node\Entity\Node|null.
------ -----------------------------------------------------------------------------------------------------------------------
[ERROR] Found 32 errors
Steps to reproduce
Run phpstan. I'm using Metadrop Boilerplate because it includes a docker env with phpstan preconfigured for Drupal. So, create a new project using composer, require node authlink, and inside the php container (make up, make shell) run:
phpstan analyze web/modules/development/node_authlink/
Proposed resolution
Fix errors.
Remaining tasks
Do it.
User interface changes
TBD.
API changes
TBD.
Data model changes
TBD.
Issue fork node_authlink-3380739
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 #2
tunicComment #4
tunicHi, rishabjasrotia , you have created an issue fork, are you planning to work on this?
Comment #5
rishabjasrotia commentedYes I do
Comment #6
rishabjasrotia commentedComment #8
rishabjasrotia commentedError1: We can ignore Unsafe usage of new static().
Ref: https://blogs.perficient.com/2023/01/17/drupal-fix-coding-issues-using-p....
Error 2: Already handled in Drupal 10 Ref: https://www.drupal.org/project/drupal/issues/3344903
Parameter #2 $value of method Drupal\Core\Database\Query\ConditionInterface::condition() expects
array|Drupal\Core\Database\Query\SelectInterface|string|null, int|string|null given.
Comment #9
rishabjasrotia commentedComment #10
tunicI confirm what it is said on #8 about errors 2 and 3. Thanks for pointing that out.
Comment #11
tunicComment #12
rishabjasrotia commentedHello @tunic,
I think for some errors reported by PHPStan may be false positive based on usage in the node_authlink module. We can ignore them!!!
Let me know what you think?
Comment #13
rishabjasrotia commentedComment #15
tunicOk, I've fixed a few more errors and I think we are done now. Thanks for your work!