Fix the issues reported by phpcs

Created on 28 June 2022, over 2 years ago
Updated 11 March 2024, 8 months ago

GitLab CI reports PHP_CodeSniffer errors/warnings that should be fixed. See the linked page for a detailed list of errors/warnings.

📌 Task
Status

Needs work

Component

Code

Created by

🇮🇳India Harsh panchal

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.

  • Needs reroll

    The patch will have to be re-rolled with new suggestions/changes described in the comments in the issue.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

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

  • 🇮🇹Italy apaderno Brescia, 🇮🇹
    -      '@date' => \Drupal::service('date.formatter')->format($dateTime->getTimestamp(), 'html_date'),
    +      '@date' => \Drupal::service('date.formatter')->
    +       format($dateTime->getTimestamp(), 'html_date'),
         ])->render();

    Drupal coding standards do not say that lines must be shorter than 81 characters. They are allowed to break that limit, if they are more readable.

         // If ($export_route = $this->getEntityExportRoute($entity_type)) {
    -    //   $collection->add("entity.{$entity_type_id}.export", $export_route);
    +    // $collection->add("entity.{$entity_type_id}.export", $export_route);
         // }.
    -    // If ($settings_form_route = $this->getCredentialsSettingsFormRoute($entity_type)) {
    -    //   $collection->add("entity.{$entity_type_id}_credentials.settings_form", $settings_form_route);
    +    // If ($settings_form_route = $this->getCredentialsSettingsFormRoute
    +    // ($entity_type)) {
    +    // $collection->add("entity.{$entity_type_id}_credentials.settings_form",
    +    // $settings_form_route);
         // }.
    -    // If ($logger_settings_form_route = $this->getOmdbApiLoggerSettingsFormRoute($entity_type)) {
    -    //   $collection->add("entity.{$entity_type_id}_logger.settings_form", $logger_settings_form_route);
    +    // If ($logger_settings_form_route = $this->getOmdbApiLoggerSettings
    +    // FormRoute($entity_type)) {
    +    // $collection->add("entity.{$entity_type_id}_logger.settings_form",
    +    // $logger_settings_form_route);
         // }.
    -    // If ($logger_settings_form_route = $this->getOmdbApiLogViewControllerRoute($entity_type)) {
    -    //   $collection->add("entity.{$entity_type_id}.log_view", $logger_settings_form_route);
    +    // If ($logger_settings_form_route = $this->
    +    // getOmdbApiLogViewControllerRoute($entity_type)) {
    +    // $collection->add("entity.{$entity_type_id}.log_view",
    +    // $logger_settings_form_route);

    Although that code is commented out, that is still code. Removing the indentation where it is correctly used is wrong, like it is splitting a control structure in two or more lines.

    -  /**
    -   * Tests the OMDB API module reinstalling after being uninstalled.
    -   */
    +  // Tests the OMDB API module reinstalling after being uninstalled.

    The documentation comments for methods and functions use /* and */ as delimiters, not //.

       // Public function testReinstallAfterUninstall() {
       // $admin_user = $this->drupalCreateUser([
    -  //     'access administration pages',
    -  //     'administer site configuration',
    -  //     'administer modules',
    -  //   ]);
    +  // 'access administration pages',
    +  // 'administer site configuration',
    +  // 'administer modules',
    +  // ]);
       // $drupalFinder = new DrupalFinder();
    -  //   $drupalFinder->locateRoot(getcwd());
    -  //   $drupalRoot = $_ENV['DRUPAL_ROOT'] ?? $drupalFinder->getDrupalRoot();
    +  // $drupalFinder->locateRoot(getcwd());
    +  // $drupalRoot = $_ENV['DRUPAL_ROOT'] ?? $drupalFinder->getDrupalRoot();
       // // Uninstall the module.
    -  //   $this->drupalLogin($admin_user);
    -  //   $this->assertDirectoryExists($drupalRoot . '/sites/default/files/public/omdb-api/qrcodes');
    -  //   $assert_session = $this->assertSession();
    -  //   $page = $this->getSession()->getPage();
    +  // $this->drupalLogin($admin_user);
    +  // $this->assertDirectoryExists($drupalRoot .
    +  // '/sites/default/files/public/omdb-api/qrcodes');
    +  // $assert_session = $this->assertSession();
    +  // $page = $this->getSession()->getPage();
       // // Uninstall the OMDB API module.
    -  //   $this->container->get('module_installer')->uninstall(['omdb_api'], FALSE);
    +  // $this->container->get('module_installer')
    +  // ->uninstall(['omdb_api'], FALSE);
       // $this->drupalGet('/admin/modules');
    -  //   $page->checkField('modules[omdb_api][enable]');
    -  //   $page->pressButton('Install');
    -  //   $assert_session->pageTextNotContains('Unable to install OMDB API');
    -  //   $assert_session->pageTextContains('Module OMDB API has been enabled');
    +  // $page->checkField('modules[omdb_api][enable]');
    +  // $page->pressButton('Install');
    +  // $assert_session->pageTextNotContains('Unable to install OMDB API');
    +  // $assert_session->pageTextContains('Module OMDB API has been enabled');
       // }.
     }

    Those changes are wrong because they change the code indentation where it should not be changed. Commented-out code is still code and it is formatted as code should be formatted.

  • Status changed to Needs review over 1 year ago
  • Hi @Neeraj333, I have applied your patch.

    These are the steps I followed:

    1. Took clone from git in drupal 10.1.x
    2. Applied patch.
    3. Ran this command:

    ./vendor/bin/phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml,twig modules/contrib/omdb_api/

    But I found errors.

    I have fixed that error with phpcbf.

    Ran this command to fix the errors:

    ./vendor/bin/phpcbf --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml,twig modules/contrib/omdb_api/

    Then again checked with phpcs:

    ./vendor/bin/phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml,twig modules/contrib/omdb_api/

    Found no errors.

    Needs Review.

  • Status changed to RTBC about 1 year ago
  • 🇵🇭Philippines roberttabigue

    Hi,

    I have reviewed the changes and confirmed that Patch #5 was applied cleanly to the OMDB API module on Drupal 10.1.2.

    And all PHPCS errors have been fixed.

    I re-ran this command on the module:
    phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml,twig omdb_api/

    Please see the attached file for reference.

    I'm moving this now to RTBC.

    Thank you!

  • Status changed to Needs work about 1 year ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
    -    $css = file_get_contents($module_path . '/libraries/css/pdf.css');
    +    file_get_contents($module_path . '/libraries/css/pdf.css');

    Calling file_get_contents(), which returns the content of the file as array, and not using the returned value is not much helpful. If $css is really not used after being initialized, that line should be removed.

         // If ($this->isNew()) {
    -    //   $this->setCreatedTime(time());
    +    // $this->setCreatedTime(time());
         // }
         // else {
    -    //   $this->setRevisionCreationTime(time());
    -    //   $this->setChangedTime(time());
    +    // $this->setRevisionCreationTime(time());
    +    // $this->setChangedTime(time());

    The existing code is correctly indented. Even when commented out, the code indentation does not change.

  • 🇮🇳India pray_12

    Hi,
    I applied patch #8 and noticed that numerous PHPCS issues are still being flagged, and the comments from #8 have not been addressed.

  • 🇮🇳India pray_12

    Hi,
    Addressed the #7 first comment.

  • 🇮🇳India zkhan.aamir

    Hi,

    Patch #10 applied successfully.

    Admin@DESKTOP-252TO6V MINGW64 ~/Desktop/projects/drupal/web/modules/omdb_api (1.x-dev)
    $ curl https://www.drupal.org/files/issues/2024-02-08/phpcs-fix-3293047-10.patch | patch -p1
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100 14013  100 14013    0     0  14791      0 --:--:-- --:--:-- --:--:-- 14797
    patching file README.md
    patching file omdb_api.install
    patching file omdb_api.module
    patching file src/Entity/Controller/OmdbApiEntityController.php
    patching file src/Entity/Form/OmdbApiEntityForm.php
    patching file src/Entity/Logger/OmdbApiEntityLogger.php
    patching file src/Entity/OmdbApiEntity.php
    patching file src/Entity/OmdbApiEntityInterface.php
    patching file src/Entity/OmdbApiEntityUninstallValidator.php
    patching file src/Entity/Routing/OmdbApiEntityHtmlRouteProvider.php
    patching file src/Entity/Storage/OmdbApiEntityStorage.php
    patching file src/Entity/Storage/OmdbApiEntityStorageInterface.php
    patching file src/Plugin/Derivative/OmdbApiContextualLinks.php
    patching file src/Plugin/Derivative/OmdbApiEntityBundlesMenuLinksDerivative.php
    patching file src/Plugin/DevelGenerate/OmdbApiEntityDevelGenerate.php
    patching file src/Plugin/Validation/Constraint/OmdbApiImdbIdConstraintValidator.php
    patching file tests/src/Kernel/DirectoryTest.php
    

    Still issue remaining.

    Admin@DESKTOP-252TO6V MINGW64 ~/Desktop/projects/drupal/web/modules
    $ phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,info,txt,md,css,js,yml omdb_api/
    
    FILE: C:\Users\Admin\Desktop\projects\drupal\web\modules\omdb_api\libraries\js\response-data-table.js
    -----------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    -----------------------------------------------------------------------------------------------------
     1 | ERROR | [x] Additional whitespace found at start of file
    -----------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    -----------------------------------------------------------------------------------------------------
    
    Time: 2.18 secs; Memory: 18MB
    
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
        // If ($this->isNew()) {
    -    //   $this->setCreatedTime(time());
    +    // $this->setCreatedTime(time());
         // }
         // else {
    -    //   $this->setRevisionCreationTime(time());
    -    //   $this->setChangedTime(time());
    +    // $this->setRevisionCreationTime(time());
    +    // $this->setChangedTime(time());
         // }

    The existing code is correctly indented, contrary to the new code.

  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • Status changed to Needs review 8 months ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • 🇮🇳India Yashaswi18

    On running the command phpcs --standard=Drupal,DrupalPractice -extensions=php,module,inc,install,test,profile,theme,info,txt,md,yml,css, found these errors remaining:

    FILE: /home/yashaswi/contribs/omdb_api/src/Entity/Controller/OmdbApiEntityController.php
    ------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AND 1 WARNING AFFECTING 2 LINES
    ------------------------------------------------------------------------------------------------------------------------
       8 | ERROR   | [x] Use statements should be sorted alphabetically. The first wrong one is
         |         |     Drupal\Component\Utility\Xss.
     307 | WARNING | [ ] Unused variable $css.
    ------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /home/yashaswi/contribs/omdb_api/src/Entity/Routing/OmdbApiEntityHtmlRouteProvider.php
    ------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ------------------------------------------------------------------------------------------------------------------------
     7 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is
       |       |     Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider.
    ------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /home/yashaswi/contribs/omdb_api/src/Entity/Form/OmdbApiEntityForm.php
    ------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ------------------------------------------------------------------------------------------------------------------------
     7 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is
       |       |     Drupal\Core\DependencyInjection\ContainerInjectionInterface.
    ------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /home/yashaswi/contribs/omdb_api/src/Entity/Storage/OmdbApiEntityStorageInterface.php
    ------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ------------------------------------------------------------------------------------------------------------------------
     7 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is
       |       |     Drupal\Core\Language\LanguageInterface.
    ------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /home/yashaswi/contribs/omdb_api/src/Entity/Storage/OmdbApiEntityStorage.php
    ------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ------------------------------------------------------------------------------------------------------------------------
     7 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is
       |       |     Drupal\Core\Language\LanguageInterface.
    ------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /home/yashaswi/contribs/omdb_api/src/Entity/OmdbApiEntityUninstallValidator.php
    ------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ------------------------------------------------------------------------------------------------------------------------
     8 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is
       |       |     Drupal\Core\Entity\ContentEntityTypeInterface.
    ------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /home/yashaswi/contribs/omdb_api/src/Entity/Logger/OmdbApiEntityLogger.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: /home/yashaswi/contribs/omdb_api/src/Entity/OmdbApiEntity.php
    ------------------------------------------------------------------------------------------------------------------------
    FOUND 3 ERRORS AFFECTING 3 LINES
    ------------------------------------------------------------------------------------------------------------------------
      13 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is
         |       |     Drupal\Core\StringTranslation\TranslatableMarkup.
     147 | ERROR | [ ] Comment indentation error, expected only 1 spaces
     150 | ERROR | [ ] Comment indentation error, expected only 1 spaces
    ------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /home/yashaswi/contribs/omdb_api/src/Entity/OmdbApiEntityInterface.php
    ------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ------------------------------------------------------------------------------------------------------------------------
     8 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is
       |       |     Drupal\Core\Entity\RevisionLogInterface.
    ------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /home/yashaswi/contribs/omdb_api/src/Plugin/Derivative/OmdbApiEntityBundlesMenuLinksDerivative.php
    ------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ------------------------------------------------------------------------------------------------------------------------
     7 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is
       |       |     Drupal\Core\Entity\EntityTypeManagerInterface.
    ------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /home/yashaswi/contribs/omdb_api/src/Plugin/Derivative/OmdbApiContextualLinks.php
    ------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ------------------------------------------------------------------------------------------------------------------------
     7 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is
       |       |     Drupal\Core\Entity\EntityTypeManagerInterface.
    ------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /home/yashaswi/contribs/omdb_api/src/Plugin/DevelGenerate/OmdbApiEntityDevelGenerate.php
    ------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ------------------------------------------------------------------------------------------------------------------------
     8 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is
       |       |     Drupal\Component\Datetime\TimeInterface.
    ------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /home/yashaswi/contribs/omdb_api/src/Plugin/Validation/Constraint/OmdbApiImdbIdConstraintValidator.php
    ------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ------------------------------------------------------------------------------------------------------------------------
     7 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is
       |       |     Drupal\omdb_api\Entity\OmdbApiEntityInterface.
    ------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /home/yashaswi/contribs/omdb_api/tests/src/Kernel/DirectoryTest.php
    ------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ------------------------------------------------------------------------------------------------------------------------
     6 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is
       |       |     Drupal\Core\File\FileSystemInterface.
    ------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /home/yashaswi/contribs/omdb_api/README.md
    ----------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    ----------------------------------------------------------------------
     101 | WARNING | Line exceeds 80 characters; contains 354 characters
    ----------------------------------------------------------------------
    
    
    FILE: /home/yashaswi/contribs/omdb_api/omdb_api.module
    ------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ------------------------------------------------------------------------------------------------------------------------
     10 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is
        |       |     Drupal\omdb_api\Entity\Bundle\Series.
    ------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /home/yashaswi/contribs/omdb_api/omdb_api.install
    ------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AND 1 WARNING AFFECTING 2 LINES
    ------------------------------------------------------------------------------------------------------------------------
      9 | ERROR   | [x] Use statements should be sorted alphabetically. The first wrong one is
        |         |     Drupal\Core\File\FileSystemInterface.
     67 | WARNING | [ ] There must be no blank line following an inline comment
    ------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ------------------------------------------------------------------------------------------------------------------------
  • Status changed to Needs work 8 months ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    GitLab CI has been enabled, but it needs a PHP_CodeSniffer settings file, since it reports errors/warnings that are not relevant for Drupal code, like the following one.

    14 | ERROR | [ ] Missing @category tag in class comment
    | | (PEAR.Commenting.ClassComment.MissingCategoryTag)
    14 | ERROR | [ ] Missing @package tag in class comment
    | | (PEAR.Commenting.ClassComment.MissingPackageTag)
    14 | ERROR | [ ] Missing @author tag in class comment
    | | (PEAR.Commenting.ClassComment.MissingAuthorTag)
    14 | ERROR | [ ] Missing @license tag in class comment
    | | (PEAR.Commenting.ClassComment.MissingLicenseTag)
    14 | ERROR | [ ] Missing @link tag in class comment

    None of those tags are required for a Drupal module.

Production build 0.71.5 2024