Fix the issues reported by phpcs

Created on 21 December 2022, about 2 years ago
Updated 26 July 2023, over 1 year ago

Problem/Motivation

Getting following error/warnings

FILE: /app/modules/contrib/profile/src/Entity/Profile.php
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
147 | ERROR | [x] Use null coalesce operator instead of ternary
| | operator.
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

FILE: /app/modules/contrib/profile/src/Form/ProfileTypeForm.php
----------------------------------------------------------------------
FOUND 0 ERRORS AND 7 WARNINGS AFFECTING 7 LINES
----------------------------------------------------------------------
28 | WARNING | t() calls should be avoided in classes, use
| | \Drupal\Core\StringTranslation\StringTranslationTrait
| | and $this->t() instead
31 | WARNING | t() calls should be avoided in classes, use
| | \Drupal\Core\StringTranslation\StringTranslationTrait
| | and $this->t() instead
45 | WARNING | t() calls should be avoided in classes, use
| | \Drupal\Core\StringTranslation\StringTranslationTrait
| | and $this->t() instead
48 | WARNING | t() calls should be avoided in classes, use
| | \Drupal\Core\StringTranslation\StringTranslationTrait
| | and $this->t() instead
53 | WARNING | t() calls should be avoided in classes, use
| | \Drupal\Core\StringTranslation\StringTranslationTrait
| | and $this->t() instead
58 | WARNING | t() calls should be avoided in classes, use
| | \Drupal\Core\StringTranslation\StringTranslationTrait
| | and $this->t() instead
63 | WARNING | t() calls should be avoided in classes, use
| | \Drupal\Core\StringTranslation\StringTranslationTrait
| | and $this->t() instead
----------------------------------------------------------------------

FILE: ...ntrib/profile/src/Plugin/Field/FieldWidget/ProfileFormWidget.php
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
126 | ERROR | [x] Use null coalesce operator instead of ternary
| | operator.
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

FILE: ...ules/contrib/profile/tests/src/Functional/ProfileDefaultTest.php
----------------------------------------------------------------------
FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
----------------------------------------------------------------------
71 | WARNING | t() calls should be avoided in classes, use
| | \Drupal\Core\StringTranslation\StringTranslationTrait
| | and $this->t() instead
87 | WARNING | t() calls should be avoided in classes, use
| | \Drupal\Core\StringTranslation\StringTranslationTrait
| | and $this->t() instead
----------------------------------------------------------------------

FILE: ...contrib/profile/tests/src/Functional/ProfileRegisterFormTest.php
----------------------------------------------------------------------
FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
----------------------------------------------------------------------
45 | WARNING | t() calls should be avoided in classes, use
| | \Drupal\Core\StringTranslation\StringTranslationTrait
| | and $this->t() instead
53 | WARNING | t() calls should be avoided in classes, use
| | \Drupal\Core\StringTranslation\StringTranslationTrait
| | and $this->t() instead
----------------------------------------------------------------------

FILE: ...modules/contrib/profile/tests/src/Functional/ProfileTypeTest.php
----------------------------------------------------------------------
FOUND 0 ERRORS AND 3 WARNINGS AFFECTING 3 LINES
----------------------------------------------------------------------
105 | WARNING | t() calls should be avoided in classes, use
| | \Drupal\Core\StringTranslation\StringTranslationTrait
| | and $this->t() instead
136 | WARNING | t() calls should be avoided in classes, use
| | \Drupal\Core\StringTranslation\StringTranslationTrait
| | and $this->t() instead
143 | WARNING | t() calls should be avoided in classes, use
| | \Drupal\Core\StringTranslation\StringTranslationTrait
| | and $this->t() instead
----------------------------------------------------------------------

Time: 1.81 secs; Memory: 14MB

Steps to reproduce

Run following command

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

Proposed resolution

Run phpcbf for auto fixable issues, and do manual fixes.
Above error/warnings need to be fixed.

Remaining tasks

User interface changes

API changes

Data model changes

📌 Task
Status

Needs work

Version

1.0

Component

Code

Created by

