Fix PHPStan L2 error in traits

Created on 2 December 2022, almost 2 years ago
Updated 16 April 2023, over 1 year ago

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.

πŸ“Œ Task
Status

Needs work

Version

10.1 ✨

Component
OtherΒ  β†’

Last updated about 3 hours ago

Created by

πŸ‡§πŸ‡ͺBelgium mallezie Loenhout

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

Comments & Activities

Not all content is available!

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

  • πŸ‡³πŸ‡ΏNew Zealand danielveza Brisbane, AU
    +++ 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.

    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

  • Status changed to Needs review over 1 year ago
  • πŸ‡³πŸ‡ΏNew Zealand danielveza Brisbane, AU

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

  • Status changed to RTBC over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    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.

  • last update over 1 year ago
    29,202 pass
  • πŸ‡¬πŸ‡§United Kingdom longwave UK

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

  • Status changed to Needs work over 1 year ago
  • πŸ‡³πŸ‡ΏNew Zealand danielveza Brisbane, AU

    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

Production build 0.71.5 2024