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.
~/.composer/vendor/bin/phpcs --standard=/home/peter/.composer/vendor/drupal/coder/coder_sniffer/Drupal --sniffs=Drupal.Classes.ClassCreateInstance core/lib/Drupal/Core/Controller/ControllerResolver.php
FILE: ...bdata/www/core/lib/Drupal/Core/Controller/ControllerResolver.php
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
76 | ERROR | Calling class constructors must always include
| | parentheses
----------------------------------------------------------------------
Offending line: return new $controller;
Comment | File | Size | Author |
---|---|---|---|
#5 | diff-2573195-3-5.txt | 5.31 KB | anoopjohn |
#5 | coder-auto-fix-class-create-instance-parenthesis-2573195.patch | 4.79 KB | anoopjohn |
Comments
Comment #2
attiks CreditAttribution: attiks at Attiks commentedPatch to mark them as fixable, and fix them
Comment #3
pfrenssenAdded a test.
Comment #4
klausiShould say "Detect and fix constructor calls with namespaces, example "new \DOMDocument;".
indentation should be 4 spaces, per PHPCS coding standards that we use in sniffs.
I don't think this is the correct fix. We should just search for T_STRING and T_NS_SEPARATOR sequences and insert he parenthesis after that.
The test case should include a namespaces example like \DOMDocument and a longer example such as \Drupal\Core\Whatever.
Comment #5
anoopjohn CreditAttribution: anoopjohn at Zyxware Technologies commentedI believe that part of the fix (test cases) had already gotten into coder. The auto fixing was not coded for the specific case listed in the issue line 70 in core/lib/Drupal/Core/Controller/ControllerResolver.php
I have added the logic to auto fix cases where classname is in a variable and also address cases where the name is in an array. Have updated the existing test cases for the automatic fixing.
Please find the patch attached. Interdiff was failing so attaching diff as well.
Comment #7
klausiCommitted, thanks!