Fix the issues reported by phpcs

Created on 7 February 2023, over 1 year ago
Updated 31 May 2024, 28 days ago

Problem/Motivation

Getting Following errors/warnings

$ phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml views_field_permissions

FILE: ...sers\Admin\Desktop\task\views_field_permissions\src\ViewsUiFormService.php
--------------------------------------------------------------------------------
FOUND 8 ERRORS AND 17 WARNINGS AFFECTING 25 LINES
--------------------------------------------------------------------------------
   1 | ERROR   | [x] End of line character is invalid; expected "\n" but found
     |         |     "\r\n"
  56 | ERROR   | [x] Inline comments must end in full-stops, exclamation marks,
     |         |     question marks, colons, or closing parentheses
  57 | WARNING | [ ] t() calls should be avoided in classes, use
     |         |     \Drupal\Core\StringTranslation\StringTranslationTrait and
     |         |     $this->t() instead
  71 | WARNING | [ ] t() calls should be avoided in classes, use
     |         |     \Drupal\Core\StringTranslation\StringTranslationTrait and
     |         |     $this->t() instead
  80 | WARNING | [ ] t() calls should be avoided in classes, use
     |         |     \Drupal\Core\StringTranslation\StringTranslationTrait and
     |         |     $this->t() instead
  81 | WARNING | [ ] t() calls should be avoided in classes, use
     |         |     \Drupal\Core\StringTranslation\StringTranslationTrait and
     |         |     $this->t() instead
  82 | WARNING | [ ] t() calls should be avoided in classes, use
     |         |     \Drupal\Core\StringTranslation\StringTranslationTrait and
     |         |     $this->t() instead
  84 | WARNING | [ ] t() calls should be avoided in classes, use
     |         |     \Drupal\Core\StringTranslation\StringTranslationTrait and
     |         |     $this->t() instead
  86 | ERROR   | [x] Use null coalesce operator instead of ternary operator.
  89 | ERROR   | [x] Inline comments must end in full-stops, exclamation marks,
     |         |     question marks, colons, or closing parentheses
  93 | WARNING | [ ] t() calls should be avoided in classes, use
     |         |     \Drupal\Core\StringTranslation\StringTranslationTrait and
     |         |     $this->t() instead
  95 | ERROR   | [x] Use null coalesce operator instead of ternary operator.
  99 | WARNING | [x] A comma should follow the last multiline array item.
     |         |     Found: 'role'
 107 | WARNING | [ ] t() calls should be avoided in classes, use
     |         |     \Drupal\Core\StringTranslation\StringTranslationTrait and
     |         |     $this->t() instead
 109 | ERROR   | [x] Use null coalesce operator instead of ternary operator.
 113 | WARNING | [x] A comma should follow the last multiline array item.
     |         |     Found: 'role'
 120 | WARNING | [ ] t() calls should be avoided in classes, use
     |         |     \Drupal\Core\StringTranslation\StringTranslationTrait and
     |         |     $this->t() instead
 125 | WARNING | [x] A comma should follow the last multiline array item.
     |         |     Found: 'perm'
 136 | WARNING | [ ] t() calls should be avoided in classes, use
     |         |     \Drupal\Core\StringTranslation\StringTranslationTrait and
     |         |     $this->t() instead
 147 | WARNING | [ ] t() calls should be avoided in classes, use
     |         |     \Drupal\Core\StringTranslation\StringTranslationTrait and
     |         |     $this->t() instead
 165 | WARNING | [ ] t() calls should be avoided in classes, use
     |         |     \Drupal\Core\StringTranslation\StringTranslationTrait and
     |         |     $this->t() instead
 168 | WARNING | [ ] t() calls should be avoided in classes, use
     |         |     \Drupal\Core\StringTranslation\StringTranslationTrait and
     |         |     $this->t() instead
 169 | WARNING | [ ] t() calls should be avoided in classes, use
     |         |     \Drupal\Core\StringTranslation\StringTranslationTrait and
     |         |     $this->t() instead
 205 | ERROR   | [x] Inline comments must end in full-stops, exclamation marks,
     |         |     question marks, colons, or closing parentheses
 257 | ERROR   | [x] Inline comments must end in full-stops, exclamation marks,
     |         |     question marks, colons, or closing parentheses
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 11 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------


FILE: ...n\Desktop\task\views_field_permissions\src\ViewsUiFormServiceInterface.php
--------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------
 1 | ERROR | [x] End of line character is invalid; expected "\n" but found
   |       |     "\r\n"
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------


FILE: ...Admin\Desktop\task\views_field_permissions\views_field_permissions.install
--------------------------------------------------------------------------------
FOUND 4 ERRORS AFFECTING 4 LINES
--------------------------------------------------------------------------------
  1 | ERROR | [x] End of line character is invalid; expected "\n" but found
    |       |     "\r\n"
 10 | ERROR | [ ] Doc comment short description must be on a single line,
    |       |     further text should be a separate paragraph
 14 | ERROR | [x] Namespaced classes/interfaces/traits should be referenced
    |       |     with use statements
 31 | ERROR | [x] Use null coalesce operator instead of ternary operator.
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 3 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------


