Replace uses of /Drupal within classes

Created on 3 May 2023, about 2 years ago
Updated 3 July 2023, almost 2 years ago

Problem/Motivation

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

FILE: /var/www/html/vbd9/web/modules/contrib/event_platform/event_platform_scheduler/src/Form/SchedulerSettingsForm.php
-----------------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
-----------------------------------------------------------------------------------------------------------------------
15 | WARNING | The class short comment should describe what the class does and not simply repeat the class name
95 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
-----------------------------------------------------------------------------------------------------------------------

FILE: /var/www/html/vbd9/web/modules/contrib/event_platform/event_platform_sponsors/event_platform_sponsors.install
-------------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
-------------------------------------------------------------------------------------------------------------------
5 | WARNING | Line exceeds 80 characters; contains 82 characters
-------------------------------------------------------------------------------------------------------------------

FILE: /var/www/html/vbd9/web/modules/contrib/event_platform/event_platform_sessions/event_platform_sessions.install
-------------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
-------------------------------------------------------------------------------------------------------------------
5 | WARNING | Line exceeds 80 characters; contains 82 characters
-------------------------------------------------------------------------------------------------------------------

FILE: /var/www/html/vbd9/web/modules/contrib/event_platform/event_platform_details/src/Plugin/Block/EventPlatformHeaderCtaBlock.php
-----------------------------------------------------------------------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 2 LINES
-----------------------------------------------------------------------------------------------------------------------------------
32 | ERROR | [x] The first index in a multi-value array must be on a new line
36 | ERROR | [x] Closing parenthesis of array declaration must be on a new line
-----------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-----------------------------------------------------------------------------------------------------------------------------------

FILE: /var/www/html/vbd9/web/modules/contrib/event_platform/event_platform_details/src/Plugin/Block/CopyrightBlock.php
----------------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
----------------------------------------------------------------------------------------------------------------------
35 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
----------------------------------------------------------------------------------------------------------------------

FILE: /var/www/html/vbd9/web/modules/contrib/event_platform/event_platform_details/src/Plugin/Block/EventPlatformHomeHeroBlock.php
----------------------------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
----------------------------------------------------------------------------------------------------------------------------------
48 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
----------------------------------------------------------------------------------------------------------------------------------

FILE: /var/www/html/vbd9/web/modules/contrib/event_platform/event_platform_details/event_platform_details.module
----------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AND 3 WARNINGS AFFECTING 4 LINES
----------------------------------------------------------------------------------------------------------------
8 | ERROR | [x] Missing function doc comment
14 | WARNING | [x] A comma should follow the last multiline array item. Found: ]
20 | WARNING | [x] A comma should follow the last multiline array item. Found: ]
32 | WARNING | [x] A comma should follow the last multiline array item. Found: ]
----------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 4 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------------------------------------------------

FILE: /var/www/html/vbd9/web/modules/contrib/event_platform/README.md
-----------------------------------------------------------------------
FOUND 1 ERROR AND 1 WARNING AFFECTING 2 LINES
-----------------------------------------------------------------------
10 | WARNING | [ ] Line exceeds 80 characters; contains 81 characters
72 | ERROR | [x] Expected 1 newline at end of file; 0 found
-----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-----------------------------------------------------------------------

Time: 1.05 secs; Memory: 12MB

Steps to reproduce

Proposed resolution

RUN::
phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml,twig web/modules/contrib/event_platform/

Remaining tasks

User interface changes

API changes

Data model changes

📌 Task
Status

Fixed

Version

1.0

Component

Code

Created by

🇮🇳India dineshkumarbollu

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

  • Issue created by @dineshkumarbollu
  • Issue was unassigned.
  • Status changed to Needs review about 2 years ago
  • 🇮🇳India dineshkumarbollu

    Hi

    I fix the all the issues except one Dependency Injection because i didn't get object for that class.

    Please review,

  • Status changed to RTBC about 2 years ago
  • 🇵🇭Philippines clarkssquared

    Hi dineshkumarbollu,

    I applied your patch #2 into Event Platform version 1.0.x-dev and confirmed that most of the PHPCS errors were fixed except the dependency injection you mentioned.

    Please look at the screenshots attached for your reference.

    Thank you

  • Status changed to Needs work almost 2 years ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
    +  /**
    +   * The configuration factory service.
    +   *
    +   * @var \Drupal\Core\Config\ConfigFactoryInterface
    +   */
    +  protected $configFactory;

    The config factory. is sufficient.

    +  /**
    +   * Constructs a new CustomBlock object.
    +   *
    +   * @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory
    +   *   The configuration factory service.
    +   */
    +  public function __construct(ConfigFactoryInterface $configFactory) {
    

    The class name is missing its namespace.

    -      return ['event_platform_header_cta' => [
    -        '#cache' => [
    -          'tags' => ['config_pages_list'],
    +      return [
    +        'event_platform_header_cta' => [
    +          '#cache' => [
    +            'tags' => ['config_pages_list'],
    +          ],

    The existing code is already correct. The first line does not even exceed 80 characters.

     /**
    - * Class SchedulerSettingsForm.
    + * Defines SchedulerSettingsForm class.

    That description is still repeating the class name.

     /**
      * @file
    - * Install, update and uninstall functions for the Event Platform Sessions module.
    + * Install, update and uninstall functions for Event Platform Sessions module.
      */
    /**
      * @file
    - * Install, update and uninstall functions for the Event Platform Sponsors module.
    + * Install, update and uninstall functions for Event Platform Sponsors module.
      */

    The existing line just needed a comma after update. Removing the definite article is not the correct change, since in English for the module is the correct phrase to use.

  • First commit to issue fork.
  • @bharath-kondeti opened merge request.
  • Status changed to Needs review almost 2 years ago
    • mandclu committed f9b76e51 on 1.0.x
      Issue #3357829 by apaderno, mandclu: Fix the issues reported by phpcs
      
  • Status changed to Fixed almost 2 years ago
  • 🇨🇦Canada mandclu

    I ended up fixing the code standards issues in a separate issue, so updating this thread to focus on replacing the usage of /Drupal static calls within classes. The code in the merge request seemed to break my Drupal 10 site, so I did some refactoring to get it functional. I also added a couple of other fixes for where /Drupal calls were being made within classes. The resulting changes are now merged in.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024