Drupal calls should be avoided in classes, use dependency injection instead

Created on 4 July 2023, over 1 year ago
Updated 30 July 2024, 5 months ago

Problem/Motivation

FILE: /var/www/html/vb/d_cont/required_content/src/Form/SettingsForm.php
----------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 7 WARNINGS AFFECTING 7 LINES
----------------------------------------------------------------------------------------------
38 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
79 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
80 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
83 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
165 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
234 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
----------------------------------------------------------------------------------------------

FILE: /var/www/html/vb/d_cont/required_content/src/EventSubscriber/RequiredContentSubscriber.php
------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 4 WARNINGS AFFECTING 4 LINES
------------------------------------------------------------------------------------------------
65 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
69 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
75 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
79 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
------------------------------------------------------------------------------------------------

Time: 117ms; Memory: 10MB

Steps to reproduce

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

Remaining tasks

Patch review

๐Ÿ“Œ Task
Status

Needs work

Version

1.0

Component

Code

Created by

๐Ÿ‡ฎ๐Ÿ‡ณIndia urvashi_vora Madhya Pradesh, India

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 @urvashi_vora
  • Status changed to Needs work 11 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia ashutosh ahirwal India

    Provided patch get applied cleanly.
    But still there are so many issue/error found by phpcs
    Used command with arguments

    ./vendor/bin/phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,info,txt,md,css,js,yml web/modules/custom/required_content

    FILE: /Users/ashutoshahirwal/Sites/lando/contribution/web/modules/custom/required_content/src/Form/SettingsForm.php
    ---------------------------------------------------------------------------------------------------------------------------------------
    FOUND 3 ERRORS AND 1 WARNING AFFECTING 4 LINES
    ---------------------------------------------------------------------------------------------------------------------------------------
    10 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\Core\Config\ConfigFactoryInterface.
    178 | ERROR | [x] Array indentation error, expected 10 spaces but found 8
    179 | ERROR | [x] Array indentation error, expected 10 spaces but found 8
    280 | WARNING | [ ] Unused variable $bundle.
    ---------------------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 3 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ---------------------------------------------------------------------------------------------------------------------------------------

    FILE: /Users/ashutoshahirwal/Sites/lando/contribution/web/modules/custom/required_content/src/EventSubscriber/RequiredContentSubscriber.php
    -------------------------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    -------------------------------------------------------------------------------------------------------------------------------------------
    6 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\Core\Config\Config.
    -------------------------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    -------------------------------------------------------------------------------------------------------------------------------------------

    FILE: /Users/ashutoshahirwal/Sites/lando/contribution/web/modules/custom/required_content/src/EventSubscriber/MissingContentSubscriber.php
    ------------------------------------------------------------------------------------------------------------------------------------------
    FOUND 14 ERRORS AND 2 WARNINGS AFFECTING 14 LINES
    ------------------------------------------------------------------------------------------------------------------------------------------
    11 | ERROR | [x] Missing class doc comment
    13 | ERROR | [ ] Missing member variable doc comment
    14 | ERROR | [ ] Missing member variable doc comment
    17 | ERROR | [x] Missing function doc comment
    17 | ERROR | [x] Expected 1 blank line before function; 2 found
    20 | ERROR | [x] Expected 1 blank line after function; 2 found
    58 | WARNING | [ ] Line exceeds 80 characters; contains 94 characters
    59 | WARNING | [ ] Line exceeds 80 characters; contains 81 characters
    59 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found 6
    60 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found 8
    61 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found 8
    62 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found 8
    63 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found 6
    64 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found 6
    65 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found 6
    67 | ERROR | [x] Line indented incorrectly; expected 5 spaces, found 4
    ------------------------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 12 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ------------------------------------------------------------------------------------------------------------------------------------------

    Time: 301ms; Memory: 12MB

  • First commit to issue fork.
  • Status changed to Needs review 11 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia viren18febS

    Hi , i have fixed all the pending reported issues.
    Please review

  • Status changed to Needs work 5 months ago
  • ๐Ÿ‡ต๐Ÿ‡ญPhilippines roberttabigue

    Hi @viren18febS,

    After applying your Patch #14 to the Required Content module against 1.0.x-dev on Drupal 10, I still see a 1 PHPCS error.

    Please see the attached file for reference.

    I ran this command on the module:
    phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,info,txt,md,yml,css,js required_content/

    I'm moving this to โ€˜Needs workโ€™ for now.

    Thank you!

Production build 0.71.5 2024