Fix the issues reported by phpcs

Created on 5 April 2023, over 1 year ago
Updated 31 January 2024, 10 months ago

Problem/Motivation

Getting the following errors/warnings.

FILE: /set_front_page/tests/src/Functional/SetFrontPageTests.php
---------------------------------------------------------------------------
FOUND 7 ERRORS AND 11 WARNINGS AFFECTING 17 LINES
---------------------------------------------------------------------------
  55 | ERROR   | [x] Space before opening parenthesis of function call prohibited
  58 | WARNING | [x] A comma should follow the last multiline array item. Found: 'set front page'
  82 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
  90 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
  98 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 111 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 120 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 128 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 141 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 145 | ERROR   | [x] Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
 157 | ERROR   | [x] Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
 164 | ERROR   | [x] Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
 177 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 195 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 212 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 218 | ERROR   | [x] Expected 1 blank line after function; 0 found
 219 | ERROR   | [x] Expected 1 newline at end of file; 2 found
 219 | ERROR   | [x] The closing brace for the class must have an empty line before it
------------------------------------------------------------------------------


FILE: /set_front_page/README.txt
-------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
-------------------------------------------------------------------------------
 37 | WARNING | Line exceeds 80 characters; contains 141 characters
-------------------------------------------------------------------------------


FILE: /set_front_page/set_front_page.install
-------------------------------------------------------------------------------
FOUND 3 ERRORS AFFECTING 3 LINES
-------------------------------------------------------------------------------
 1 | ERROR | [x] Missing file doc comment
 3 | ERROR | [x] Missing function doc comment
 4 | ERROR | [x] Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
----------------------------------------------------------------------------------------------------------


FILE: /set_front_page/src/Form/SetFrontPageConfigForm.php
-----------------------------------------------------------------------------
FOUND 1 ERROR AND 4 WARNINGS AFFECTING 3 LINES
-----------------------------------------------------------------------------
 133 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 158 | ERROR   | [x] Use null coalesce operator instead of ternary operator.
 230 | WARNING | [x] '@todo: validate entity types' should match the format '@todo Fix problem X here.'
 230 | WARNING | [x] There must be no blank line following an inline comment
 230 | WARNING | [ ] There must be no blank line following an inline comment
-----------------------------------------------------------------------------


FILE: /set_front_page/src/Form/SetFrontPageEntitySettings.php
-----------------------------------------------------------------------------
FOUND 0 ERRORS AND 6 WARNINGS AFFECTING 6 LINES
-----------------------------------------------------------------------------
 181 | WARNING | Unused variable $config.
 184 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
 185 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
 198 | WARNING | Unused variable $config.
 202 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
 203 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
--------------------------------------------------------------------------------


FILE: /set_front_page/src/SetFrontPageManager.php
-------------------------------------------------------------------
FOUND 5 ERRORS AND 1 WARNING AFFECTING 4 LINES
-------------------------------------------------------------------
  59 | WARNING | [ ] \Drupal calls should be avoided in classes, use dependency injection instead
 114 | ERROR   | [x] Each PHP statement must be on a line by itself
 117 | ERROR   | [x] Inline comments must start with a capital letter
 117 | ERROR   | [x] Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
 122 | ERROR   | [x] Inline comments must start with a capital letter
 122 | ERROR   | [x] Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
-------------------------------------------------------------------

Steps to reproduce

Run the following command

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

Proposed resolution

The above errors/warnings need to be fixed.

📌 Task
Status

Needs review

Version

1.0

Component

Code

Created by

