diff --git a/src/Standards/Generic/Sniffs/NamingConventions/ConstructorNameSniff.php b/src/Standards/Generic/Sniffs/NamingConventions/ConstructorNameSniff.php
index 48e7659e3c..e87f066b3f 100644
--- a/src/Standards/Generic/Sniffs/NamingConventions/ConstructorNameSniff.php
+++ b/src/Standards/Generic/Sniffs/NamingConventions/ConstructorNameSniff.php
@@ -78,8 +78,13 @@ protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScop
$this->currentClass = $className;
}
- $methodName = strtolower($phpcsFile->getDeclarationName($stackPtr));
+ $methodName = $phpcsFile->getDeclarationName($stackPtr);
+ if ($methodName === null) {
+ // Live coding or parse error. Bow out.
+ return;
+ }
+ $methodName = strtolower($methodName);
if ($methodName === $className) {
if (in_array('__construct', $this->functionList, true) === false) {
$error = 'PHP4 style constructors are not allowed; use "__construct()" instead';
@@ -164,7 +169,13 @@ protected function loadFunctionNamesInScope(File $phpcsFile, $currScope)
continue;
}
- $this->functionList[] = trim(strtolower($phpcsFile->getDeclarationName($i)));
+ $methodName = $phpcsFile->getDeclarationName($i);
+ if ($methodName === null) {
+ // Live coding or parse error. Ignore.
+ continue;
+ }
+
+ $this->functionList[] = trim(strtolower($methodName));
if (isset($tokens[$i]['scope_closer']) !== false) {
// Skip past nested functions and such.
diff --git a/src/Standards/Generic/Tests/NamingConventions/ConstructorNameUnitTest.inc b/src/Standards/Generic/Tests/NamingConventions/ConstructorNameUnitTest.1.inc
similarity index 100%
rename from src/Standards/Generic/Tests/NamingConventions/ConstructorNameUnitTest.inc
rename to src/Standards/Generic/Tests/NamingConventions/ConstructorNameUnitTest.1.inc
diff --git a/src/Standards/Generic/Tests/NamingConventions/ConstructorNameUnitTest.2.inc b/src/Standards/Generic/Tests/NamingConventions/ConstructorNameUnitTest.2.inc
new file mode 100644
index 0000000000..bfd1cfe25e
--- /dev/null
+++ b/src/Standards/Generic/Tests/NamingConventions/ConstructorNameUnitTest.2.inc
@@ -0,0 +1,9 @@
+
*/
- public function getErrorList()
+ public function getErrorList($testFile='')
{
- return [
- 6 => 1,
- 11 => 1,
- 47 => 1,
- 62 => 1,
- 91 => 1,
- 103 => 1,
- 104 => 1,
- 112 => 1,
- 120 => 1,
- 121 => 1,
- 126 => 1,
- 127 => 1,
- ];
+ switch ($testFile) {
+ case 'ConstructorNameUnitTest.1.inc':
+ return [
+ 6 => 1,
+ 11 => 1,
+ 47 => 1,
+ 62 => 1,
+ 91 => 1,
+ 103 => 1,
+ 104 => 1,
+ 112 => 1,
+ 120 => 1,
+ 121 => 1,
+ 126 => 1,
+ 127 => 1,
+ ];
+ default:
+ return [];
+ }//end switch
}//end getErrorList()