Problem/Motivation

Update phpstan to level 1

Proposed resolution

Change to level 1, and update baseline with new errors introduced.

Remaining tasks

Check when baseline of level 0 is (almost) clear and ignored errors are reduced to a minimum.

CommentFileSizeAuthor
#23 3180406-23-10.1.patch247.48 KBmondrake
#18 3180406-18.patch245.42 KBmondrake

Issue fork drupal-3190406

Command icon 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

klausi created an issue. See original summary.

klausi’s picture

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mondrake’s picture

Issue tags: +PHPStan-1

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mallezie made their first commit to this issue’s fork.

mallezie’s picture

Title: Fix PHPStan level 1 problems » Update PHPStan to level 1
Issue summary: View changes

Let's try this to see how much extra work level 1 will give.

mallezie’s picture

Version: 9.4.x-dev » 10.0.x-dev
Component: base system » other

mallezie’s picture

[OK] Baseline generated with 1176 errors.

So about 800 new errors added, that's not too bad actually.
But keeping postponed for now, i was just curious.

mondrake’s picture

Status: Postponed » Needs review

Just tried to bump to level 1, 1892 errors, IMHO we should still reduce the level 0 ones before doing this.

longwave’s picture

Now we have the baseline, we could just do this now, and it would stop further level 1 errors from being introduced - not sure we need to fix all level 0 errors first?

mondrake’s picture

I saw some comments about the baseline being too big already to action. I'm fine either way.

mondrake’s picture

mallezie’s picture

I would also think it might be a bit more manageable to postpone on those four issues.
Those solve a lot of the L0 issues.

mallezie’s picture

Just checked the above issues, fixing them first would lower our baseline from 2600 lines to about 1500, thus that would mean approximatley 400 L0 issues left.

Phpstan issues for 'return statement is missing' are also about 150 issues. But not sure if we can fix those easily (is adding a return type a BC break?)

I we can add those directly might be good to have those done as well first, before going to L1?

mondrake’s picture

StatusFileSize
new245.42 KB

A patch to bump PHPStan to level 1 and update the baseline (approx 1.4k errors). Please disregard MRs that are there for baseline generation.

Seems sensible to update now - L1 adds approx 1k errors to current baseline, whereas L2 would add further 10k.

Also see https://drupal.slack.com/archives/C1BMUQ9U6/p1667497607653919 for discussion.

daffie’s picture

Status: Needs review » Reviewed & tested by the community

The patch changes the PHPStan level to 1.
A lot of exceptions are added to the baseline.
For me it is RTBC.

mallezie’s picture

Queued a 10.1.x run, to be sure. Not sure if branches already diverged.

mallezie’s picture

Status: Reviewed & tested by the community » Needs work

Sorry, this will need a separate 10.1.x patch. So setting back to NW

mondrake’s picture

Version: 10.0.x-dev » 10.1.x-dev
mondrake’s picture

Status: Needs work » Needs review
StatusFileSize
new247.48 KB

A 10.1.x baseline.

daffie’s picture

Status: Needs review » Reviewed & tested by the community

The patch changes the PHPStan level to 1.
A lot of exceptions are added to the baseline.
For me it is RTBC.

alexpott’s picture

Version: 10.1.x-dev » 10.0.x-dev
Status: Reviewed & tested by the community » Fixed

This makes sense to me. Perfect is the enemy of progress sometimes and upping the level helps us improve new code.

Committed 7fa5f0a and pushed to 10.1.x. Thanks!
Committed b1fe75f and pushed to 10.0.x. Thanks!

diff --git a/core/phpstan-baseline.neon b/core/phpstan-baseline.neon
index ac9ef95823..0a143fbb4c 100644
--- a/core/phpstan-baseline.neon
+++ b/core/phpstan-baseline.neon
@@ -100,11 +100,21 @@ parameters:
 			count: 4
 			path: lib/Drupal/Component/Diff/DiffFormatter.php
 
+		-
+			message: "#^Variable \\$xi in empty\\(\\) always exists and is not falsy\\.$#"
+			count: 1
+			path: lib/Drupal/Component/Diff/DiffFormatter.php
+
 		-
 			message: "#^Variable \\$y0 might not be defined\\.$#"
 			count: 4
 			path: lib/Drupal/Component/Diff/DiffFormatter.php
 
+		-
+			message: "#^Variable \\$yi in empty\\(\\) always exists and is not falsy\\.$#"
+			count: 1
+			path: lib/Drupal/Component/Diff/DiffFormatter.php
+
 		-
 			message: "#^Access to an undefined property Drupal\\\\Component\\\\Diff\\\\Engine\\\\DiffEngine\\:\\:\\$in_seq\\.$#"
 			count: 3
@@ -1180,6 +1190,16 @@ parameters:
 			count: 2
 			path: modules/config_translation/tests/src/Functional/ConfigTranslationUiTest.php
 
+		-
+			message: "#^Variable \\$settings_locations in empty\\(\\) always exists and is not falsy\\.$#"
+			count: 1
+			path: modules/config_translation/tests/src/Functional/ConfigTranslationUiTest.php
+
+		-
+			message: "#^Variable \\$source_string in empty\\(\\) always exists and is not falsy\\.$#"
+			count: 1
+			path: modules/config_translation/tests/src/Functional/ConfigTranslationUiTest.php
+
 		-
 			message: "#^Method Drupal\\\\contact\\\\ContactFormEditForm\\:\\:save\\(\\) should return int but return statement is missing\\.$#"
 			count: 1
@@ -3957,12 +3977,12 @@ parameters:
 
 		-
 			message: "#^Offset 'display_id' on array\\{\\} in isset\\(\\) does not exist\\.$#"
-			count: 3
+			count: 1
 			path: modules/views/tests/src/Kernel/Handler/AreaDisplayLinkTest.php
 
 		-
 			message: "#^Offset 'view_mode' on array\\{\\} in isset\\(\\) does not exist\\.$#"
-			count: 2
+			count: 1
 			path: modules/views/tests/src/Kernel/Handler/AreaEntityTest.php
 
 		-
@@ -4310,6 +4330,11 @@ parameters:
 			count: 1
 			path: tests/Drupal/BuildTests/Composer/Template/ComposerProjectTemplatesTest.php
 
+		-
+			message: "#^Variable \\$machine_name_1_value in empty\\(\\) always exists and is not falsy\\.$#"
+			count: 1
+			path: tests/Drupal/FunctionalJavascriptTests/Core/MachineNameTest.php
+
 		-
 			message: "#^Variable \\$rawResult on left side of \\?\\? always exists and is not nullable\\.$#"
 			count: 1

Regenerated the baseline on commit.

  • alexpott committed 7fa5f0a on 10.1.x
    Issue #3190406 by mondrake, mallezie, klausi: Update PHPStan to level 1
    

  • alexpott committed b1fe75f on 10.0.x
    Issue #3190406 by mondrake, mallezie, klausi: Update PHPStan to level 1
    

andypost’s picture

This makes __call() methods to fail so I changed to bug #2959989-11: Deprecate Extension::__call() magic

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.