PHPCS and PHPStan errors

Created on 3 March 2024, 10 months ago

Problem/Motivation

Fix PHPCS and PHPStan errors.
See

Proposed resolution

Fix phpcs and phpctsn errors according to gitlab-ci

๐Ÿ“Œ Task
Status

Active

Version

1.0

Component

Code

Created by

๐Ÿ‡บ๐Ÿ‡ฆUkraine HitchShock Ukraine

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

Merge Requests

Comments & Activities

  • Issue created by @HitchShock
  • First commit to issue fork.
  • Assigned to sourabhjain
  • Merge request !3#3425194: Phpcs and phpstan errors โ†’ (Merged) created by sourabhjain
  • Pipeline finished with Success
    10 months ago
    Total: 187s
    #110418
  • Issue was unassigned.
  • Status changed to Needs work 10 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia sourabhjain

    Below are the PHPSTAN errors

    PHP Warning:  Undefined global variable $base_path in /var/www/html/drupal10/web/core/includes/common.inc on line 161
    Warning: Undefined global variable $base_path in /var/www/html/drupal10/web/core/includes/common.inc on line 161
     5/5 [โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“] 100%
    
     ------ ---------------------------------------------------------------------------------------------------------------------------------------- 
      Line   src/PDFToImageBatchHelper.php                                                                                                           
     ------ ---------------------------------------------------------------------------------------------------------------------------------------- 
      117    Parameter $pdf of method Drupal\pdf_to_imagefield\PDFToImageBatchHelper::generateProcessPage() has invalid type Spatie\PdfToImage\Pdf.  
      133    Parameter $pdf of method Drupal\pdf_to_imagefield\PDFToImageBatchHelper::generatePage() has invalid type Spatie\PdfToImage\Pdf.         
     ------ ---------------------------------------------------------------------------------------------------------------------------------------- 
    
     ------ --------------------------------------------------------------------- 
      Line   src/PDFToImageManager.php                                            
     ------ --------------------------------------------------------------------- 
      169    Instantiated class Spatie\PdfToImage\Pdf not found.                  
             ๐Ÿ’ก Learn more at https://phpstan.org/user-guide/discovering-symbols  
     ------ --------------------------------------------------------------------- 
    
     ------ ----------------------------------------------------------------------------------- 
      Line   src/Plugin/Field/FieldWidget/PDFToImageWidget.php                                  
     ------ ----------------------------------------------------------------------------------- 
      64     Unsafe usage of new static().                                                      
             ๐Ÿ’ก See: https://phpstan.org/blog/solving-phpstan-error-unsafe-usage-of-new-static  
     ------ ----------------------------------------------------------------------------------- 
    

    I just investigated on the above and it showing imagick extension is missing as per https://github.com/spatie/pdf-to-image/issues/145

  • ๐Ÿ‡บ๐Ÿ‡ฆUkraine HitchShock Ukraine

    Hi @sourabhjain
    Seems like php extension doesn't exist only on your local env, that's why you have such PHPStan errors.
    According to
    https://git.drupalcode.org/project/pdf_to_imagefield/-/jobs/947631
    https://git.drupalcode.org/issue/pdf_to_imagefield-3425194/-/jobs/976016
    there is only one PHPStan error

     ------ ------------------------------------------------------------------------------ 
      Line   src/Plugin/Field/FieldWidget/PDFToImageWidget.php                             
     ------ ------------------------------------------------------------------------------ 
      64     Unsafe usage of new static().                                                 
             ๐Ÿ’ก See:                                                                       
                https://phpstan.org/blog/solving-phpstan-error-unsafe-usage-of-new-static  
     ------ ------------------------------------------------------------------------------ 
    
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia dev2.addweb

    nilesh.addweb โ†’ made their first commit to this issueโ€™s fork.

  • Pipeline finished with Failed
    5 months ago
    Total: 55s
    #231152
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia dev2.addweb

    Hi,
    I have fixed remaining phpcs and phstan error.

    beofre phpstan-->

    5/5 [โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“] 100%
    
     ------ ---------------------------------------------------------------------------------------------------------------------------------------- 
      Line   src/PDFToImageBatchHelper.php                                                                                                           
     ------ ---------------------------------------------------------------------------------------------------------------------------------------- 
      117    Parameter $pdf of method Drupal\pdf_to_imagefield\PDFToImageBatchHelper::generateProcessPage() has invalid type Spatie\PdfToImage\Pdf.  
      133    Parameter $pdf of method Drupal\pdf_to_imagefield\PDFToImageBatchHelper::generatePage() has invalid type Spatie\PdfToImage\Pdf.         
      146    Fetching deprecated class constant EXISTS_RENAME of interface Drupal\Core\File\FileSystemInterface:                                     
             in drupal:10.3.0 and is removed from drupal:12.0.0. Use                                                                                 
             \Drupal\Core\File\FileExists::Rename instead.                                                                                           
      175    Fetching deprecated class constant EXISTS_ERROR of interface Drupal\Core\File\FileSystemInterface:                                      
             in drupal:10.3.0 and is removed from drupal:12.0.0. Use                                                                                 
              \Drupal\Core\File\FileExists::Error instead.                                                                                           
     ------ ---------------------------------------------------------------------------------------------------------------------------------------- 
    
     ------ --------------------------------------------------------------------- 
      Line   src/PDFToImageManager.php                                            
     ------ --------------------------------------------------------------------- 
      169    Instantiated class Spatie\PdfToImage\Pdf not found.                  
             ๐Ÿ’ก Learn more at https://phpstan.org/user-guide/discovering-symbols  
     ------ --------------------------------------------------------------------- 
    
     ------ ----------------------------------------------------------------------------------- 
      Line   src/Plugin/Field/FieldWidget/PDFToImageWidget.php                                  
     ------ ----------------------------------------------------------------------------------- 
      64     Unsafe usage of new static().                                                      
             ๐Ÿ’ก See: https://phpstan.org/blog/solving-phpstan-error-unsafe-usage-of-new-static  
     ------ ----------------------------------------------------------------------------------- 
    
                                                                                                                            
     [ERROR] Found 6 errors

    After fixing some phpstan and added spatie as per #5 -->

    5/5 [โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“] 100%
    
    
                                                                                                                            
     [OK] No errors    
  • Pipeline finished with Failed
    5 months ago
    Total: 56s
    #231185
  • Pipeline finished with Success
    5 months ago
    Total: 165s
    #231202
  • Pipeline finished with Success
    5 months ago
    Total: 158s
    #231225
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia dev2.addweb

    Now all pipeline job is green, Need to check composer.json which I have been updated for build pass and need to check after composer-lint.

    Before --> https://git.drupalcode.org/issue/pdf_to_imagefield-3425194/-/pipelines/2...
    After --> https://git.drupalcode.org/issue/pdf_to_imagefield-3425194/-/pipelines/2...

  • Status changed to Needs review 5 months ago
  • ๐Ÿ‡บ๐Ÿ‡ฆUkraine HitchShock Ukraine
  • Pipeline finished with Skipped
    28 days ago
    #349619
  • Status changed to Fixed 28 days ago
  • ๐Ÿ‡บ๐Ÿ‡ฆUkraine HitchShock Ukraine

    Thanks all for the help.
    I reverted some changes to keep the module compatible with other packages and older versions of Drupal.
    For example:
    - I reverted "spatie/pdf-to-image": "*" cuz our module doesn't support version >=3.0
    - We still need to use FileSystemInterface for older Drupal versions

    A fix will be provided in the next release

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

Production build 0.71.5 2024