Fix the issues reported by phpcs

Created on 19 May 2023, over 1 year ago
Updated 13 March 2024, 8 months ago

Problem/Motivation

vendor/bin/phpcs   --standard="Drupal,DrupalPractice" -n   --extensions="php,module,inc,install,test,profile,theme,yml"   web/modules/contrib/verf/

white executing PHPCS we are getting below PHPCS errors.

FILE: /home/shivsharma/project/my-drupal10-site/web/modules/contrib/verf/tests/verf_test_views/verf_test_views.info.yml
-----------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
-----------------------------------------------------------------------------------------------------------------------
 11 | ERROR | [x] Expected 1 newline at end of file; 0 found
-----------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-----------------------------------------------------------------------------------------------------------------------


FILE: /home/shivsharma/project/my-drupal10-site/web/modules/contrib/verf/tests/src/Functional/IntegrationTest.php
-----------------------------------------------------------------------------------------------------------------
FOUND 9 ERRORS AFFECTING 5 LINES
-----------------------------------------------------------------------------------------------------------------
  61 | ERROR | [x] TRUE, FALSE and NULL must be uppercase; expected "TRUE" but found "true"
 126 | ERROR | [ ] Parameter comment must start with a capital letter
 126 | ERROR | [x] Parameter comment must end with a full stop
 128 | ERROR | [ ] Parameter comment must start with a capital letter
 128 | ERROR | [x] Parameter comment must end with a full stop
 140 | ERROR | [ ] Parameter comment must start with a capital letter
 140 | ERROR | [x] Parameter comment must end with a full stop
 142 | ERROR | [ ] Parameter comment must start with a capital letter
 142 | ERROR | [x] Parameter comment must end with a full stop
-----------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 5 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-----------------------------------------------------------------------------------------------------------------


FILE: /home/shivsharma/project/my-drupal10-site/web/modules/contrib/verf/src/Plugin/views/filter/EntityReference.php
--------------------------------------------------------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 2 LINES
--------------------------------------------------------------------------------------------------------------------
  29 | ERROR | [x] Opening brace should be on the same line as the declaration
 205 | ERROR | [ ] Description for the @return value is missing
--------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------------------------------------------


FILE: /home/shivsharma/project/my-drupal10-site/web/modules/contrib/verf/verf.info.yml
--------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------------
 4 | ERROR | [x] Expected 1 newline at end of file; 0 found
--------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------------

Steps to reproduce

executed PHPCS on verf module.

vendor/bin/phpcs   --standard="Drupal,DrupalPractice" -n   --extensions="php,module,inc,install,test,profile,theme,yml"   web/modules/contrib/verf/
📌 Task
Status

RTBC

Version

