Fix the issues reported by phpcs

Created on 13 April 2020, almost 5 years ago
Updated 19 May 2023, almost 2 years ago

Problem/Motivation

FILE: ~/projects/drupal-d10/modules/contrib/viewfield/viewfield.module
-------------------------------------------------------------------------------------------------
FOUND 9 ERRORS AND 3 WARNINGS AFFECTING 9 LINES
-------------------------------------------------------------------------------------------------
  20 | ERROR   | [ ] The array declaration extends to column 1052 (the limit is 80). The array content should be split up over multiple lines
 100 | ERROR   | [x] Use null coalesce operator instead of ternary operator.
 105 | ERROR   | [x] Use null coalesce operator instead of ternary operator.
 107 | ERROR   | [x] Use null coalesce operator instead of ternary operator.
 110 | ERROR   | [ ] Comment indentation error, expected only 1 spaces
 111 | ERROR   | [ ] Comment indentation error, expected only 2 spaces
 114 | WARNING | [ ] Line exceeds 80 characters; contains 124 characters
 114 | ERROR   | [ ] Comment indentation error, expected only 1 spaces
 115 | WARNING | [ ] Line exceeds 80 characters; contains 128 characters
 115 | ERROR   | [ ] Comment indentation error, expected only 2 spaces
 136 | WARNING | [ ] Line exceeds 80 characters; contains 188 characters
 136 | ERROR   | [ ] Comment indentation error, expected only 1 spaces
-------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 3 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------------------------------


FILE: ~/projects/drupal-d10/modules/contrib/viewfield/tests/src/FunctionalJavascript/ViewfieldFormatterTest.php
---------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 5 WARNINGS AFFECTING 5 LINES
---------------------------------------------------------------------------------------------
  46 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
  85 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 129 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 176 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 222 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
---------------------------------------------------------------------------------------------


FILE: ~/projects/drupal-d10/modules/contrib/viewfield/tests/src/FunctionalJavascript/ViewfieldFunctionalTestBase.php
------------------------------------------------------------------------------------------------
FOUND 4 ERRORS AFFECTING 4 LINES
------------------------------------------------------------------------------------------------
  32 | ERROR | [ ] Missing @var tag in member variable comment
  64 | ERROR | [ ] The array declaration extends to column 100 (the limit is 80). The array content should be split up over multiple lines
 165 | ERROR | [x] Expected 1 blank line after function; 2 found
 168 | ERROR | [x] The closing brace for the class must have an empty line before it
------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------


FILE: ~/projects/drupal-d10/modules/contrib/viewfield/tests/src/FunctionalJavascript/ViewfieldWidgetTest.php
------------------------------------------------------------------------------------------------
FOUND 1 ERROR AND 2 WARNINGS AFFECTING 3 LINES
------------------------------------------------------------------------------------------------
 26 | WARNING | [ ] Unused variable $page.
 50 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 58 | ERROR   | [x] Expected 1 newline at end of file; 0 found
------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------


FILE: ~/projects/drupal-d10/modules/contrib/viewfield/tests/src/Kernel/ViewfieldKernelTest.php
------------------------------------------------------------------------------------------------------------------------------
FOUND 6 ERRORS AND 18 WARNINGS AFFECTING 13 LINES
------------------------------------------------------------------------------------------------------------------------------
 28 | ERROR   | [ ] Missing @var tag in member variable comment
 31 | ERROR   | [x] Missing function doc comment
 32 | WARNING | [x] 'TODO: Change the autogenerated stub' should match the format '@todo Fix problem X here.'
 32 | WARNING | [ ] There must be no blank line following an inline comment
 32 | ERROR   | [x] Comments may not appear after statements
 32 | ERROR   | [x] Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
 59 | ERROR   | [x] Missing function doc comment
 60 | WARNING | [x] There must be no blank line following an inline comment
 60 | WARNING | [ ] There must be no blank line following an inline comment
 62 | WARNING | [x] There must be no blank line following an inline comment
 62 | WARNING | [ ] There must be no blank line following an inline comment
 64 | WARNING | [x] There must be no blank line following an inline comment
 64 | WARNING | [ ] There must be no blank line following an inline comment
 66 | WARNING | [x] There must be no blank line following an inline comment
 66 | WARNING | [ ] There must be no blank line following an inline comment
 68 | WARNING | [x] There must be no blank line following an inline comment
 68 | WARNING | [ ] There must be no blank line following an inline comment
 70 | WARNING | [x] There must be no blank line following an inline comment
 70 | WARNING | [ ] There must be no blank line following an inline comment
 72 | WARNING | [x] There must be no blank line following an inline comment
 72 | WARNING | [ ] There must be no blank line following an inline comment
 74 | WARNING | [x] There must be no blank line following an inline comment
 74 | WARNING | [ ] There must be no blank line following an inline comment
 78 | ERROR   | [x] Missing function doc comment
