Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment | File | Size | Author |
---|---|---|---|
#29 | after-patch.png | 49.19 KB | gquisini |
#27 | 2933031-27.patch | 101.56 KB | bruno.bicudo |
#15 | 2933031-15.patch | 45.52 KB | urvashi_vora |
#13 | interdiff_12-13.txt | 68.96 KB | deepanker_bhalla |
#13 | 2933031-Drupal-best-practices-13.patch | 79.11 KB | deepanker_bhalla |
Issue fork token-2933031
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
teeyo CreditAttribution: teeyo as a volunteer commentedHere's a fix for Drupal best practices, I didn't touch coding standards so not to make the diff file bigger and hard to review.
Comment #3
teeyo CreditAttribution: teeyo as a volunteer commentedComment #4
BerdirI doubt that formatting is correct, and unsure why it is commented out, but I'd rather just remove it if not required anymore.
this is not the same check, why change this?
same here, if really not needed then lets remove this. This would also be a valid inline comment, it's just missing a space.
same here, this doesn't seem formatted correctly and I'd rather fix the code instad of just fixing the way it is commented out, that doesn't bring us forward.
weird variable names, we could rename it to $entity_types and $entity_type while touching it anyway.
Comment #5
harsha012 CreditAttribution: harsha012 as a volunteer and at Red Crackle commentedfixed as per #4
Comment #6
nkoporecTested the patch and it fixed coding standard and issues that @Berdir has found.
Comment #7
ankitjain28may CreditAttribution: ankitjain28may as a volunteer and at Google Summer of Code commentedPatch submitted in #5 still has some issue.
Comment #8
ankitjain28may CreditAttribution: ankitjain28may as a volunteer and at Google Summer of Code commentedThis is the patch and interdiff.
Comment #9
ankitjain28may CreditAttribution: ankitjain28may as a volunteer and at Google Summer of Code commentedIt would be great if someone let me know regarding this warning so i will fix it.
Comment #11
deepanker_bhalla CreditAttribution: deepanker_bhalla as a volunteer and at Srijan | A Material+ Company commentedI was unable to apply the patch due to changes in the version. Thus updating the rerolling patch.
Comment #12
deepanker_bhalla CreditAttribution: deepanker_bhalla as a volunteer and at Srijan | A Material+ Company commentedComment #13
deepanker_bhalla CreditAttribution: deepanker_bhalla as a volunteer and at Srijan | A Material+ Company commentedUpdating the patch with the solved changes with the interdiff.
Comment #15
urvashi_vora CreditAttribution: urvashi_vora at Valuebound for Valuebound commentedPlease review the patch. Thanks
Comment #16
bruno.bicudoPatch failed to apply. Needs reroll.
Comment #17
bruno.bicudo#15 didn't apply clean, i rerolled it and worked on other files.
Fixed all empty doc blocks and other CS details. Diffed against 8.x-1.x.
Needs review.
Comment #18
bruno.bicudoSilly me, forgot to unassign. Sorry.
Comment #19
bruno.bicudoCorrects "TokenTestTrai
t
" undertests/src/Functional/TokenTestBase.php
Needs review.
Comment #21
bruno.bicudoCorrects route access for
TreeTest
data retrieval and wrong variable name onHelpPageTest
Now everything might pass (tests were passing on local, but failing here. So i worked against DO test results).
Needs review :)
Comment #22
bruno.bicudoComment #23
aldairsoares CreditAttribution: aldairsoares at CI&T commentedI run all tests and phpcs command to find any erros. No indentation problems were found and tests are running well.
No crashes happened during my review.
I'm moving it to RTBC.
Comment #24
Christopher Riley CreditAttribution: Christopher Riley commentedShould this patch be needed for release 8.x-1.11 because I am getting a failure when it tries to patch via composer and when I do it manually
-> patch -p1 <2933031-20.patch
patching file README.md
patching file css/jquery.treetable.css
patching file css/token.css
patching file src/Controller/TokenDevelController.php
patching file src/Controller/TokenTreeController.php
patching file src/Element/TokenTreeTable.php
Hunk #3 succeeded at 113 (offset -4 lines).
Hunk #4 succeeded at 162 (offset -4 lines).
Hunk #5 succeeded at 182 (offset -4 lines).
patching file src/MenuLinkFieldItemList.php
patching file src/Plugin/Derivative/DevelLocalTask.php
patching file src/Routing/RouteSubscriber.php
patching file src/Token.php
patching file src/TokenEntityMapper.php
patching file src/TokenEntityMapperInterface.php
patching file src/TokenFieldRender.php
patching file src/TokenInterface.php
patching file src/TokenServiceProvider.php
patching file src/TreeBuilder.php
patching file src/TreeBuilderInterface.php
patching file tests/modules/token_module_test/token_module_test.module
patching file tests/modules/token_module_test/token_module_test.routing.yml
patching file tests/modules/token_module_test/token_module_test.tokens.inc
patching file tests/src/Functional/TokenBlockTest.php
patching file tests/src/Functional/TokenCurrentPageTest.php
patching file tests/src/Functional/TokenFieldUiTest.php
patching file tests/src/Functional/TokenMenuTest.php
patching file tests/src/Functional/TokenTestTrait.php
patching file tests/src/Functional/TokenURLTest.php
patching file tests/src/Functional/TokenUserTest.php
patching file tests/src/Functional/Tree/HelpPageTest.php
patching file tests/src/Functional/Tree/TokenTreeTestTrait.php
patching file tests/src/Functional/Tree/TreeTest.php
Hunk #3 FAILED at 98.
1 out of 5 hunks FAILED -- saving rejects to file tests/src/Functional/Tree/TreeTest.php.rej
patching file tests/src/Functional/UrlTest.php
patching file tests/src/Kernel/ArrayTest.php
patching file tests/src/Kernel/BookTest.php
patching file tests/src/Kernel/CommentTest.php
patching file tests/src/Kernel/DateTest.php
patching file tests/src/Kernel/EntityTest.php
patching file tests/src/Kernel/FieldTest.php
patching file tests/src/Kernel/FileTest.php
patching file tests/src/Kernel/LanguageTest.php
patching file tests/src/Kernel/NodeTest.php
patching file tests/src/Kernel/RandomTest.php
patching file tests/src/Kernel/TaxonomyTest.php
patching file tests/src/Kernel/UnitTest.php
patching file tests/src/Kernel/UrlTest.php
patching file token.install
patching file token.module
patching file token.pages.inc
patching file token.tokens.inc
--- tests/src/Functional/Tree/TreeTest.php
+++ tests/src/Functional/Tree/TreeTest.php
@@ -98,7 +103,10 @@
// Request with show_restricted set to TRUE to show restricted tokens and
// check for them.
- $this->drupalGet($this->getTokenTreeUrl(['token_types' => ['user'], 'show_restricted' => TRUE]));
+ $this->drupalGet($this->getTokenTreeUrl([
+ 'token_types' => ['user'],
+ 'show_restricted' => TRUE,
+ ]));
$this->assertEquals('MISS', $this->drupalGetHeader('x-drupal-dynamic-cache'), 'Cache was not hit');
$this->assertTokenInTree('[user:one-time-login-url]', 'user');
$this->assertTokenInTree('[user:original:cancel-url]', 'user--original');
Comment #25
bruno.bicudoRerolled #21.
Comment #26
bruno.bicudoComment #27
bruno.bicudoSorry, i made a mistake on the last patch.
Kindly review it.
Comment #28
gquisini CreditAttribution: gquisini at CI&T commentedI'll be reviewing.
Comment #29
gquisini CreditAttribution: gquisini at CI&T commentedI applied #27 patch and no more PHPCS errors.
Comment #30
Manoj Raj.R CreditAttribution: Manoj Raj.R as a volunteer and at ITT Digital commented#27 looks good for me. after seeing #29 no PHPCS errors.
Should we consider moving to RTBC to Fixed!
Comment #31
Christopher Riley CreditAttribution: Christopher Riley commentedOn my 9.5 Beta 2 system when I try to apply patch 27 now it applies correctly however after I do the computer update -W and drush updb I then run drush cr to flush the cache and I get the following:
Fatal error: Uncaught Error: Call to undefined method Drupal\Core\StringTranslation\TranslationManager::t() in /home/sitename/public_html/modules/contrib/token/src/Plugin/Derivative/DevelLocalTask.php:64
Stack trace:
#0 /home/sitename/public_html/core/lib/Drupal/Component/Plugin/Discovery/DerivativeDiscoveryDecorator.php(101): Drupal\token\Plugin\Derivative\DevelLocalTask->getDerivativeDefinitions(Array)
#1 /home/sitename/public_html/core/lib/Drupal/Component/Plugin/Discovery/DerivativeDiscoveryDecorator.php(87): Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator->getDerivatives(Array)
#2 /home/sitename/public_html/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php(285): Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator->getDefinitions()
#3 /home/sitename/public_html/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php(175): Drupal\Core\Plugin\DefaultPluginManager->findDefinitions()
#4 /home/sitename/public_html/core/lib/Drupal/Core/Menu/LocalTaskManager.php(181): Drupal\Core\Plugin\DefaultPluginManager->getDefinitions()
#5 /home/sitename/public_html/modules/contrib/webform/webform.module(521): Drupal\Core\Menu\LocalTaskManager->getDefinitions()
#6 /home/sitename/public_html/core/lib/Drupal/Core/Extension/ModuleHandler.php(562): webform_menu_links_discovered_alter(Array, NULL, NULL)
#7 /home/sitename/public_html/core/lib/Drupal/Core/Menu/MenuLinkManager.php(166): Drupal\Core\Extension\ModuleHandler->alter('menu_links_disc...', Array)
#8 /home/sitename/public_html/core/lib/Drupal/Core/Menu/MenuLinkManager.php(189): Drupal\Core\Menu\MenuLinkManager->getDefinitions()
#9 /home/sitename/public_html/core/lib/Drupal/Core/EventSubscriber/MenuRouterRebuildSubscriber.php(82): Drupal\Core\Menu\MenuLinkManager->rebuild()
#10 /home/sitename/public_html/core/lib/Drupal/Core/EventSubscriber/MenuRouterRebuildSubscriber.php(70): Drupal\Core\EventSubscriber\MenuRouterRebuildSubscriber->menuLinksRebuild()
#11 [internal function]: Drupal\Core\EventSubscriber\MenuRouterRebuildSubscriber->onRouterRebuild(Object(Drupal\Component\EventDispatcher\Event), 'routing.route_f...', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
#12 /home/sitename/public_html/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(142): call_user_func(Array, Object(Drupal\Component\EventDispatcher\Event), 'routing.route_f...', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
#13 /home/sitename/public_html/core/lib/Drupal/Core/Routing/RouteBuilder.php(197): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object(Drupal\Component\EventDispatcher\Event), 'routing.route_f...')
#14 /home/sitename/public_html/core/lib/Drupal/Core/ProxyClass/Routing/RouteBuilder.php(83): Drupal\Core\Routing\RouteBuilder->rebuild()
#15 /home/sitename/public_html/core/includes/common.inc(587): Drupal\Core\ProxyClass\Routing\RouteBuilder->rebuild()
#16 /home/sitename/public_html/core/includes/utility.inc(41): drupal_flush_all_caches(Object(Drupal\Core\DrupalKernel))
#17 /home/sitename/vendor/drush/drush/src/Commands/core/CacheCommands.php(227): drupal_rebuild(Object(Composer\Autoload\ClassLoader), Object(Symfony\Component\HttpFoundation\Request))
#18 [internal function]: Drush\Commands\core\CacheCommands->rebuild(Array)
#19 /home/sitename/vendor/consolidation/annotated-command/src/CommandProcessor.php(257): call_user_func_array(Array, Array)
#20 /home/sitename/vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback(Array, Object(Consolidation\AnnotatedCommand\CommandData))
#21 /home/sitename/vendor/consolidation/annotated-command/src/CommandProcessor.php(176): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter(Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#22 /home/sitename/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(350): Consolidation\AnnotatedCommand\CommandProcessor->process(Object(Symfony\Component\Console\Output\ConsoleOutput), Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#23 /home/sitename/vendor/symfony/console/Command/Command.php(255): Consolidation\AnnotatedCommand\AnnotatedCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#24 /home/sitename/vendor/symfony/console/Application.php(1027): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#25 /home/sitename/vendor/symfony/console/Application.php(273): Symfony\Component\Console\Application->doRunCommand(Object(Consolidation\AnnotatedCommand\AnnotatedCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#26 /home/sitename/vendor/symfony/console/Application.php(149): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#27 /home/sitename/vendor/drush/drush/src/Runtime/Runtime.php(124): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#28 /home/sitename/vendor/drush/drush/src/Runtime/Runtime.php(51): Drush\Runtime\Runtime->doRun(Array, Object(Symfony\Component\Console\Output\ConsoleOutput))
#29 /home/sitename/vendor/drush/drush/drush.php(72): Drush\Runtime\Runtime->run(Array)
#30 /home/sitename/vendor/drush/drush/includes/preflight.inc(18): require('/home/pls/prepp...')
#31 phar:///usr/local/bin/drush/bin/drush.php(159): drush_main()
#32 /usr/local/bin/drush(10): require('phar:///usr/loc...')
#33 {main}
thrown in /home/sitename/public_html/modules/contrib/token/src/Plugin/Derivative/DevelLocalTask.php on line 64
[warning] Drush command terminated abnormally.
This does not happen if I do not have 27 applied.
Comment #32
BerdirCoding 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.
Comment #33
zkhan.aamir CreditAttribution: zkhan.aamir at Specbee for Drupal India Association commented