🇮🇳India omkar_yewale Mumbai

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 @omkar_yewale
  • 🇮🇳India omkar_yewale Mumbai

    The !2 MR was created and all errors/warnings are fixed except these two warnings.

    FILE: /set_front_page/src/Form/SetFrontPageEntitySettings.php
    -----------------------------------------------------------------------------
     181 | WARNING | Unused variable $config.
     198 | WARNING | Unused variable $config.
    -----------------------------------------------------------------------------
    

    The maintainer can make this decision.

  • Issue was unassigned.
  • Status changed to RTBC over 1 year ago
  • 🇵🇭Philippines paraderojether

    Hi omkar_yewale

    I reviewed MR!2, and confirmed that the issues reported by phpcs are fixed except for the 2 warnings:

    FILE: /Users/studenttrainees/New/drupalorgsite/docroot/modules/contrib/set_front_page/src/Form/SetFrontPageEntitySettings.php
    -----------------------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
    -----------------------------------------------------------------------------------------------------------------------------
    181 | WARNING | Unused variable $config.
    198 | WARNING | Unused variable $config.
    -----------------------------------------------------------------------------------------------------------------------------

    Time: 536ms; Memory: 10MB

    I added screenshots for reference.
    Thank You.

  • Status changed to Needs work over 1 year ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
    +/**
    + * @file
    + * Install, update and uninstall functions for set_front_page module.
    + */

    That comment must use the module name, not its machine name.
    After for, there is a missing article.

     function set_front_page_uninstall() {
    -  // Remove State
    +  // Remove State.
       \Drupal::state()->delete('set_front_page.path');

    Instead of editing that comment, it would be better to remove it, since it does not say anything that is already clear from the code.

    +   * @param \Drupal\Core\State\State $state
    +   *   The object State.

    State is misspelled, since it is not the first word of a sentence.
    The object State. is not the correct description to give.

         if ($frontpage !== NULL) {
    -      // frontpage can be empty
    +      // Frontpage can be empty.
           $this->setFrontPage($frontpage);
         }
     
         if ($default !== NULL) {
    -      // default can be empty
    +      // Default can be empty.
           $config->set('site_frontpage_default', $default);
         }

    Those comments do not make sense. $frontpage is not NULL. What does $frontpage can be empty. mean, since the code already verified that $frontpage is not empty?
    It is better to removed those comments, instead of editing them.

  • Assigned to himanshu_jhaloya
  • 🇮🇳India himanshu_jhaloya Indore

    I will work on this issue

  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • Open on Drupal.org →
    Core: 9.5.5 + Environment: PHP 8.1 & MySQL 8
    last update over 1 year ago
    Waiting for branch to pass
  • 🇮🇳India himanshu_jhaloya Indore

    Created a patch to fix the commented issues. please review

  • Status changed to Needs work over 1 year ago
  • 🇺🇸United States DamienMcKenna NH, USA

    I don't see why comments are being removed? I'll have to take a look.

  • First commit to issue fork.
  • Open on Drupal.org →
    Core: 9.5.5 + Environment: PHP 8.1 & MySQL 8
    last update 11 months ago
    Waiting for branch to pass
  • Status changed to Needs review 10 months ago
  • 🇮🇳India zkhan.aamir

    Hi

    MR #9 applied successfully.

    Admin@DESKTOP-252TO6V MINGW64 ~/Desktop/projects/drupal/web/modules/contrib/set_front_page (8.x-1.x)
    $ curl https://git.drupalcode.org/project/set_front_page/-/merge_requests/2.diff | patch -p1
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100 17508    0 17508    0     0  43039      0 --:--:-- --:--:-- --:--:-- 43229
    patching file README.txt
    patching file set_front_page.install
    patching file set_front_page.services.yml
    patching file src/Controller/SetFrontPageController.php
    patching file src/Form/SetFrontPageConfigForm.php
    patching file src/Form/SetFrontPageEntitySettings.php
    patching file src/SetFrontPageManager.php
    patching file tests/src/Functional/SetFrontPageTests.php
    
    Admin@DESKTOP-252TO6V MINGW64 ~/Desktop/projects/drupal/web/modules/contrib
    $ phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,info,txt,md,js,yml set_front_page/
    
    Admin@DESKTOP-252TO6V MINGW64 ~/Desktop/projects/drupal/web/modules/contrib
    $
    

    No issues or error remaining.

Production build 0.71.5 2024