------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 14 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------------------------------------


FILE: ~/projects/drupal-d10/modules/contrib/viewfield/viewfield.libraries.yml
------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
------------------------------------------------------------------------------------------------------
 9 | ERROR | [x] Expected 1 newline at end of file; 0 found
------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------------


FILE: ~/projects/drupal-d10/modules/contrib/viewfield/README.txt
-----------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
-----------------------------------------------------------------------------------------
 54 | WARNING | Line exceeds 80 characters; contains 81 characters
-----------------------------------------------------------------------------------------


FILE: ~/projects/drupal-d10/modules/contrib/viewfield/viewfield.install
------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
------------------------------------------------------------------------------------------------
 128 | ERROR | [x] Expected 1 newline at end of file; 0 found
------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------


FILE: ~/projects/drupal-d10/modules/contrib/viewfield/src/ViewfieldServiceProvider.php
---------------------------------------------------------------------------------------------------------------
FOUND 4 ERRORS AFFECTING 4 LINES
---------------------------------------------------------------------------------------------------------------
 11 | ERROR | [x] Doc comment short description must end with a full stop
 22 | ERROR | [x] Short array syntax must be used to define arrays
 26 | ERROR | [x] Short array syntax must be used to define arrays
 31 | ERROR | [x] Expected 1 newline at end of file; 0 found
---------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 4 MARKED SNIFF VIOLATIONS AUTOMATICALLY
---------------------------------------------------------------------------------------------------------------


FILE: ~/projects/drupal-d10/modules/contrib/viewfield/src/Plugin/Field/FieldWidget/ViewfieldWidgetSelect.php
----------------------------------------------------------------------------------------
FOUND 8 ERRORS AND 3 WARNINGS AFFECTING 8 LINES
----------------------------------------------------------------------------------------
  92 | ERROR   | [x] Expected 1 space after "="; 2 found
 111 | ERROR   | [x] TRUE, FALSE and NULL must be uppercase; expected "FALSE" but found "false"
 115 | ERROR   | [x] Concat operator must be surrounded by a single space
 116 | ERROR   | [x] Concat operator must be surrounded by a single space
 163 | ERROR   | [x] Whitespace found at end of line
 244 | ERROR   | [x] Missing function doc comment
 245 | WARNING | [ ] Line exceeds 80 characters; contains 108 characters
 245 | WARNING | [x] 'TODO: Change the autogenerated stub' should match the format '@todo Fix problem X here.'
 245 | ERROR   | [x] Comments may not appear after statements
 245 | ERROR   | [x] Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
 246 | WARNING | [ ] Unused variable $key.
----------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 9 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------------------------


FILE: ~/projects/drupal-d10/modules/contrib/viewfield/src/Plugin/Field/FieldType/ViewfieldItem.php
-----------------------------------------------------------------------------------------------
FOUND 1 ERROR AND 2 WARNINGS AFFECTING 3 LINES
-----------------------------------------------------------------------------------------------
   5 | WARNING | [x] Unused use statement
   8 | WARNING | [x] Unused use statement
 138 | ERROR   | [ ] The array declaration extends to column 84 (the limit is 80). The array content should be split up over multiple lines
-----------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-----------------------------------------------------------------------------------------------


FILE: ~/projects/drupal-d10/modules/contrib/viewfield/src/Plugin/Field/FieldFormatter/ViewfieldFormatterDefault.php
-----------------------------------------------------------------------------------------------
FOUND 2 ERRORS AND 1 WARNING AFFECTING 3 LINES
-----------------------------------------------------------------------------------------------
 154 | ERROR   | [x] Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
 162 | ERROR   | [x] Expected 1 space after IF keyword; 0 found
 249 | WARNING | [ ] \Drupal calls should be avoided in classes, use dependency injection instead
