-
-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generic/ConstructorName: more defensive coding
This sniff could throw the following fatal errors when it encountered parse errors/during live coding: ``` Fatal error: Uncaught PHP_CodeSniffer\Exceptions\RuntimeException: strtolower(): Passing null to parameter #1 ($string) of type string is deprecated in path/to/PHPCS/src/Standards/Generic/Sniffs/NamingConventions/ConstructorNameSniff.php on line 83 in path/to/PHPCS/src/Runner.php on line 624 Fatal error: Uncaught PHP_CodeSniffer\Exceptions\RuntimeException: strtolower(): Passing null to parameter #1 ($string) of type string is deprecated in path/to/PHPCS/src/Standards/Generic/Sniffs/NamingConventions/ConstructorNameSniff.php on line 167 in path/to/PHPCS/src/Runner.php on line 624 ``` Fixed now by adding more defensive coding. Includes tests safeguarding the fix.
- Loading branch information
Showing
3 changed files
with
29 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/Standards/Generic/Tests/NamingConventions/ConstructorNameUnitTest.2.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
// Intentional parse error (missing method name). | ||
// This should be the only test in this file. | ||
// Testing that the sniff is *not* triggered. | ||
|
||
class My_Class { | ||
public function {} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/Standards/Generic/Tests/NamingConventions/ConstructorNameUnitTest.3.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
// Intentional parse error (missing function name). | ||
// This should be the only test in this file. | ||
// Testing that the sniff is *not* triggered. | ||
|
||
function |