Skip to content

Commit ddba452

Browse files
authored
Merge pull request #62 from PHPCSStandards/feature/generic-lowercasetype-fix-php-notice
Generic/LowerCaseType: fix potential PHP notice
2 parents 206b3db + fed93f1 commit ddba452

File tree

5 files changed

+21
-3
lines changed

5 files changed

+21
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ The file documents changes to the PHP_CodeSniffer project.
145145
- Thanks to Dan Wallis (@fredden) for the patch
146146
- Fixed bug #3816 : PSR12/FileHeader: bug fix - false positives on PHP 8.2+ readonly classes
147147
- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
148+
- Fixed bug #3833 : Generic.PHP.LowerCaseType: fixed potential undefined array index notice
149+
- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
148150
- Fixed bug #3854 : Fatal error when using Gitblame report in combination with `--basepath` and running from project subdirectory
149151
- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
150152
- Fixed bug #3867 : Tokenizer/PHP: union type and intersection type operators were not correctly tokenized for static properties without explicit visibility

src/Standards/Generic/Sniffs/PHP/LowerCaseTypeSniff.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ public function process(File $phpcsFile, $stackPtr)
9898
return;
9999
}
100100

101+
if (empty($props) === true) {
102+
// Parse error - property in interface or enum. Ignore.
103+
return;
104+
}
105+
101106
// Strip off potential nullable indication.
102107
$type = ltrim($props['type'], '?');
103108

src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.inc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,9 @@ function intersectionReturnTypes ($var): \Package\ClassName&\Package\Other_Class
9393
$arrow = fn (int $a, string $b, bool $c, array $d, Foo\Bar $e) : int => $a * $b;
9494
$arrow = fn (Int $a, String $b, BOOL $c, Array $d, Foo\Bar $e) : Float => $a * $b;
9595

96-
$cl = function (False $a, TRUE $b, Null $c): ?True {}
96+
$cl = function (False $a, TRUE $b, Null $c): ?True {};
97+
98+
// Intentional error, should be ignored by the sniff.
99+
interface PropertiesNotAllowed {
100+
public $notAllowed;
101+
}

src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.inc.fixed

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,9 @@ function intersectionReturnTypes ($var): \Package\ClassName&\Package\Other_Class
9393
$arrow = fn (int $a, string $b, bool $c, array $d, Foo\Bar $e) : int => $a * $b;
9494
$arrow = fn (int $a, string $b, bool $c, array $d, Foo\Bar $e) : float => $a * $b;
9595

96-
$cl = function (false $a, true $b, null $c): ?true {}
96+
$cl = function (false $a, true $b, null $c): ?true {};
97+
98+
// Intentional error, should be ignored by the sniff.
99+
interface PropertiesNotAllowed {
100+
public $notAllowed;
101+
}

src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ public function getErrorList()
8383
*/
8484
public function getWarningList()
8585
{
86-
return [];
86+
// Warning from getMemberProperties() about parse error.
87+
return [100 => 1];
8788

8889
}//end getWarningList()
8990

0 commit comments

Comments
 (0)