Fix the issues reported by PHP_CodeSniffer

Created on 8 August 2023, 11 months ago
Updated 13 February 2024, 4 months ago

Running phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml shows the following errors/warnings that should be fixed.

FILE: ./README.md
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 42 | ERROR | [x] Expected 1 newline at end of file; 3 found
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


FILE: ./src/Controller/LiveWeatherController.php
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 6 | ERROR | [x] Use statements should be sorted alphabetically. The
   |       |     first wrong one is
   |       |     Drupal\Core\Config\ConfigFactoryInterface.
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


FILE: ./src/Form/LiveWeatherDeleteForm.php
----------------------------------------------------------------------
FOUND 3 ERRORS AFFECTING 3 LINES
----------------------------------------------------------------------
  3 | ERROR | [x] Namespaced classes, interfaces and traits should
    |       |     not begin with a file doc comment
 11 | ERROR | [x] Use statements should be sorted alphabetically. The
    |       |     first wrong one is
    |       |     Drupal\Core\Config\ConfigFactoryInterface.
 23 | ERROR | [ ] Missing @var tag in member variable comment
----------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


FILE: ./src/Form/LiveWeatherForm.php
----------------------------------------------------------------------
FOUND 5 ERRORS AND 1 WARNING AFFECTING 6 LINES
----------------------------------------------------------------------
   1 | ERROR   | [x] The PHP open tag must be followed by exactly one
     |         |     blank line
   2 | ERROR   | [x] Namespaced classes, interfaces and traits should
     |         |     not begin with a file doc comment
  10 | ERROR   | [x] Use statements should be sorted alphabetically.
     |         |     The first wrong one is
     |         |     Drupal\Core\Config\ConfigFactoryInterface.
  41 | ERROR   | [x] Expected 1 blank line before function; 0 found
  76 | ERROR   | [x] Short array syntax must be used to define arrays
 116 | WARNING | [ ] Possible useless method overriding detected
----------------------------------------------------------------------
PHPCBF CAN FIX THE 5 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


FILE: ./src/Form/LiveWeatherSettingsForm.php
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 3 | ERROR | [x] Namespaced classes, interfaces and traits should not
   |       |     begin with a file doc comment
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


