Skip to content

PEAR/FunctionDeclaration: prevent fixer conflict for unfinished closures/live coding #827

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

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,10 @@ public function process(File $phpcsFile, $stackPtr)
// enforced by the previous check because there is no content between the keywords
// and the opening parenthesis.
// Unfinished closures are tokenized as T_FUNCTION however, and can be excluded
// by checking for the scope_opener.
// by checking if the function has a name.
$methodProps = $phpcsFile->getMethodProperties($stackPtr);
if ($tokens[$stackPtr]['code'] === T_FUNCTION
&& (isset($tokens[$stackPtr]['scope_opener']) === true || $methodProps['has_body'] === false)
) {
$methodName = $phpcsFile->getDeclarationName($stackPtr);
if ($tokens[$stackPtr]['code'] === T_FUNCTION && $methodName !== null) {
if ($tokens[($openBracket - 1)]['content'] === $phpcsFile->eolChar) {
$spaces = 'newline';
} else if ($tokens[($openBracket - 1)]['code'] === T_WHITESPACE) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

// Intentional parse error/live coding.
// Ensuring that the sniff does not get into a fixer conflict with itself for unfinished closure declarations
// (missing close parenthesis for import use).
// This must be the only test in this file.
$closure = function (string $param) use ($var
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

// Intentional parse error/live coding.
// Ensuring that the sniff does not get into a fixer conflict with itself for unfinished closure declarations
// (missing close parenthesis for import use).
// This must be the only test in this file.
$closure = function(string $param) use ($var
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

// Intentional parse error/live coding.
// Ensuring that the sniff does not get into a fixer conflict with itself for unfinished closure declarations
// (missing close parenthesis for import use).
// This must be the only test in this file.
$closure = function (string $param) use ($var
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ public function getErrorList($testFile='')
48 => 1,
];

case 'FunctionDeclarationUnitTest.4.inc':
return [
7 => 1,
];

default:
return [];
}//end switch
Expand Down
Loading