Fix the warnings/errors reported by PHP_CodeSniffer

Created on 26 June 2023, over 1 year ago
Updated 28 July 2024, 5 months ago

Problem/Motivation

Several warnings and errors reported by PHP_CodeSniffer were found in the multi_region module. These issues need to be addressed to ensure compliance with coding standards and maintain code quality.

FILE: src/ConfigurableRegionHtmlRouteProvider.php
-----------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
-----------------------------------------------------------------------------
19 | WARNING | Possible useless method overriding detected
-----------------------------------------------------------------------------

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

FILE: src/ConfigurableRegionListBuilder.php
-----------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
-----------------------------------------------------------------------------
7 | WARNING | [x] Unused use statement
-----------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-----------------------------------------------------------------------------

FILE: src/RegionManager.php
-----------------------------------------------------------------------------
FOUND 1 ERROR AND 2 WARNINGS AFFECTING 3 LINES
-----------------------------------------------------------------------------
5 | WARNING | [x] Unused use statement
8 | WARNING | [x] Unused use statement
129 | ERROR | [x] Object operator not indented correctly; expected 8 spaces but found 10
-----------------------------------------------------------------------------
PHPCBF CAN FIX THE 3 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-----------------------------------------------------------------------------

Time: 174ms; Memory: 10MB

Steps to reproduce

Run PHP_CodeSniffer with the Drupal coding standard and specified file extensions using the command:
phpcs --standard=Drupal --extensions=php,module,inc,install,info,txt,md modules/multi_region

Proposed resolution

Fix the issues reported by PHP_CodeSniffer in the multi_region module by addressing the specific warnings and errors outlined above. Ensure that the code follows Drupal coding standards and maintains consistency throughout.

šŸ“Œ Task
Status

RTBC

Version

1.0

Component

Code

Created by

šŸ‡®šŸ‡³India sonam_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 @sonam_sharma
  • Issue was unassigned.
  • šŸ‡®šŸ‡¹Italy apaderno Brescia, šŸ‡®šŸ‡¹

    Since the issue is showing what PHP_CodeSniffer shows, let us rescope it to fix all the warnings/errors reported by PHP_CodeSniffer.

    The issue summary should always describe what the issue is trying to fix and, in the case of coding standards issues, show which command and arguments have been used and which report that command shown. In this way, project maintainers can verify the patch/MR fixes all the warnings/errors.

  • šŸ‡®šŸ‡³India immaculatexavier

    Updated issue summary.

  • First commit to issue fork.
  • Status changed to Needs review 7 months ago
  • šŸ‡®šŸ‡³India kalash-j jaipur

    hello , i have solved all the issues that PHPCS has shown.
    MR!2 have 0 PHPCS error please check.

  • Status changed to RTBC 7 months ago
  • šŸ‡µšŸ‡­Philippines clarkssquared

    Hi

    I applied the updated MR !2 and I followed the steps to reproduce and confirmed that the PHPCS issues:

    āžœ  contrib git:(master) āœ— phpcs --standard=Drupal --extensions=php,module,inc,install,info,txt,md multi_region 
    
    FILE: ...local/web/modules/contrib/multi_region/src/Form/ConfigurableRegionForm.php
    --------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    --------------------------------------------------------------------------------
     10 | WARNING | The class short comment should describe what the class does and
        |         | not simply repeat the class name
    --------------------------------------------------------------------------------
    
    
    FILE: ...ules/contrib/multi_region/src/Plugin/Block/RegionLanguageSwitcherBlock.php
    --------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    --------------------------------------------------------------------------------
     6 | ERROR | [x] Use statements should be sorted alphabetically. The first
       |       |     wrong one is Drupal\Core\Access\AccessResult.
    --------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    --------------------------------------------------------------------------------
    
    
    FILE: ...b/modules/contrib/multi_region/src/ConfigurableRegionHtmlRouteProvider.php
    --------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    --------------------------------------------------------------------------------
     19 | WARNING | Possible useless method overriding detected
    --------------------------------------------------------------------------------
    
    
    FILE: ...odules/contrib/multi_region/src/ConfigurableRegionAccessControlHandler.php
    --------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    --------------------------------------------------------------------------------
     8 | ERROR | [x] Use statements should be sorted alphabetically. The first
       |       |     wrong one is Drupal\Core\Access\AccessResult.
    --------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    --------------------------------------------------------------------------------
    
    
    FILE: ...cal/web/modules/contrib/multi_region/src/ConfigurableRegionListBuilder.php
    --------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    --------------------------------------------------------------------------------
     7 | WARNING | [x] Unused use statement
    --------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    --------------------------------------------------------------------------------
    
    
    FILE: ...rojects/d9/d9-local/web/modules/contrib/multi_region/src/RegionManager.php
    --------------------------------------------------------------------------------
    FOUND 1 ERROR AND 2 WARNINGS AFFECTING 3 LINES
    --------------------------------------------------------------------------------
       5 | WARNING | [x] Unused use statement
       8 | WARNING | [x] Unused use statement
     129 | ERROR   | [x] Object operator not indented correctly; expected 8 spaces
         |         |     but found 10
    --------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 3 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    --------------------------------------------------------------------------------
    
    Time: 157ms; Memory: 8MB
    
    āžœ  contrib git:(master) āœ— cd multi_region 
    āžœ  multi_region git:(master) āœ— curl https://git.drupalcode.org/project/multi_region/-/merge_requests/2.diff | patch -p1
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100 10218    0 10218    0     0  19688      0 --:--:-- --:--:-- --:--:-- 19918
    patching file 'src/ConfigurableRegionAccessControlHandler.php'
    patching file 'src/ConfigurableRegionHtmlRouteProvider.php'
    patching file 'src/ConfigurableRegionListBuilder.php'
    patching file 'src/Form/ConfigurableRegionForm.php'
    patching file 'src/Plugin/Block/RegionLanguageSwitcherBlock.php'
    patching file 'src/RegionManager.php'
    āžœ  multi_region git:(master) āœ— ..
    āžœ  contrib git:(master) āœ— phpcs --standard=Drupal --extensions=php,module,inc,install,info,txt,md multi_region
    āžœ  contrib git:(master) āœ— 
  • šŸ‡®šŸ‡¹Italy apaderno Brescia, šŸ‡®šŸ‡¹
  • Status changed to Needs work 7 months ago
  • šŸ‡®šŸ‡¹Italy apaderno Brescia, šŸ‡®šŸ‡¹
  • Pipeline finished with Success
    7 months ago
    Total: 139s
    #182809
  • Pipeline finished with Success
    7 months ago
    Total: 139s
    #184399
  • Status changed to Needs review 7 months ago
  • šŸ‡®šŸ‡³India kalash-j jaipur

    @apaderno i have done the changes on the feedback you have provided

  • Status changed to RTBC 5 months ago
  • šŸ‡®šŸ‡³India Tirupati_Singh

    Hi, I've applied the MR!2 as patch and it applied successfully with no errors. After applying patch all the mentioned phpcs errors has been resolved successfully. Hence, moving the issue status to Reviewed and tested.

Production build 0.71.5 2024