-----------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-----------------------------------------------------------------------------------------------

Time: 251ms; Memory: 12MB

Steps to reproduce

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

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

📌 Task
Status

Needs work

Version

3.0

Component

Code

Created by

🇮🇳India maithri shetty

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

Comments & Activities

Not all content is available!

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

  • First commit to issue fork.
  • @vladimiraus opened merge request.
  • 🇦🇺Australia VladimirAus Brisbane, Australia

    Rerolled as MR and fixed everything except

    FILE: /Users/tesboss/_PROJECTS/drupal/viewfield/src/Plugin/Field/FieldFormatter/ViewfieldFormatterDefault.php
    -------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    -------------------------------------------------------------------------------------------------------------
     249 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
    -------------------------------------------------------------------------------------------------------------
    
  • 🇮🇳India rassoni Bangalore

    MR 6 review and tested locally and PHPCS issues are resolved. Please check the screenshot for reference.

  • Status changed to RTBC about 2 years ago
  • Status changed to Needs work about 2 years ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    The issue summary should always describe what the issue is trying to fix and, in the case, of coding standards issues, show which command has been used, which arguments have been used, and which report that command shown.

  • Status changed to Needs review about 2 years ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • Status changed to RTBC about 2 years ago
  • 🇦🇺Australia VladimirAus Brisbane, Australia
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
    +  /**
    +   * The Token service.
    +   *
    +   * @var \Drupal\Core\Utility\Token

    Only the first word in the description must be capitalized.

    +  /**
    +   * Constructs a StringFormatter instance.

    The class is not correct; the class is ViewfieldFormatterDefault.
    The description for a constructor must start with Constructs a new followed by the class name (including its namespace), and end with object.

    -        // Set arguments if they exist
    +        // Set arguments if they exist.
             if (!empty($arguments)) {
               $view->setArguments($arguments);
             }

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

    + // @todo Change the autogenerated stub

    The period at the end is missing.

     /**
    - * Service Provider for Viewfield
    + * Service Provider for Viewfield.
      */
     class ViewfieldServiceProvider extends ServiceProviderBase {

    That description does not say what the class does.
    Only the first word must be capitalized.

  • Status changed to Needs work almost 2 years ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • Assigned to nitin_lama
  • Issue was unassigned.
  • First commit to issue fork.
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.1 & MySQL 5.7
    last update almost 2 years ago
    8 pass
  • Status changed to Needs review almost 2 years ago
  • 🇮🇳India sakthi_dev

    Updated the MR with the changes mentioned in #26. Please review.

  • Status changed to Needs work almost 2 years ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
    -        // Set arguments if they exist
    +        // Set arguments if they exist.
             if (!empty($arguments)) {
               $view->setArguments($arguments);
             }
    

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

    - * Service Provider for Viewfield
    + * Sets definition for searializer and tag for normalizer.

    There is a typo in that description, which does not make sense.

    +  /**
    +   * Test view field item default value.
    +   */

    The verb must use the third singular person.
    The description should be rewritten: Four attributive nouns are too much.

    -  //  if (!isset($default_attributes)) {
    -  //    $default_attributes = new Attribute();
    -  //  }
    +  // if (!isset($default_attributes)) {
    +  // $default_attributes = new Attribute();
    +  // }
    

    Even if commented out, that is still code. The existing line are correctly indented; the changed code is not correctly indented.

    -    //    $variables['items'][$delta]['attributes'] = !empty($element['#items'][$delta]->_attributes) ? new Attribute($element['#items'][$delta]->_attributes) : clone($default_attributes);
    +    // $variables['items'][$delta]['attributes'] =
    +    // !empty($element['#items'][$delta]->_attributes) ?
    +    // new Attribute($element['#items'][$delta]->_attributes) :
    +    // clone($default_attributes);

    Code lines can exceed 80 characters, if they are more readable. That is still valid for commented out code.

  • Assigned to nitin_lama
  • Issue was unassigned.
Production build 0.71.5 2024