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

Squiz.Scope.MethodScope misses visibility keyword on previous line #3575

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 2 additions & 11 deletions src/Standards/Squiz/Sniffs/Scope/MethodScopeSniff.php
Expand Up @@ -54,17 +54,8 @@ protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScop
return;
}

$modifier = null;
for ($i = ($stackPtr - 1); $i > 0; $i--) {
if ($tokens[$i]['line'] < $tokens[$stackPtr]['line']) {
break;
} else if (isset(Tokens::$scopeModifiers[$tokens[$i]['code']]) === true) {
$modifier = $i;
break;
}
}

if ($modifier === null) {
$properties = $phpcsFile->getMethodProperties($stackPtr);
if ($properties['scope_specified'] === false) {
$error = 'Visibility must be declared on method "%s"';
$data = [$methodName];
$phpcsFile->addError($error, $stackPtr, 'Missing', $data);
Expand Down
7 changes: 7 additions & 0 deletions src/Standards/Squiz/Tests/Scope/MethodScopeUnitTest.inc
Expand Up @@ -48,3 +48,10 @@ enum SomeEnum
private function func1() {}
protected function func1() {}
}

class UnconventionalSpacing {
public
static
function
myFunction() {}
}