Add return type hints

Created on 10 August 2022, over 2 years ago
Updated 7 October 2024, about 1 month ago

Problem/Motivation

I have run PHPStan with the following phpstan.neon to get an overview about the overall code quality.
As of official minimum version of PHP 8.0 or 7.4 we can add all related type hints and return types and fix the rest of all.

PHPStan results

 ------ ---------------------------------------------------------------
  Line   etracker.install
 ------ ---------------------------------------------------------------
  13     Function etracker_update_8101() has no return type specified.
  31     Function etracker_update_8102() has no return type specified.
 ------ ---------------------------------------------------------------

 ------ ---------------------------------------------------------------------------------------------------------------------------------
  Line   etracker.module
 ------ ---------------------------------------------------------------------------------------------------------------------------------
  21     Function etracker_help() has no return type specified.
  21     Function etracker_help() has parameter $route_name with no type specified.
  31     Function etracker_library_info_build() has no return type specified.
  94     Function etracker_preprocess_page() has no return type specified.
  94     Function etracker_preprocess_page() has parameter $variables with no type specified.
  148    Function etracker_page_attachments_alter() has no return type specified.
  193    Instanceof between array|string|null and Drupal\Core\StringTranslation\TranslatableMarkup will always evaluate to false.
  195    PHPDoc tag @var has invalid value ($titleObject Drupal\Core\StringTranslation\TranslatableMarkup): Unexpected token
         "$titleObject", expected type at offset 9
  223    Parameter #1 $str of function rawurlencode expects string, mixed given.
  248    Function etracker_form_user_form_alter() has no return type specified.
  248    Function etracker_form_user_form_alter() has parameter $form with no type specified.
  251    PHPDoc tag @var has invalid value ($interface \Drupal\Core\Entity\EntityFormInterface): Unexpected token "$interface", expected
         type at offset 9
  252    Call to an undefined method Drupal\Core\Form\FormInterface::getEntity().
  304    Function etracker_form_user_form_submit() has no return type specified.
  304    Function etracker_form_user_form_submit() has parameter $form with no type specified.
  328    PHPDoc tag @var has invalid value ($breadcrumb Drupal\Core\Breadcrumb\Breadcrumb): Unexpected token "$breadcrumb", expected
         type at offset 9
  339    Parameter #2 $array of function implode expects array<string>, array<int, array|Drupal\Component\Render\MarkupInterface|string>
         given.
  369    Result of && is always false.
  369    Variable $key in isset() always exists and is always null.
  369    Variable $value in isset() always exists and is always null.
 ------ --------------------------------------------------------------------------------------------------------------------------------- 
 ------ -----------------------------------------------------------------------
  Line   modules\cookies_etracker\cookies_etracker.install
 ------ -----------------------------------------------------------------------
  13     Function cookies_etracker_install() has no return type specified.
  36     Function cookies_etracker_update_8001() has no return type specified.
  50     Function cookies_etracker_update_8002() has no return type specified.
 ------ -----------------------------------------------------------------------

 ------ ---------------------------------------------------------------------------------------------------------------
  Line   modules\cookies_etracker\cookies_etracker.module
 ------ ---------------------------------------------------------------------------------------------------------------
  16     Function cookies_etracker_help() has no return type specified.
  16     Function cookies_etracker_help() has parameter $route_name with no type specified.
  46     Function cookies_etracker_library_info_alter() has no return type specified.
  46     Function cookies_etracker_library_info_alter() has parameter $extension with no type specified.
  46     Function cookies_etracker_library_info_alter() has parameter $libraries with no type specified.
  100    Function cookies_etracker_page_attachments() has no return type specified.
  100    Function cookies_etracker_page_attachments() has parameter $page with no type specified.
  151    Function cookies_etracker_form_etracker_admin_settings_alter() has no return type specified.
  151    Function cookies_etracker_form_etracker_admin_settings_alter() has parameter $form with no type specified.
  151    Function cookies_etracker_form_etracker_admin_settings_alter() has parameter $form_id with no type specified.
  214    Function _cookies_etracker_form_etracker_admin_settings_save() has no return type specified.
 ------ ---------------------------------------------------------------------------------------------------------------

 ------ --------------------------------------------------------------------------------------------------------------------------------
  Line   modules\cookies_etracker\tests\src\FunctionalJavascript\CookieTrackingTest.php
 ------ --------------------------------------------------------------------------------------------------------------------------------
  84     Method Drupal\Tests\cookies_etracker\FunctionalJavascript\CookieTrackingTest::testCookieEtrackerBlockingModeDefault() has no
         return type specified.
  116    Method Drupal\Tests\cookies_etracker\FunctionalJavascript\CookieTrackingTest::testCookieEtrackerBlockingModeKnockedOutCookie()
         has no return type specified.
  152    Method Drupal\Tests\cookies_etracker\FunctionalJavascript\CookieTrackingTest::testCookieEtrackerBlockingModeKnockedOutScript()
         has no return type specified.
  186    Method
         Drupal\Tests\cookies_etracker\FunctionalJavascript\CookieTrackingTest::testCookieEtrackerBlockingModeIgnoreConsentScript() has
         no return type specified.
 ------ --------------------------------------------------------------------------------------------------------------------------------

 ------ ---------------------------------------------------------------------------------------------------------------------------------
  Line   modules\cookies_etracker\tests\src\Functional\EtrackerCookiesFunctionalTest.php
 ------ ---------------------------------------------------------------------------------------------------------------------------------
  78     Method Drupal\Tests\cookies_etracker\Functional\EtrackerCookiesFunctionalTest::testLibraryExists() has no return type
         specified.
  91     Method Drupal\Tests\cookies_etracker\Functional\EtrackerCookiesFunctionalTest::testScriptIsTextPlainBeforeConsentInHeader() has
         no return type specified.
  119    Method Drupal\Tests\cookies_etracker\Functional\EtrackerCookiesFunctionalTest::testScriptIsTextPlainBeforeConsentInFooter() has
         no return type specified.
 ------ ---------------------------------------------------------------------------------------------------------------------------------

 ------ --------------------------------------------------------------------------------------------------------------------
  Line   src\EventSubscriber\CspSubscriber.php
 ------ --------------------------------------------------------------------------------------------------------------------
  35     Method Drupal\etracker\EventSubscriber\CspSubscriber::onCspPolicyAlter() has no return type specified.
  35     Parameter $alterEvent of method Drupal\etracker\EventSubscriber\CspSubscriber::onCspPolicyAlter() has invalid type
         Drupal\csp\Event\PolicyAlterEvent.
  35     Parameter $alterEvent of method Drupal\etracker\EventSubscriber\CspSubscriber::onCspPolicyAlter() has invalid type
         Drupal\csp\Event\PolicyAlterEvent.
  36     Call to method getPolicy() on an unknown class Drupal\csp\Event\PolicyAlterEvent.
         💡 Learn more at https://phpstan.org/user-guide/discovering-symbols
 ------ --------------------------------------------------------------------------------------------------------------------

 ------ -----------------------------------------------------------------------------------------------------
  Line   src\Form\EtrackerAdminSettingsForm.php
 ------ -----------------------------------------------------------------------------------------------------
  262    Method Drupal\etracker\Form\EtrackerAdminSettingsForm::validateForm() has no return type specified.
  293    Method Drupal\etracker\Form\EtrackerAdminSettingsForm::submitForm() has no return type specified.
 ------ -----------------------------------------------------------------------------------------------------

 ------ ------------------------------------------------------------------------------------------------------------------
  Line   tests\src\Functional\AdminSettingsFormTests.php
 ------ ------------------------------------------------------------------------------------------------------------------
  61     Method Drupal\Tests\etracker\Functional\AdminSettingsFormTests::testPageTracking() has no return type specified.
 ------ ------------------------------------------------------------------------------------------------------------------

 ------ ---------------------------------------------------------------------------------------------------------------------------------
  Line   tests\src\Functional\ETrackerFunctionalTests.php
 ------ ---------------------------------------------------------------------------------------------------------------------------------
  77     Method Drupal\Tests\etracker\Functional\ETrackerFunctionalTests::testEtrackerAccessFormAsAnonymous() has no return type
         specified.
  89     Method Drupal\Tests\etracker\Functional\ETrackerFunctionalTests::testEtrackerAccessFormAsAdmin() has no return type specified.
  102    Method Drupal\Tests\etracker\Functional\ETrackerFunctionalTests::testEtrackerFormAccountKey() has no return type specified.
  123    Method Drupal\Tests\etracker\Functional\ETrackerFunctionalTests::testEtrackerInHeaderExists() has no return type specified.
  149    Method Drupal\Tests\etracker\Functional\ETrackerFunctionalTests::testEtrackerInFooterExists() has no return type specified.
  170    Method Drupal\Tests\etracker\Functional\ETrackerFunctionalTests::testDataBlockCookieValueEnabled() has no return type
         specified.
  190    Method Drupal\Tests\etracker\Functional\ETrackerFunctionalTests::testDataRespectDntValueEnabled() has no return type specified.
  210    Method Drupal\Tests\etracker\Functional\ETrackerFunctionalTests::testExclusionByPathWithSlashUrl() has no return type
         specified.
  240    Method Drupal\Tests\etracker\Functional\ETrackerFunctionalTests::testInclusionByPathWithSlashUrl() has no return type
         specified.
  270    Method Drupal\Tests\etracker\Functional\ETrackerFunctionalTests::testExclusionByPathWithoutSlashUrl() has no return type
         specified.
  301    Method Drupal\Tests\etracker\Functional\ETrackerFunctionalTests::testInclusionByPathWithoutSlashUrl() has no return type
         specified.
  332    Method Drupal\Tests\etracker\Functional\ETrackerFunctionalTests::testExclusionByRoleAuthenticatedTest() has no return type
         specified.
  362    Method Drupal\Tests\etracker\Functional\ETrackerFunctionalTests::testInclusionByRoleAuthenticatedTest() has no return type
         specified.
  392    Method Drupal\Tests\etracker\Functional\ETrackerFunctionalTests::testExclusionByRoleAnonymousTest() has no return type
         specified.
  423    Method Drupal\Tests\etracker\Functional\ETrackerFunctionalTests::testInclusionByRoleAnonymousTest() has no return type
         specified.
  455    Method Drupal\Tests\etracker\Functional\ETrackerFunctionalTests::testExclusionByRoleAdminTest() has no return type specified.
  496    Method Drupal\Tests\etracker\Functional\ETrackerFunctionalTests::testInclusionByRoleAdminTest() has no return type specified.
  539    Method Drupal\Tests\etracker\Functional\ETrackerFunctionalTests::testExclusionByRoleMultipleRoleTest() has no return type
         specified.
  569    Method Drupal\Tests\etracker\Functional\ETrackerFunctionalTests::testInclusionByRoledMultipleRoleTest() has no return type
         specified.
  600    Method Drupal\Tests\etracker\Functional\ETrackerFunctionalTests::testInclusionByRoleAuthenticatedInheritTest() has no return
         type specified.
 ------ ---------------------------------------------------------------------------------------------------------------------------------


 [ERROR] Found 70 errors
📌 Task
Status

Active

Version

3.0

Component

Code

Created by

🇩🇪Germany sunlix Wesel

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

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024