FILE: ./src/LiveWeather.php
----------------------------------------------------------------------
FOUND 50 ERRORS AND 3 WARNINGS AFFECTING 33 LINES
----------------------------------------------------------------------
   1 | ERROR   | [x] The PHP open tag must be followed by exactly one
     |         |     blank line
   2 | ERROR   | [x] Namespaced classes, interfaces and traits should
     |         |     not begin with a file doc comment
  10 | ERROR   | [x] Use statements should be sorted alphabetically.
     |         |     The first wrong one is
     |         |     Drupal\Component\Serialization\Json.
  13 | WARNING | [x] Unused use statement
  76 | ERROR   | [x] Use null coalesce operator instead of ternary
     |         |     operator.
  76 | ERROR   | [x] Expected 1 space before "?"; 0 found
  76 | ERROR   | [x] Expected 1 space after "?"; 0 found
  76 | ERROR   | [x] Expected 1 space before ":"; 0 found
  76 | ERROR   | [x] Expected 1 space after ":"; 0 found
  77 | ERROR   | [x] Use null coalesce operator instead of ternary
     |         |     operator.
  77 | ERROR   | [x] Expected 1 space before "?"; 0 found
  77 | ERROR   | [x] Expected 1 space after "?"; 0 found
  77 | ERROR   | [x] Expected 1 space before ":"; 0 found
  77 | ERROR   | [x] Expected 1 space after ":"; 0 found
  78 | ERROR   | [x] Use null coalesce operator instead of ternary
     |         |     operator.
  78 | ERROR   | [x] Expected 1 space before "?"; 0 found
  78 | ERROR   | [x] Expected 1 space after "?"; 0 found
  78 | ERROR   | [x] Expected 1 space before ":"; 0 found
  78 | ERROR   | [x] Expected 1 space after ":"; 0 found
  79 | ERROR   | [x] Expected 1 space after IF keyword; 0 found
  80 | ERROR   | [x] Short array syntax must be used to define arrays
  80 | ERROR   | [x] Expected one space after the comma, 0 found
  80 | ERROR   | [x] Comma not allowed after last value in
     |         |     single-line array declaration
  81 | ERROR   | [x] Short array syntax must be used to define arrays
  82 | ERROR   | [x] Array indentation error, expected 8 spaces but
     |         |     found 6
  83 | ERROR   | [x] Array indentation error, expected 8 spaces but
     |         |     found 6
  84 | ERROR   | [x] Array indentation error, expected 8 spaces but
     |         |     found 6
  85 | ERROR   | [x] Array indentation error, expected 8 spaces but
     |         |     found 6
  86 | ERROR   | [x] Array indentation error, expected 8 spaces but
     |         |     found 6
  86 | ERROR   | [x] Closing parenthesis of array declaration must be
     |         |     on a new line
  89 | ERROR   | [x] TRUE, FALSE and NULL must be uppercase; expected
     |         |     "TRUE" but found "true"
  92 | ERROR   | [x] Short array syntax must be used to define arrays
  94 | WARNING | [x] A comma should follow the last multiline array
     |         |     item. Found: $app_id
  96 | ERROR   | [x] Short array syntax must be used to define arrays
  98 | ERROR   | [x] TRUE, FALSE and NULL must be uppercase; expected
     |         |     "FALSE" but found "false"
 100 | ERROR   | [x] TRUE, FALSE and NULL must be uppercase; expected
     |         |     "TRUE" but found "true"
 101 | WARNING | [x] A comma should follow the last multiline array
     |         |     item. Found: false
 101 | ERROR   | [x] TRUE, FALSE and NULL must be uppercase; expected
     |         |     "FALSE" but found "false"
 106 | ERROR   | [x] Whitespace found at end of line
 194 | ERROR   | [x] Doc comment short description must start with a
     |         |     capital letter
 197 | ERROR   | [x] Short array syntax must be used to define arrays
 199 | ERROR   | [x] Expected 1 space after FOREACH keyword; 0 found
 200 | ERROR   | [x] Line indented incorrectly; expected 6 spaces,
     |         |     found 8
 206 | ERROR   | [x] Doc comment short description must start with a
     |         |     capital letter
 210 | ERROR   | [x] Short array syntax must be used to define arrays
 211 | ERROR   | [x] Expected 1 space after FOREACH keyword; 0 found
 211 | ERROR   | [x] Expected 1 space before "=>"; 0 found
 211 | ERROR   | [x] Expected 1 space after "=>"; 0 found
 211 | ERROR   | [x] Expected 1 space before "=>"; 0 found
 211 | ERROR   | [x] Expected 1 space after "=>"; 0 found
 212 | ERROR   | [x] Line indented incorrectly; expected 6 spaces,
     |         |     found 8
 216 | ERROR   | [x] Expected 1 blank line after function; 0 found
 217 | ERROR   | [x] The closing brace for the class must have an
     |         |     empty line before it
----------------------------------------------------------------------
PHPCBF CAN FIX THE 53 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


FILE: ./src/LiveWeatherInterface.php
----------------------------------------------------------------------
FOUND 8 ERRORS AFFECTING 8 LINES
----------------------------------------------------------------------
  1 | ERROR | [x] The PHP open tag must be followed by exactly one
    |       |     blank line
  2 | ERROR | [x] Namespaced classes, interfaces and traits should
    |       |     not begin with a file doc comment
 17 | ERROR | [x] Expected 1 blank line after function; 0 found
 21 | ERROR | [x] Expected 1 blank line after function; 0 found
 25 | ERROR | [x] Expected 1 blank line after function; 0 found
 27 | ERROR | [x] Doc comment short description must start with a
    |       |     capital letter
 29 | ERROR | [x] Expected 1 blank line after function; 0 found
 31 | ERROR | [x] Doc comment short description must start with a
    |       |     capital letter
----------------------------------------------------------------------
PHPCBF CAN FIX THE 8 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