2.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 Nishant
  • @nishant opened merge request.
  • Merge request !9Fixed Phpcs Issue → (Open) created by Nishant
  • Status changed to Needs review over 1 year ago
  • Status changed to Needs work over 1 year ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    The report shows errors/warnings for two files, but the MR changes four files.

  • 🇮🇳India Nishant

    @apaderno,

    If you see the reporter command,
    vendor/bin/phpcs --standard="Drupal,DrupalPractice" -n --extensions="php,module,inc,install,test,profile,theme", There is 'yml' is missing in extensions list, that's why they unable to find issue in 'tests/verf_test_views/verf_test_views.info.yml' and 'verf.info.yml'

    I have run this command
    vendor/bin/phpcs --standard="Drupal,DrupalPractice" -n --extensions="php,module,inc,install,test,profile,theme,yml"
    and I got issues in 4 files that I have fixed and created MR.

  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    @Nishant In that case, the command shown in the issue summary must be updated to include that extension. The command shown in the issue summary must be the same used when fixing the existing issues.

  • 🇮🇳India Shiv_Sharma

    updated the issue @apaderno

  • 🇮🇳India Nishant

    Will take care from next. @apaderno

  • Status changed to Needs review over 1 year ago
  • Status changed to Needs work over 1 year ago
  • 🇵🇭Philippines paraderojether

    Hi I reviewed MR!9, and there is still remaining issue reported by phpcs shown below:

    FILE: .../studenttrainees/Drupal.org/drupalorg-site/docroot/modules/contrib/verf/tests/src/Functional/IntegrationTest.php
    ----------------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
    ----------------------------------------------------------------------------------------------------------------------
     171 | WARNING | Unused variable $referencingPublished.
     175 | WARNING | Unused variable $referencingUnpublished.
    ----------------------------------------------------------------------------------------------------------------------
    
    
    FILE: ...udenttrainees/Drupal.org/drupalorg-site/docroot/modules/contrib/verf/src/Plugin/views/filter/EntityReference.php
    ----------------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
    ----------------------------------------------------------------------------------------------------------------------
       7 | WARNING | [x] Unused use statement
     136 | WARNING | [ ] t() calls should be avoided in classes, use
         |         |     \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
    ----------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ----------------------------------------------------------------------------------------------------------------------
    
    Time: 259ms; Memory: 10MB

    I will try to work on this.

  • Status changed to Needs review over 1 year ago
  • 🇵🇭Philippines paraderojether

    Created a patch to fix the remaining issues.

    Please review.
    Thank You.

  • Issue was unassigned.
  • 🇮🇳India arpitk

    Hi I reviewed the patch #13 it applied cleanly. No errors/warnings by phpcs are reported after applying the patch.

    Thanks!

  • 🇮🇳India Abh1shek

    Hi @paraderojether, your patch applied cleanly, but I found 1 error. Here are the steps I have followed:

    1. Taken clone from git version 2.0.x in drupal 10.1.2
    2. Applied your patch and ran the phpcs command
    3. Found 1 error

    4. Then ran the phpcbf command to fix that error. Now It is error free.

    Attaching screenshots and patch.
    Please review.

  • Status changed to RTBC over 1 year ago
  • Hi @Abh1shek Chauhan, I have applied your patch.

    These are the steps I followed:

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

    2. 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/verf

    3. Applied patch and again ran phpcs command.

    I found no error. Moving it to RTBC.

  • Status changed to Needs work over 1 year ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
         $form['show_unpublished'] = [
           '#type' => 'checkbox',
    -      '#title' => t("Ignore access control"),
    -      '#default_value' => $this->options['show_unpublished'],
    +      '#title' => $this->t("Ignore access control"),
    +      '#default_value' => $options['show_unpublished'],
         ];

    There is not any $options variable in buildOptionsForm().

      /**
       * {@inheritdoc}
       */
      public function buildOptionsForm(&$form, FormStateInterface $form_state) {
        parent::buildOptionsForm($form, $form_state);
    
        $form['show_unpublished'] = [
          '#type' => 'checkbox',
          '#title' => t("Ignore access control"),
          '#default_value' => $this->options['show_unpublished'],
        ];
    
        if (!$this->targetEntityType->hasKey('bundle')) {
          return $form;
        }
    
        $options = [];
        $bundleInfo = $this->entityTypeBundleInfo->getBundleInfo($this->targetEntityType->id());
        foreach ($bundleInfo as $id => $info) {
          $options[$id] = $info['label'];
        }
    
        $form['verf_target_bundles'] = [
          '#type' => 'checkboxes',
          '#title' => $this->t('Target entity bundles to filter by'),
          '#options' => $options,
          '#default_value' => array_filter($this->options['verf_target_bundles']),
        ];
    
        return $form;
      }
    
        * @return \Drupal\Core\Entity\EntityInterface[]
    +   *   The Reference entity.
    

    Reference is misspelled, since it is not the first word.

        * @param string $locator
    -   *   input id, name or label
    +   *   Input id, name or label.
    

    It is ID, not id.

        * @param string $value
    -   *   option value
    +   *   Option value.
    

    A definite article is missing.

    -    $referencingPublished = $this->drupalCreateNode([
    +    $this->drupalCreateNode([
           'type' => $this->nodeType->id(),
           'field_refs' => [['target_id' => $published->id()]],
         ]);
    -    $referencingUnpublished = $this->drupalCreateNode([
    -      'type' => $this->nodeType->id(),
    -      'field_refs' => [['target_id' => $unpublished->id()]],
    -    ]);
    

    The code is creating two nodes. Why is the code that creates the node with a reference to the unpublished node removed?

  • Status changed to Needs review over 1 year ago
  • 🇮🇳India subhashuyadav Mumbai

    Here is the updated patch as per @apaderno comments.

  • Status changed to Needs work over 1 year ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
    -    $form['show_unpublished'] = [
    -      '#type' => 'checkbox',
    -      '#title' => t("Ignore access control"),
    -      '#default_value' => $this->options['show_unpublished'],
    -    ];
    -
         if (!$this->targetEntityType->hasKey('bundle')) {
           return $form;
         }
    @@ -148,6 +140,12 @@ class EntityReference extends InOperator implements ContainerFactoryPluginInterf
           $options[$id] = $info['label'];
         }
     
    +    $form['show_unpublished'] = [
    +      '#type' => 'checkbox',
    +      '#title' => $this->t("Ignore access control"),
    +      '#default_value' => $options['show_unpublished'],
    +    ];
    +

    The existing code correctly uses $this->options. It does not need to be changed, except to remove the call to t(), nor those lines need to be moved.

        * @return \Drupal\Core\Entity\EntityInterface[]
    +   *   The reference entity.

    Since the return value is an array, it cannot be described as The reference entity.

    -   *   input id, name or label
    +   *   Input id, name or label.

    It is ID, not id.
    A comma is missing after name.

    -    $this->assertSelectOptionCanBeSelected('Refs (VERF selector)', $published->getTitle());
    -    $this->assertSelectOptionCanBeSelected('Refs (VERF selector)', $unpublished->getTitle());
    +    $this->assertSelectOptionCanBeSelected('Refs (VERF selector)', $referencingPublished->getTitle());
    +    $this->assertSelectOptionCanBeSelected('Refs (VERF selector)', $referencingUnpublished->getTitle());
     
         $this->drupalLogin($this->author);
         $this->drupalGet('verftest');
    -    $this->assertSelectOptionCanBeSelected('Refs (VERF selector)', $published->getTitle());
    -    $this->assertSelectOptionCanBeSelected('Refs (VERF selector)', $unpublished->getTitle());
    +    $this->assertSelectOptionCanBeSelected('Refs (VERF selector)', $referencingPublished->getTitle());
    +    $this->assertSelectOptionCanBeSelected('Refs (VERF selector)', $referencingUnpublished->getTitle());
     
         $this->drupalLogout();
         $this->drupalGet('verftest');
    -    $this->assertSelectOptionCanBeSelected('Refs (VERF selector)', $published->getTitle());
    +    $this->assertSelectOptionCanBeSelected('Refs (VERF selector)', $referencingPublished->getTitle());
         $this->assertSelectOptionCanBeSelected('Refs (VERF selector)', '- Restricted access -');
    -    $this->assertSelectOptionCanNotBeSelected('Refs (VERF selector)', $unpublished->getTitle());
    +    $this->assertSelectOptionCanNotBeSelected('Refs (VERF selector)', $referencingUnpublished->getTitle());

    Why are the variables passed to those methods changed?

  • Assigned to nitin_lama
  • 🇮🇳India nitin_lama India

    Updated patch as per #20 comment.

  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.2 & MySQL 8
    last update over 1 year ago
    2 fail
  • Status changed to Needs work over 1 year ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    Tests that runs when a patch is checked are failing.

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.2 & MySQL 8
    last update over 1 year ago
    2 fail
  • Status changed to Needs review about 1 year ago
  • 🇮🇳India amit.rawat777

    please review this, I have resolved some issues.

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.2 & MySQL 8
    last update about 1 year ago
    2 fail
  • 🇮🇳India Yashaswi18

    Hello, I tried applying the patch provided in #25, it is applying succesfully.
    I ran the command phpcs --standard=Drupal --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml to verify, there is one error remaining in \src\Plugin\views\filter\EntityReference.php.

    11 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\Core\Extension\ModuleHandlerInterface.

  • 🇷🇺Russia zniki.ru

    Nikolay Shapovalov changed the visibility of the branch 3361499-phpcs-issue-on to hidden.

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

    Thanks everyone for contributions, but I get lost in this issue.
    What is the workflow used in this issue?

    @Nishant created the Merge Request, but @paraderojether later created patch.
    I don't see any explanation why workflow was changed.
    https://www.drupal.org/docs/develop/git/using-git-to-contribute-to-drupa...

    I hide branch 3361499-phpcs-issue-on, because no changes were made in the branch.
    And as mentioned at #26 I will move Status to Needs work.

    I add interdiff file for #25.

  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    Since there is an issue fork, let's use that instead or patches.

  • I cloned the project and ran the command phpcs --standard=Drupal --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml

    Found no phpcs errors

  • Status changed to Needs review 10 months ago
  • 🇮🇳India pray_12

    Hi,
    I ran this command phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml verf/ and found following warnings.

    FILE: /verf/src/Plugin/views/filter/EntityReference.php
    ------------------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    ------------------------------------------------------------------------------------------------------------------------
     135 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and
         |         | $this->t() instead
    ------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /verf/tests/src/Functional/IntegrationTest.php
    ---------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
    ---------------------------------------------------------------------------------------------------------
     171 | WARNING | Unused variable $referencingPublished.
     175 | WARNING | Unused variable $referencingUnpublished.
    ---------------------------------------------------------------------------------------------------------
  • Hi,
    I checked for phpcs issues for MR!9 using phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml verf/
    Found no errors and warnings.

  • Pipeline finished with Failed
    8 months ago
    Total: 139s
    #118471
  • Status changed to RTBC 8 months ago
Production build 0.71.5 2024