diff --git a/src/Standards/Generic/Sniffs/PHP/LowerCaseTypeSniff.php b/src/Standards/Generic/Sniffs/PHP/LowerCaseTypeSniff.php index 29cfbc7e2b..f08c6938c7 100644 --- a/src/Standards/Generic/Sniffs/PHP/LowerCaseTypeSniff.php +++ b/src/Standards/Generic/Sniffs/PHP/LowerCaseTypeSniff.php @@ -97,6 +97,11 @@ public function process(File $phpcsFile, $stackPtr) return; } + if (empty($props) === true) { + // Parse error - property in interface or enum. Ignore. + return; + } + // Strip off potential nullable indication. $type = ltrim($props['type'], '?'); diff --git a/src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.inc b/src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.inc index 011adcd530..d6eb83ba64 100644 --- a/src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.inc +++ b/src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.inc @@ -92,3 +92,8 @@ function intersectionReturnTypes ($var): \Package\ClassName&\Package\Other_Class $arrow = fn (int $a, string $b, bool $c, array $d, Foo\Bar $e) : int => $a * $b; $arrow = fn (Int $a, String $b, BOOL $c, Array $d, Foo\Bar $e) : Float => $a * $b; + +// Intentional error, should be ignored by the sniff. +interface PropertiesNotAllowed { + public $notAllowed; +} \ No newline at end of file diff --git a/src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.inc.fixed b/src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.inc.fixed index d866101b6f..87405785e6 100644 --- a/src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.inc.fixed +++ b/src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.inc.fixed @@ -92,3 +92,8 @@ function intersectionReturnTypes ($var): \Package\ClassName&\Package\Other_Class $arrow = fn (int $a, string $b, bool $c, array $d, Foo\Bar $e) : int => $a * $b; $arrow = fn (int $a, string $b, bool $c, array $d, Foo\Bar $e) : float => $a * $b; + +// Intentional error, should be ignored by the sniff. +interface PropertiesNotAllowed { + public $notAllowed; +} \ No newline at end of file diff --git a/src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.php b/src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.php index 197b734a1f..1733c44a37 100644 --- a/src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.php +++ b/src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.php @@ -82,7 +82,8 @@ public function getErrorList() */ public function getWarningList() { - return []; + // Warning from getMemberProperties() about parse error. + return [98 => 1]; }//end getWarningList()