🇮🇳India shivam-kumar

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.

  • 🇮🇳India Charchil Khandelwal

    The patch #5 has been reviewed and applied cleanly, but a few phpcs still remain.

    FILE: C:\xampp\htdocs\abc\drupal\modules\profile\README.md
    ----------------------------------------------------------------------
    FOUND 0 ERRORS AND 6 WARNINGS AFFECTING 6 LINES
    ----------------------------------------------------------------------
    47 | WARNING | Line exceeds 80 characters; contains 194 characters
    48 | WARNING | Line exceeds 80 characters; contains 146 characters
    49 | WARNING | Line exceeds 80 characters; contains 117 characters
    53 | WARNING | Line exceeds 80 characters; contains 158 characters
    55 | WARNING | Line exceeds 80 characters; contains 101 characters
    56 | WARNING | Line exceeds 80 characters; contains 120 characters
    ----------------------------------------------------------------------

  • @charchil-khandelwal opened merge request.
  • Issue was unassigned.
  • Status changed to Needs review almost 2 years ago
  • 🇮🇳India Charchil Khandelwal

    Created MR, Please review.

  • 🇮🇳India rajneeshb New Delhi

    Reviewed MR !15 all coding standard issues fixed. Also the readme.md file warning also fixed.

  • Status changed to RTBC almost 2 years ago
  • 🇮🇳India arunkumark Coimbatore

    The MR !15 applied cleanly and resolve all the PHPCS issue for the module. Moving to RTBC.

  • Status changed to Needs work almost 2 years ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
    +  use StringTranslationTrait;
       /**
        * Profile entity storage.

    The must be an empty line after use StringTranslationTrait; which is missing.

  • Assigned to imustakim
  • 🇨🇦Canada imustakim Canada

    working on this.

  • Issue was unassigned.
  • Status changed to Needs review almost 2 years ago
  • 🇨🇦Canada imustakim Canada

    Patch updated.
    Please review.

  • First commit to issue fork.
  • @nayana_mvr opened merge request.
  • 🇮🇳India nayana_mvr

    Verified the patch #14. The patch applied with a warning message:

    3328568-14.patch:108: trailing whitespace.
      
    Checking patch src/Entity/Profile.php...
    Checking patch src/Form/ProfileTypeForm.php...
    Checking patch src/Plugin/Field/FieldWidget/ProfileFormWidget.php...
    Checking patch tests/src/Functional/ProfileDefaultTest.php...
    Checking patch tests/src/Functional/ProfileRegisterFormTest.php...
    Checking patch tests/src/Functional/ProfileTypeTest.php...
    Applied patch src/Entity/Profile.php cleanly.
    Applied patch src/Form/ProfileTypeForm.php cleanly.
    Applied patch src/Plugin/Field/FieldWidget/ProfileFormWidget.php cleanly.
    Applied patch tests/src/Functional/ProfileDefaultTest.php cleanly.
    Applied patch tests/src/Functional/ProfileRegisterFormTest.php cleanly.
    Applied patch tests/src/Functional/ProfileTypeTest.php cleanly.
    warning: 1 line adds whitespace errors.

    Also, the warnings related to README.md file was not there in the patch. So I have fixed the above warning and the warnings in the README file and created a new MR. Please review. Thanks.

  • 🇮🇳India rajneeshb New Delhi

    Reviewd MR 19 looks good. +1 for RTBC, Attaching screenshots for reference.

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

    Hi,

    I applied the latest MR to the Profile module against 8.x-1.x-dev on Drupal 9.5.10 and confirmed all PHPCS errors have been fixed.

    I ran this command:

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

    Please see the attached files for reference.

    I'm moving this now to RTBC.

    Thank you!

  • Status changed to Needs work over 1 year ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • First commit to issue fork.
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.3 & MySQL 5.7
    last update over 1 year ago
    23 pass
  • 🇮🇳India mukhtarm

    @apaderno Addressed the changes mentioned in MR. Please review.

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

    Hi @MukhtarM,

    I reviewed your latest changes and after applying MR !19, there are new warnings found.

    Please see the attached file for reference.

    Moving this to Needs work for now for investigation.

    Thank you!

  • 🇮🇳India mukhtarm

    hi @roberttabigue ohh actually it needs to not use either "t()" or "$this->t()" there in the tests.
    Its mentioned in the comment: #20 📌 Fix the issues reported by phpcs Needs work
    I will correct this in the MR.
    refer this too: https://drupal.stackexchange.com/questions/258535/should-i-translate-str...

  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.3 & MySQL 5.7
    last update over 1 year ago
    16 pass, 6 fail
  • 🇮🇳India mukhtarm

    @roberttabigue I made the changes in the same MR , please check. Also the same is applied to some related tests (ProfileRegisterFormTest and ProfileTypeTest) too. thanks

  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.3 & MySQL 5.7
    last update over 1 year ago
    17 pass, 4 fail
Production build 0.71.5 2024