Drupal best practices and coding standards

Created on 26 December 2017, almost 7 years ago
Updated 28 July 2024, 4 months ago

Hey, I came across some best practices issues and coding standards, example of Drupal practices :

 phpcs --standard=DrupalPractice --extensions=php,module,inc,install,test,profile,theme,info,txt,md .

FILE: ...d8/modules/contrib/token/src/Controller/TokenCacheController.php
----------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
----------------------------------------------------------------------
 17 | WARNING | t() calls should be avoided in classes, use
    |         | dependency injection and $this->t() instead
----------------------------------------------------------------------


FILE: ...d8/modules/contrib/token/src/Controller/TokenDevelController.php
----------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
----------------------------------------------------------------------
 95 | WARNING | There must be no blank line following an inline
    |         | comment
----------------------------------------------------------------------


FILE: ...ant/Code/d8/modules/contrib/token/src/Element/TokenTreeTable.php
----------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
----------------------------------------------------------------------
 73 | WARNING | Variable $tree is undefined.
----------------------------------------------------------------------


FILE: ...agrant/Code/d8/modules/contrib/token/src/Tests/TokenMenuTest.php
----------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
----------------------------------------------------------------------
 102 | WARNING | There must be no blank line following an inline
     |         | comment
----------------------------------------------------------------------


FILE: /home/vagrant/Code/d8/modules/contrib/token/src/TreeBuilder.php
----------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
----------------------------------------------------------------------
 100 | WARNING | t() calls should be avoided in classes, use
     |         | dependency injection and $this->t() instead
----------------------------------------------------------------------


FILE: ...s/token_module_test/src/Controller/TokenTreeBrowseController.php
----------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
----------------------------------------------------------------------
 16 | WARNING | \Drupal calls should be avoided in classes, use
    |         | dependency injection instead
----------------------------------------------------------------------


FILE: ...en/tests/modules/token_module_test/token_module_test.routing.yml
----------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
----------------------------------------------------------------------
 7 | WARNING | Open page callback found, please add a comment before
   |         | the line why there is no access restriction
----------------------------------------------------------------------


FILE: ...ken/tests/modules/token_user_picture/token_user_picture.info.yml
----------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
----------------------------------------------------------------------
 8 | WARNING | All dependencies must be prefixed with the project
   |         | name, for example "drupal:"
----------------------------------------------------------------------


FILE: /home/vagrant/Code/d8/modules/contrib/token/token.install
----------------------------------------------------------------------
FOUND 0 ERRORS AND 4 WARNINGS AFFECTING 4 LINES
----------------------------------------------------------------------
 117 | WARNING | There must be no blank line following an inline
     |         | comment
 122 | WARNING | There must be no blank line following an inline
     |         | comment
 206 | WARNING | Unused variable $index.
 246 | WARNING | There must be no blank line following an inline
     |         | comment
----------------------------------------------------------------------


FILE: /home/vagrant/Code/d8/modules/contrib/token/token.routing.yml
----------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
----------------------------------------------------------------------
 13 | WARNING | Open page callback found, please add a comment before
    |         | the line why there is no access restriction
----------------------------------------------------------------------


FILE: /home/vagrant/Code/d8/modules/contrib/token/token.tokens.inc
----------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
----------------------------------------------------------------------
 70 | WARNING | Unused variable $entity.
----------------------------------------------------------------------

Time: 714ms; Memory: 22Mb

I'll try to fix those along with the coding standards

๐Ÿ“Œ Task
Status

Closed: duplicate

Version

1.0

Component

Code

Created by

๐Ÿ‡ฒ๐Ÿ‡ฆMorocco teeyo

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.

  • ๐Ÿ‡จ๐Ÿ‡ญSwitzerland berdir Switzerland

    Coding standard improvements must be provided as merge requests now, so that we can verify it using GitlabCI.

    Additionally, this is way too big as a single patch and overlaps with many other issues. This is impossible to review and needs to be split up into issues for specific changes or groups of related changes.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia dev16.addweb

    silvi.addweb โ†’ made their first commit to this issueโ€™s fork.

  • Status changed to Needs review 6 months ago
  • Status changed to RTBC 6 months ago
  • ๐Ÿ‡ต๐Ÿ‡ญPhilippines roberttabigue

    Hi @silvi.addweb,

    I have reviewed the changes and confirmed that Patch #35 was applied cleanly to the Token module against 8.x-1.x-dev on Drupal 10.

    And all PHPCS errors have been fixed.

    I ran this command on the module:
    phpcs --standard=DrupalPractice --extensions=php,module,inc,install,test,profile,theme,info,txt,md token

    Please see the attached file for reference.

    I'm moving this now to โ€˜RTBCโ€™.

    Thank you!

  • ๐Ÿ‡ซ๐Ÿ‡ทFrance dydave
  • Status changed to Closed: duplicate 4 months ago
  • ๐Ÿ‡จ๐Ÿ‡ญSwitzerland berdir Switzerland

    #36 ignored #32 in multiple ways, I said this won't be merged as a single change and certainly not as a patch, closing as duplicate of the issue mentioned in #37.

Production build 0.71.5 2024