You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Whenever a class has a method that uses an anonymous class that itself has a method that matches the name of the containing class, PHP_CodeSniffer reports that the class uses an old style constructor.
Running with php Nested.php shows: In method nested!
Running PHP_CodeSniffer, it reports that an old style constructor is used:
FILE: Nested.php
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
8 | ERROR | PHP4 style constructors are not allowed; use
| | "__construct()" instead
| | (Generic.NamingConventions.ConstructorName.OldStyle)
----------------------------------------------------------------------
Had an old style constructor been used, the line In method nested! should have appeared in the output twice, once for the constructor on line 15, and once for the method call on line 16.
Based on the error message, ConstructorNameSniff::processTokenWithinScope is to blame. From what I can see, it uses the name of the containing class because the anonymous class does not have a name.
gsherwood
changed the title
Generic.NamingConventions.ConstructorName.OldStyle matches methods in anonymous classes named the same as the containing class
Generic.NamingConventions.ConstructorName matches methods in anon classes with same name as containing class
Oct 11, 2018
Whenever a class has a method that uses an anonymous class that itself has a method that matches the name of the containing class, PHP_CodeSniffer reports that the class uses an old style constructor.
Running with
php Nested.php
shows:In method nested!
Running PHP_CodeSniffer, it reports that an old style constructor is used:
Had an old style constructor been used, the line
In method nested!
should have appeared in the output twice, once for the constructor on line 15, and once for the method call on line 16.Based on the error message, ConstructorNameSniff::processTokenWithinScope is to blame. From what I can see, it uses the name of the containing class because the anonymous class does not have a name.
Used .phpcs.xml file:
Used PHPCS 3.3.2.
The text was updated successfully, but these errors were encountered: