Problem/Motivation

We are trying to reduce the L2 phpstan baseline before starting to go up to L2.
One thing to quickly reduce the number is tackle errors occurring in traits.

This is becuase phpstan reports errors for each class using the trait, causing lots of duplicates.
With some small and focussed non-intrusive changes, this would lower the baseline already a lot making it easier for further optimalisations of the baseline.

Proposed resolution

I propose to focus on small and simple fixes first which occur a lot in the baseline. Anything which needs a slightly more complex change i would descope.

Issue fork drupal-3325057

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

mallezie created an issue. See original summary.

mallezie’s picture

Status: Active » Needs review
StatusFileSize
new243 bytes
new6.78 KB

Some initial work done here.
Attached the update to L2 patch, and patch L2 with small changes. Just checking status. This is not ready yet.

mallezie’s picture

StatusFileSize
new8.43 KB

New patch.

mallezie’s picture

StatusFileSize
new8.2 KB

Baseline starts here at 9427 errors.

Above patch brings it back to 9298, so that's 130 quick fixes down.

Setting needs review to stop here, and see if we could easily get small things like this committed.

smustgrave’s picture

StatusFileSize
new371 bytes
new7.66 KB

@mallezie The last patch doesn't pass commit checks, could you make sure to run ./core/scripts/dev/commit-code-check.sh before uploading a patch to make sure there are no issues with code formatting. see https://www.drupal.org/docs/develop/development-tools/running-core-devel...

Fixed the issue.

spokje’s picture

Status: Needs review » Needs work

Testbot is not a happy bunny...

smustgrave’s picture

Status: Needs work » Needs review
StatusFileSize
new373 bytes
new7.12 KB

Pulled changes for 10.1 this morning but looks like there were more short while ago.

smustgrave’s picture

Status: Needs review » Needs work

That one I can't explain. Locally it passes.

spokje’s picture

spokje’s picture

Assigned: Unassigned » spokje
spokje’s picture

Assigned: spokje » Unassigned
Status: Needs work » Needs review
StatusFileSize
new10.53 KB
new3.34 KB

Recreated the PHPStan baseline, let's see what TestBot thinks

Status: Needs review » Needs work

The last submitted patch, 11: 3325057-11.patch, failed testing. View results

spokje’s picture

Looks like the changes in the patch break some/quite a lot of tests...

danielveza’s picture

+++ b/core/modules/rest/tests/src/Functional/BasicAuthResourceTestTrait.php
@@ -23,7 +23,7 @@ trait BasicAuthResourceTestTrait {
-        'Authorization' => 'Basic ' . base64_encode($this->account->name->value . ':' . $this->account->passRaw),
+        'Authorization' => 'Basic ' . base64_encode($this->account->getAccountName()->value . ':' . $this->account->passRaw),

I think this is the cause of all the broken tests. getAccountName returns a string, so value isn't needed.

+++ b/core/tests/Drupal/FunctionalJavascriptTests/WebDriverTestBase.php
@@ -191,7 +191,13 @@ protected function createScreenshot($filename, $set_background_color = TRUE) {
+   * @return \Drupal\Tests\WebAssert
+   *   A new web-assert option for asserting the presence of elements with.

I think we should be able to change the return here to WebDriverWebAssert and that should hopefully stop another 500 or so errors being thrown. Specifically the ones with Call to an undefined method Drupal\Tests\WebAssert::{method}

The patch also doesn't apply to 10.1.x anymore, fixed the issues but couldn't get the baseline to regenerate properly. I was getting a lot of new warnings added to the baseline

danielveza’s picture

Status: Needs work » Needs review
StatusFileSize
new9.5 KB
new5.39 KB

Self addressed the feedback in #14 and regenerated the baseline. Lets see how the tests go.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

Believe I tested this one write

I applied the patch
Changed the level to 2
Staged everything
./core/scripts/dev/commit-code-check.sh --cached
Got no errors.

Let me know if I missed a step for these level 2 stuff.

longwave’s picture

Should this be postponed on #3352916: Fix PHPStan L1 errors "Call to method getDefinitions()/getSortedDefinitions() on an unknown class Drupal\Core\Plugin\CategorizingPluginManagerTrait.", or should that part of the change here be removed, given it interferes with the fix there?

danielveza’s picture

Status: Reviewed & tested by the community » Needs work

Oh good call. Yeah I think we should remove it from this issue. Thats only one part of this patch, so we can just remove it and regenerate the baseline

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mably’s picture

Looks like the problem isn't fixed yet.

Is there a better solution to it other than adding an @phpstan-ignore-next-line?

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

mstrelan’s picture

Status: Needs work » Needs review

Manually applied parts of #15 that weren't already resolved in HEAD and pushed up a new MR. Hiding patches.

danielveza’s picture

Status: Needs review » Reviewed & tested by the community

Changes look good, the only thing I noticed missing from the original patch were the changes to BasicAuthResourceTestTrait::getAuthenticationRequestOptions. Should they be included in this?

Other that that it looks good and is ready to be RTBC, just checking in on that one first.

mstrelan’s picture

Status: Reviewed & tested by the community » Needs review

Good spotting, I'm not sure why that one didn't make it initially. I generated the baseline at level 2, then updated that method and regenerated it. This removed a further 96 errors from the baseline, so I think that's worth it.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Seems feedback has been addressed.

  • longwave committed 4680f1ab on 11.x
    Issue #3325057 by mallezie, mstrelan, smustgrave, spokje, danielveza:...
longwave’s picture

Status: Reviewed & tested by the community » Fixed

Thanks, having tried level 2 locally and run into the many duplicated errors caused by traits I think this is worthwhile to clean up now so we can try to get a reasonable baseline before going to level 2 for real.

Status: Fixed » Closed (fixed)

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