FILE: ./src/Plugin/Block/LiveWeatherBlock.php
----------------------------------------------------------------------
FOUND 21 ERRORS AND 1 WARNING AFFECTING 14 LINES
----------------------------------------------------------------------
   1 | ERROR   | [x] The PHP open tag must be followed by exactly one
     |         |     blank line
   2 | ERROR   | [x] Namespaced classes, interfaces and traits should
     |         |     not begin with a file doc comment
  13 | ERROR   | [x] Use statements should be sorted alphabetically.
     |         |     The first wrong one is
     |         |     Drupal\Core\Config\ConfigFactoryInterface.
  41 | ERROR   | [ ] Parameter $configuration is not described in
     |         |     comment
  41 | ERROR   | [ ] Parameter $plugin_id is not described in comment
  41 | ERROR   | [ ] Parameter $plugin_definition is not described in
     |         |     comment
  77 | ERROR   | [x] Short array syntax must be used to define arrays
  83 | ERROR   | [x] Short array syntax must be used to define arrays
 109 | ERROR   | [x] Whitespace found at end of line
 109 | ERROR   | [x] Functions must not contain multiple empty lines
     |         |     in a row; found 2 empty lines
 110 | ERROR   | [x] Whitespace found at end of line
 111 | ERROR   | [x] Short array syntax must be used to define arrays
 112 | WARNING | [ ] Unused variable $feed.
 112 | ERROR   | [x] Short array syntax must be used to define arrays
 127 | ERROR   | [x] Expected 1 space before "?"; 0 found
 127 | ERROR   | [x] Expected 1 space before "*"; 0 found
 127 | ERROR   | [x] Expected 1 space after "*"; 0 found
 127 | ERROR   | [x] Expected 1 space before "/"; 0 found
 127 | ERROR   | [x] Expected 1 space after "/"; 0 found
 150 | ERROR   | [x] Whitespace found at end of line
 153 | ERROR   | [x] Short array syntax must be used to define arrays
 156 | ERROR   | [x] Short array syntax must be used to define arrays
----------------------------------------------------------------------
PHPCBF CAN FIX THE 18 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

Time: 171ms; Memory: 6MB
📌 Task
Status

Needs review

Version

3.0

Component

Code

Created by

