Drupal Coding Standards Issues | phpcs

Created on 31 January 2023, almost 2 years ago

Problem/Motivation

Getting Following errors/warnings

$ phpcs --standard=Drupal change_field_type

FILE: ...sers\Admin\Desktop\task\change_field_type\src\Form\ChangeFieldTypeForm.php
--------------------------------------------------------------------------------
FOUND 3 ERRORS AND 2 WARNINGS AFFECTING 5 LINES
--------------------------------------------------------------------------------
   1 | ERROR   | [x] End of line character is invalid; expected "\n" but found
     |         |     "\r\n"
 146 | ERROR   | [x] 4 spaces found before inline comment; expected "//
     |         |     $view_storage =
     |         |     $this->entityTypeManager->getStorage('view');" but found
     |         |     "//    $view_storage =
     |         |     $this->entityTypeManager->getStorage('view');"
 147 | WARNING | [ ] Line exceeds 80 characters; contains 87 characters
 149 | WARNING | [x] There must be no blank line following an inline comment
 232 | ERROR   | [x] Array indentation error, expected 10 spaces but found 12
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 4 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------

Time: 474ms; Memory: 10MB

Proposed resolution

Fix the errors and warnings.

šŸ“Œ Task
Status

Active

Version

1.0

Component

Code

Created by

šŸ‡®šŸ‡³India jay jangid Jaipur

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

Comments & Activities

  • Issue created by @jay jangid
  • @jay-jangid opened merge request.
  • Issue was unassigned.
  • Status changed to Needs review almost 2 years ago
  • šŸ‡®šŸ‡³India jay jangid Jaipur

    Created MR , please review.

    Thank you.

  • šŸ‡®šŸ‡³India nayana_mvr

    Verified MR3 and tested it on Drupal version 10.1.x and Change Field Type version 1.0.x. All the coding standard issues are fixed. Screenshots attached for reference.

  • Assigned to lalitkyttn
  • Status changed to Active almost 2 years ago
  • Issue was unassigned.
  • Status changed to Needs review almost 2 years ago
  • Status changed to Needs work 4 months ago
  • šŸ‡µšŸ‡­Philippines cleavinjosh

    Hi @lalitkyttn,

    I applied patch#6, it was applied and fixed some of the phpcs issues.

    These are the remaining issues after I ran phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml.

    āžœ  change_field_type git:(1.0.x) curl https://www.drupal.org/files/issues/2023-02-01/ChangeFieldTypeForm.php-3337847-6.patch | patch -p1
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100  1364  100  1364    0     0   3217      0 --:--:-- --:--:-- --:--:--  3224
    patching file src/Form/ChangeFieldTypeForm.php
    āžœ  change_field_type git:(1.0.x) āœ— ..
    āžœ  contrib phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml change_field_type
    
    FILE: /Users/interns/Demo-site/drupal-org-issues/web/modules/contrib/change_field_type/change_field_type.routing.yml
    -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
     7 | WARNING | The administration page callback should probably use "administer site configuration" - which implies the user can change something - rather than "access administration pages" which is about
       |         | viewing but not changing configurations.
    -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /Users/interns/Demo-site/drupal-org-issues/web/modules/contrib/change_field_type/src/Form/ChangeFieldTypeForm.php
    -----------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AND 5 WARNINGS AFFECTING 5 LINES
    -----------------------------------------------------------------------------------------------------------------------
     144 | WARNING | Unused variable $config.
     147 | WARNING | Line exceeds 80 characters; contains 87 characters
     147 | ERROR   | Comment indentation error, expected only 1 spaces
     187 | WARNING | FieldStorageConfig::load calls should be avoided in classes, use dependency injection instead
     281 | WARNING | FieldStorageConfig::load calls should be avoided in classes, use dependency injection instead
     565 | WARNING | Unused variable $key.
    -----------------------------------------------------------------------------------------------------------------------
    
    Time: 270ms; Memory: 12MB
    
    āžœ  contrib

    I also applied MR!3 and still encountered the same issues after I ran phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml.

    āžœ  change_field_type git:(1.0.x) curl https://git.drupalcode.org/project/change_field_type/-/merge_requests/3.diff | patch -p1
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100  1647    0  1647    0     0   2948      0 --:--:-- --:--:-- --:--:--  2946
    patching file src/Form/ChangeFieldTypeForm.php
    āžœ  change_field_type git:(1.0.x) āœ— ..
    āžœ  contrib phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml change_field_type
    
    FILE: /Users/interns/Demo-site/drupal-org-issues/web/modules/contrib/change_field_type/change_field_type.routing.yml
    -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
     7 | WARNING | The administration page callback should probably use "administer site configuration" - which implies the user can change something - rather than "access administration pages" which is about
       |         | viewing but not changing configurations.
    -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /Users/interns/Demo-site/drupal-org-issues/web/modules/contrib/change_field_type/src/Form/ChangeFieldTypeForm.php
    -----------------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 4 WARNINGS AFFECTING 4 LINES
    -----------------------------------------------------------------------------------------------------------------------
     144 | WARNING | Unused variable $config.
     188 | WARNING | FieldStorageConfig::load calls should be avoided in classes, use dependency injection instead
     282 | WARNING | FieldStorageConfig::load calls should be avoided in classes, use dependency injection instead
     566 | WARNING | Unused variable $key.
    -----------------------------------------------------------------------------------------------------------------------
    
    Time: 280ms; Memory: 12MB
    
    āžœ  contrib

    Thank you.

  • Assigned to priyanka_chauhan31
Production build 0.71.5 2024