Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic/LowerCaseType: fix potential PHP notice #3833

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Standards/Generic/Sniffs/PHP/LowerCaseTypeSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'], '?');

Expand Down
5 changes: 5 additions & 0 deletions src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
3 changes: 2 additions & 1 deletion src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ public function getErrorList()
*/
public function getWarningList()
{
return [];
// Warning from getMemberProperties() about parse error.
return [98 => 1];

}//end getWarningList()

Expand Down