🇮🇳India Shiv_Sharma

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 @Shiv_Sharma
  • Assigned to kpoornima
  • 🇮🇳India kpoornima

    looking on it

  • Merge request !6#3379900-fixing phpcs errors → (Open) created by kpoornima
  • Issue was unassigned.
  • Status changed to Needs review 11 months ago
  • 🇮🇳India kpoornima

    Please review and merge

  • Status changed to Needs work 11 months ago
  • 🇮🇳India Nishant

    I have checkout 3379900-phpcs-errors this branch and run the above command, I saw some phpcs cs error, I am posting below.

    FILE: /var/www/html/web/modules/live_weather/src/Plugin/Block/LiveWeatherBlock.php
    -----------------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    -----------------------------------------------------------------------------------------------------------------------------------
     9 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\Core\Config\ConfigFactoryInterface.
    -----------------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    -----------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /var/www/html/web/modules/live_weather/src/Form/LiveWeatherDeleteForm.php
    -----------------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    -----------------------------------------------------------------------------------------------------------------------------------
     6 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\Core\Config\ConfigFactoryInterface.
    -----------------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    -----------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /var/www/html/web/modules/live_weather/src/Form/LiveWeatherForm.php
    -----------------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    -----------------------------------------------------------------------------------------------------------------------------------
     6 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\Core\Config\ConfigFactoryInterface.
    -----------------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    -----------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /var/www/html/web/modules/live_weather/src/Controller/LiveWeatherController.php
    -----------------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    -----------------------------------------------------------------------------------------------------------------------------------
     6 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\Core\Config\ConfigFactoryInterface.
    -----------------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    -----------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /var/www/html/web/modules/live_weather/src/LiveWeather.php
    -----------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    -----------------------------------------------------------------------------------------------------------------------------
     6 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\Component\Serialization\Json.
    -----------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
  • 🇮🇳India Shreya_98

    Review this phpcs fixed issues .

  • Status changed to Needs review 11 months ago
  • Status changed to RTBC 11 months ago
  • 🇮🇳India aayushDrupal

    Hi @Shreya_th,
    I have tested your patch and found no errors. I've attached a screenshot for your reference.

    These are the steps I followed:

    1. Took clone from git version 3.0.0 in drupal 10.1.x

    2. Ran this command:

    ./vendor/bin/phpcs --standard="Drupal,DrupalPractice" --extensions="php,module,inc,install,test,profile,theme,md,yml" modules/contrib/live_weather/

    3. Applied patch and again ran phpcs command.

    I found no error. Moving it to RTBC.

  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • Status changed to Needs work 8 months ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
       public function submitForm(array &$form, FormStateInterface $form_state) {
    -    parent::submitForm($form, $form_state);
    +    // parent::submitForm($form, $form_state);.
       }

    If a method is merely calling the parent method, that method can be removed. There is no need to comment out the code.

       protected $httpClient;
    -
       /**
        * A logger instance.
        *
        * @var \Psr\Log\LoggerInterface
        */
       protected $logger;
    -
       /**
        * The configuration factory service.
        *

    Between a line defining a class property and the comment for the next property there must be an empty line.

  • Status changed to Needs review 8 months ago
  • 🇮🇳India mrinalini9 New Delhi

    Updated patch #6 by addressing #10 and some other phpcs issues (missing type hint), please review it.

    Thanks!

  • Status changed to RTBC 8 months ago
  • 🇮🇳India vsheokeen NCR

    Took clone from latst version
    Ran the PHPCS commands
    Applied the Patch
    Ran again all commands.

    Now it looks clean. So moving to RTBC

  • Status changed to Needs work 8 months ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
    +      '#description' => $this->t(
    +    'Enter Where On Earth IDentification of location. Find WOEID to use this url http://woeid.rosselliot.co.nz'),
    +    ];

    The second line is not correctly indented.
    It is probably better to leave the method call on a single line, as it is easier to understand. The fact the first line ends with ( and the last line ends with ] is a bit confusing.

       public function submitForm(array &$form, FormStateInterface $form_state) {
    -    parent::submitForm($form, $form_state);
       }

    The full method must be deleted.

    +   * @param string|null $woeid
    +   *   The Where On Earth IDentifier of the location.

    IDentifier should be identifier. It is not necessary to say of the location, since a Where on Earth identifier is surely for a location.

    +        'oauth_nonce' =>
    +        uniqid(mt_rand(1, 1000)),

    The second line is not correctly indented. It is probably better to put the code on a single line.

    -        CURLOPT_HEADER => false,
    +        CURLOPT_HEADER =>
    +        FALSE,

    There is not need to put FALSE on a new line.

    +      '#title' =>
    +      $this->t('Location list'),
    +      '#description' =>
    +      $this->t('Select locations to display in block'),

    The second line is not correctly indented and it is not necessary to use two lines.

  • Status changed to Needs review 8 months ago
  • 🇮🇳India mrinalini9 New Delhi

    Updated patch #11 by addressing #13, please review it.

    Thanks!

  • Status changed to Needs work 8 months ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
       /**
        * The Drupal configuration factory.
        *
        * @var \Drupal\Core\Config\ConfigFactoryInterface
        */
       protected $configFactory;
    -
       /**
        * The Live weather controller.
        *

    That empty line must be kept.

       /**
    -   * {@inheritdoc}
    +   * Creates an instance of the LiveWeatherForm plugin.
    +   *
    +   * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
    +   *   The service container.
    +   * @param array $configuration
    +   *   An associative array of configuration settings.
    +   * @param string $plugin_id
    +   *   The plugin ID for the plugin instance.
    +   * @param mixed $plugin_definition
    +   *   The plugin definition.
    +   *
    +   * @return static
    +   *   A new instance of the LiveWeatherForm plugin.
        */
       public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {

    Since that is a method defined in an interface, the existing documentation comment is already correct.

       /**
    -   * {@inheritdoc}
    +   * Builds the form for configuring the block settings.
    +   *
    +   * @param array $form
    +   *   An associative array representing the form structure.
    +   * @param \Drupal\Core\Form\FormStateInterface $form_state
    +   *   The current state of the form.
    +   *
    +   * @return array
    +   *   The built form structure.
        */
    -  public function blockForm($form, FormStateInterface $form_state) {

    The existing documentation comment is already correct.

  • First commit to issue fork.
  • 🇮🇳India Yashaswi18

    Applied patch provided in #14, patch applied cleanly, all phpcs issues are fixed. The reviews yet to be addressed.
    Ran this command to check :
    phpcs --standard=Drupal --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml live_weather/

  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    The merge request has more recent changes. That needs to be reviewed, not the patch.

  • Status changed to Needs review 5 months ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • Status changed to Needs work 5 months ago
  • 🇷🇺Russia zniki.ru

    Set to NW.

  • Status changed to Needs review 5 months ago
  • Status changed to Needs work 5 months ago
  • 🇷🇺Russia zniki.ru

    Please check my feedback.

  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • Status changed to Needs review 4 months ago
  • 🇮🇳India zkhan.aamir

    Hi,

    I have checkout 3379900-phpcs-errors this branch and run the above command.
    There are no errors found.

    Admin@DESKTOP-252TO6V MINGW64 ~/Desktop/projects/drupal/web/modules
    $ phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,info,txt,md,js,yml live_weather/
    
    Admin@DESKTOP-252TO6V MINGW64 ~/Desktop/projects/drupal/web/modules
    $
    
    
    
Production build 0.69.0 2024