Fix phpstan issues

Created on 9 May 2024, 7 months ago
Updated 21 June 2024, 5 months ago

Problem/Motivation

Adding the GitLab CI template identified some PHPStan issues:

 ------ ----------------------------------------------------------------------- 
  Line   src/Form/RRSSBSettingsForm.php                                         
 ------ ----------------------------------------------------------------------- 
  244    Relying on entity queries to check access by default is deprecated in  
         drupal:9.2.0 and an error will be thrown from drupal:10.0.0. Call      
         \Drupal\Core\Entity\Query\QueryInterface::accessCheck() with TRUE or   
         FALSE to specify whether access should be checked.                     
         💡 See https://www.drupal.org/node/3201242                             
 ------ ----------------------------------------------------------------------- 
 ------ ---------------------------------------------------------------------- 
  Line   src/Plugin/Block/RRSSBBlock.php                                       
 ------ ---------------------------------------------------------------------- 
  27     \Drupal calls should be avoided in classes, use dependency injection  
         instead                                                               
 ------ ---------------------------------------------------------------------- 
 ------ ---------------------------------------------------------------------- 
  Line   src/Plugin/Block/RRSSBDemoBlock.php                                   
 ------ ---------------------------------------------------------------------- 
  26     \Drupal calls should be avoided in classes, use dependency injection  
         instead                                                               
  29     \Drupal calls should be avoided in classes, use dependency injection  
         instead                                                               
 ------ ---------------------------------------------------------------------- 

Let's fix these.

📌 Task
Status

Postponed

Version

2.0

Component

Code

Created by

🇯🇵Japan ptmkenny

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

Merge Requests

Comments & Activities

  • Issue created by @ptmkenny
  • Merge request !14fix phpstan issues → (Open) created by ptmkenny
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.5 + Environment: PHP 7.3 & MySQL 5.7
    last update 7 months ago
    PHPLint Failed
  • Pipeline finished with Failed
    7 months ago
    Total: 173s
    #168889
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.5 + Environment: PHP 7.3 & MySQL 5.7
    last update 7 months ago
    PHPLint Failed
  • Pipeline finished with Failed
    7 months ago
    Total: 174s
    #168899
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.5 + Environment: PHP 7.3 & MySQL 5.7
    last update 7 months ago
    PHPLint Failed
  • 🇯🇵Japan ptmkenny

    The DI adds a lot of lines, but once D9 support is dropped and PHP 8 is required, we can make use of php 8 constructor property promotion 📌 Use PHP 8 constructor property promotion for existing code Needs work .

  • Pipeline finished with Failed
    7 months ago
    Total: 139s
    #168905
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.5 + Environment: PHP 7.3 & MySQL 5.7
    last update 7 months ago
    PHPLint Failed
  • Status changed to Needs review 7 months ago
  • Pipeline finished with Failed
    7 months ago
    Total: 139s
    #168913
  • Status changed to Needs work 6 months ago
  • 🇬🇧United Kingdom adamps

    Relying on entity queries to check access by default is deprecated in drupal:9.2.0 and an error will be thrown from drupal:10.0.0.

    So this first one is presumably a bug.

    The other 3 are all insisting on DI. Personally I don't really agree when it adds loads of code and anyway does anyone care😃? It seems like we are responding to the automatic warning rather than changing it because someone actually wants it. Also the constructor change would break any code that extends the class.

    The DI adds a lot of lines, but once D9 support is dropped and PHP 8 is required,

    D9 is already EOL and no longer supported and it could safely be removed from the info file.

  • 🇯🇵Japan ptmkenny

    If D9 support is dropped we can do constructor promotion 📌 Use PHP 8 constructor property promotion for existing code Needs work to wipe out most of the boilerplate code, but that will still change the constructor, breaking the class for anyone extending it.

    Since this needs discussion, I'll open a separate issue to fix the query access check.

  • 🇬🇧United Kingdom adamps

    In theory we ought to create a major release for a non-BC change, however it seems a bit excessive in this case.

  • 🇬🇧United Kingdom adamps

    OK here's as idea. I feel that it would be worth creating a new major release if we did a more widespread update of the entire module to use PHP8. We could adopt constructor promotion, add types to class variable and function returns, and anything else relevant. It's not a big module so it probably wouldn't take very long.

    Otherwise we could postpone this issue for now until there is another reason to create a major release.

  • Status changed to Postponed 6 months ago
  • 🇯🇵Japan ptmkenny

    @AdamPS: Agreed, going full PHP 8 seems worthy of a new major release. Having done this with a few other modules recently, it should be quite easy. I assume that should be a new issue ("require php 8")?

  • 🇬🇧United Kingdom adamps

    A new issue sounds good to me thanks

Production build 0.71.5 2024