Issues reported by phpstan

Created on 3 April 2024, 9 months ago
Updated 4 April 2024, 9 months ago

Problem/Motivation

PhpStan is reporting errors with the code. Some are a result of Drupal's coding standards and/or backward-compatibility but most should be fixed to keep the code up to par. I'm listing all errors but notably the return types missing in hook implementations are not something that needs fixing.

Steps to reproduce

Testing on level 9, the following errors are reported:

 ------ ------------------------------------------------------------------------
  Line   cookieinformation.install
 ------ ------------------------------------------------------------------------
  6      Function cookieinformation_update_8101() has no return type specified.
  16     Function cookieinformation_update_8102() has no return type specified.
  26     Function cookieinformation_update_8103() has no return type specified.
 ------ ------------------------------------------------------------------------

 ------ ------------------------------------------------------------------------------------------------------------------------------
  Line   cookieinformation.module
 ------ ------------------------------------------------------------------------------------------------------------------------------
  14     Function cookieinformation_help() has no return type specified.
  14     Function cookieinformation_help() has parameter $route_name with no type specified.
  31     Function cookieinformation_page_attachments_alter() has no return type specified.
  31     Function cookieinformation_page_attachments_alter() has parameter $page with no value type specified in iterable type array.
         💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
 ------ ------------------------------------------------------------------------------------------------------------------------------

 ------ ----------------------------------------------------------------------------------------------------------------------------------------
  Line   src/CookieInformationBlockBase.php
 ------ ----------------------------------------------------------------------------------------------------------------------------------------
  41     Constructor of class Drupal\cookieinformation\CookieInformationBlockBase has an unused parameter $config_factory.
  41     Constructor of class Drupal\cookieinformation\CookieInformationBlockBase has an unused parameter $language_service.
  41     Constructor of class Drupal\cookieinformation\CookieInformationBlockBase has an unused parameter $visibility_service.
  41     Method Drupal\cookieinformation\CookieInformationBlockBase::__construct() has parameter $configuration with no value type specified in
         iterable type array.
         💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
  61     Method Drupal\cookieinformation\CookieInformationBlockBase::create() has parameter $configuration with no value type specified in
         iterable type array.
         💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
  62     Unsafe usage of new static().
         💡 See: https://phpstan.org/blog/solving-phpstan-error-unsafe-usage-of-new-static
  76     \Drupal calls should be avoided in classes, use dependency injection instead
  87     Method Drupal\cookieinformation\CookieInformationBlockBase::build() return type has no value type specified in iterable type array.
         💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
 ------ ----------------------------------------------------------------------------------------------------------------------------------------

 ------ ------------------------------------------------------------------------------------------------------------------------------------------
  Line   src/Form/CookieInformationSettingsForm.php
 ------ ------------------------------------------------------------------------------------------------------------------------------------------
  22     Property Drupal\cookieinformation\Form\CookieInformationSettingsForm::$config type has no value type specified in iterable type array.
         💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
  32     Property Drupal\cookieinformation\Form\CookieInformationSettingsForm::$config (array) does not accept Drupal\Core\Config\Config.
  38     Method Drupal\cookieinformation\Form\CookieInformationSettingsForm::create() has no return type specified.
  39     Unsafe usage of new static().
         💡 See: https://phpstan.org/blog/solving-phpstan-error-unsafe-usage-of-new-static
  54     Method Drupal\cookieinformation\Form\CookieInformationSettingsForm::getEditableConfigNames() return type has no value type specified in
         iterable type array.
         💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
  61     Method Drupal\cookieinformation\Form\CookieInformationSettingsForm::buildForm() has parameter $form with no value type specified in
         iterable type array.
         💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
  61     Method Drupal\cookieinformation\Form\CookieInformationSettingsForm::buildForm() return type has no value type specified in iterable type
         array.
         💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
  66     Cannot call method get() on array.
  72     Cannot call method get() on array.
  83     Cannot call method get() on array.
  89     Cannot call method get() on array.
  95     Cannot call method get() on array.
  109    Cannot call method get() on array.
  109    Cannot call method get() on array.
  120    Cannot call method get() on array.
  126    Cannot call method get() on array.
  134    Method Drupal\cookieinformation\Form\CookieInformationSettingsForm::validateForm() has no return type specified.
  134    Method Drupal\cookieinformation\Form\CookieInformationSettingsForm::validateForm() has parameter $form with no value type specified in
         iterable type array.
         💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
  141    Method Drupal\cookieinformation\Form\CookieInformationSettingsForm::submitForm() has no return type specified.
  141    Method Drupal\cookieinformation\Form\CookieInformationSettingsForm::submitForm() has parameter $form with no value type specified in
         iterable type array.
         💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
  143    Cannot call method set() on array.
  144    Cannot call method set() on array.
  145    Cannot call method set() on array.
  146    Cannot call method set() on array.
  147    Cannot call method set() on array.
  148    Cannot call method set() on array.
  149    Cannot call method set() on array.
  150    Cannot call method set() on array.
  151    Cannot call method save() on array.
 ------ ------------------------------------------------------------------------------------------------------------------------------------------

 ------ ---------------------------------------------------------------------------------------------------------------------------------
  Line   src/LanguageService.php
 ------ ---------------------------------------------------------------------------------------------------------------------------------
  24     Property Drupal\cookieinformation\LanguageService::$rewriteLanguages type has no value type specified in iterable type array.
         💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
  34     Property Drupal\cookieinformation\LanguageService::$supportedLanguages type has no value type specified in iterable type array.
         💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
 ------ ---------------------------------------------------------------------------------------------------------------------------------

 ------ -----------------------------------------------------------------------------------------------------------------------------------------
  Line   src/Plugin/Block/CookiePolicyBlock.php
 ------ -----------------------------------------------------------------------------------------------------------------------------------------
  21     Method Drupal\cookieinformation\Plugin\Block\CookiePolicyBlock::build() return type has no value type specified in iterable type array.
         💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
  22     \Drupal calls should be avoided in classes, use dependency injection instead
 ------ -----------------------------------------------------------------------------------------------------------------------------------------

 ------ -------------------------------------------------------------------------------------------------------------------------------------
  Line   src/Plugin/Block/PrivacyControlsBlock.php
 ------ -------------------------------------------------------------------------------------------------------------------------------------
  21     Method Drupal\cookieinformation\Plugin\Block\PrivacyControlsBlock::build() return type has no value type specified in iterable type
         array.
         💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
 ------ -------------------------------------------------------------------------------------------------------------------------------------

 ------ ------------------------------------------------------------------------------------------------------------------
  Line   src/VisibilityService.php
 ------ ------------------------------------------------------------------------------------------------------------------
  106    Right side of && is always true.
  135    Right side of && is always true.
  169    Parameter #2 $patterns of method Drupal\Core\Path\PathMatcherInterface::matchPath() expects string, mixed given.
  170    Parameter #2 $patterns of method Drupal\Core\Path\PathMatcherInterface::matchPath() expects string, mixed given.
 ------ ------------------------------------------------------------------------------------------------------------------

Proposed resolution

Fix errors that can be fixed. Possibly add a baseline and a configuration for repeating the steps in the module, also adding the dependencies that enable rechecking in the future, in the composer.json of the module.

Remaining tasks

  • Fix errors
  • Add baseline and configuration for phpstan
  • Add mglaman/phpstan-drupal as a dev dependency

User interface changes

None

API changes

None

Data model changes

None

📌 Task
Status

Active

Version

2.1

Component

Code

Created by

🇫🇮Finland kekkis Pirkkala

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024