FILE: ...\Admin\Desktop\task\views_field_permissions\views_field_permissions.module
--------------------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 2 LINES
--------------------------------------------------------------------------------
  1 | ERROR | [x] End of line character is invalid; expected "\n" but found
    |       |     "\r\n"
 61 | ERROR | [x] Use null coalesce operator instead of ternary operator.
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------


FILE: ...sktop\task\views_field_permissions\views_field_permissions.post_update.php
--------------------------------------------------------------------------------
FOUND 1 ERROR AND 1 WARNING AFFECTING 2 LINES
--------------------------------------------------------------------------------
  1 | ERROR   | [x] End of line character is invalid; expected "\n" but found
    |         |     "\r\n"
 31 | WARNING | [ ] Line exceeds 80 characters; contains 83 characters
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------

Time: 581ms; Memory: 10MB

Proposed resolution

Fix the errors and warnings.

šŸ“Œ Task
Status

Closed: outdated

Version

2.0

Component

Code

Created by

šŸ‡®šŸ‡³India Jay Jangid

Live updates comments and jobs are added and updated live.
  • Coding standards

    It involves compliance with, or the content of coding standards. Requires broad community agreement.

Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @Jay Jangid
  • @jay-jangid opened merge request.
  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • šŸ‡®šŸ‡³India Jay Jangid

    Created MR , please review.

    Thank you.

  • Status changed to Needs work over 1 year ago
  • šŸ‡®šŸ‡³India mrinalini9 New Delhi

    Hi,

    I have reviewed MR, it removed all the phpcs errors and warnings but these changes doesn't seems correct to me:

    1. For example: t() calls, it should be $this->t() not $this() here:

    diff --git a/src/ViewsUiFormService.php b/src/ViewsUiFormService.php
    -    $perms = ['' => t('- None -')];
    +    $perms = ['' => $this('- None -')];

    2. Doc comment short description should explain what the function is actually doing not the function name as it is here:

    diff --git a/views_field_permissions.install b/views_field_permissions.install
    - * Update views configs to guarantee retrocompatibility for the role-based
    - * permission feature.
    + * Summary of views_field_permissions_update_8001.

    3. For line exceeds 80 characters, break the sentence just once it's reaching 80 characters, not from anywhere. Like here:

    diff --git a/views_field_permissions.module b/views_field_permissions.module
    -            // Save the new settings, log the change, and mark the view for update.
    +            // Save the new settings, log the change,
    +            // mark the view for update.

    It should be:

    +            // Save the new settings, log the change,  mark the view for
    +            // update.

    Thanks & Regards,
    Mrinalini

  • First commit to issue fork.
  • First commit to issue fork.
  • Status changed to Needs review over 1 year ago
  • šŸ‡®šŸ‡³India kkalashnikov Ghaziabad, India
  • Status changed to Needs work about 1 year ago
  • šŸ‡®šŸ‡¹Italy apaderno Brescia, šŸ‡®šŸ‡¹

    I am going to review the MR3. (It is not clear whether MR5 was created to fix something that MR3 did not fix.)

    -    // Get list of permissions
    -    $perms = ['' => t('- None -')];
    +    // Get list of permissions.
    +    $perms = ['' => $this->t('- None -')];
         $permissions = $this->permissionHandler->getPermissions();

    That comment can be removed, since it describes something the code makes already clear.

    -            // Save the new settings, log the change, and mark the view for update.
    +            // Save the new settings,log the change,and mark the view for
    +            // update.

    In English, there must be a space between a comma and the word following it.

  • Assigned to nitin_lama
  • First commit to issue fork.
  • Issue was unassigned.
  • šŸ‡®šŸ‡¹Italy apaderno Brescia, šŸ‡®šŸ‡¹
         $form['options']['expose']['views_field_permissions'] = $elements;
         $form['actions']['submit']['#submit'][] = [get_class($this), 'submit'];
    +
    +    return $form;

    A method that is declared as public function form(array &$form, FormStateInterface &$form_state) does not need to return $form.

    Also, the report shows errors/warnings for five files, but MR5 just changes a single file.

  • Status changed to Needs review 7 months ago
  • Status changed to Needs work 7 months ago
  • šŸ‡®šŸ‡¹Italy apaderno Brescia, šŸ‡®šŸ‡¹
  • Assigned to nitin_lama
  • Issue was unassigned.
  • Status changed to Needs review 7 months ago
  • Status changed to RTBC 29 days ago
  • Hi @everyone,

    All issues mentioned were fixed after #16's MR!5 commit

    drupal-orgissue git:(main) āœ— phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml,twig views_field_permissions
    āžœ  drupal-orgissue git:(main) āœ—

    Moving this to RTBC.

    Thanks,
    Jake

  • šŸ‡®šŸ‡¹Italy apaderno Brescia, šŸ‡®šŸ‡¹

    apaderno ā†’ changed the visibility of the branch 3339907-drupal-coding-standards to hidden.

  • Pipeline finished with Success
    28 days ago
    Total: 139s
    #187259
  • Status changed to Closed: outdated 28 days ago
  • šŸ‡®šŸ‡¹Italy apaderno Brescia, šŸ‡®šŸ‡¹

    These issues has been already fixed in šŸ“Œ Automated Drupal 10 compatibility fixes Fixed . GitLab CI does not show any PHP_CodeSniffer warning/error that should be fixed.

Production build 0.69.0 2024