Skip to content

Commit 89a588a

Browse files
committed
Merge branch 'feature/squiz-methodscope-handle-unconventional-spacing' of https://github.com/jrfnl/PHP_CodeSniffer
2 parents d9cf568 + 10c10ac commit 89a588a

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

src/Standards/Squiz/Sniffs/Scope/MethodScopeSniff.php

+2-11
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,8 @@ protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScop
5454
return;
5555
}
5656

57-
$modifier = null;
58-
for ($i = ($stackPtr - 1); $i > 0; $i--) {
59-
if ($tokens[$i]['line'] < $tokens[$stackPtr]['line']) {
60-
break;
61-
} else if (isset(Tokens::$scopeModifiers[$tokens[$i]['code']]) === true) {
62-
$modifier = $i;
63-
break;
64-
}
65-
}
66-
67-
if ($modifier === null) {
57+
$properties = $phpcsFile->getMethodProperties($stackPtr);
58+
if ($properties['scope_specified'] === false) {
6859
$error = 'Visibility must be declared on method "%s"';
6960
$data = [$methodName];
7061
$phpcsFile->addError($error, $stackPtr, 'Missing', $data);

src/Standards/Squiz/Tests/Scope/MethodScopeUnitTest.inc

+7
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,10 @@ enum SomeEnum
4848
private function func1() {}
4949
protected function func1() {}
5050
}
51+
52+
class UnconventionalSpacing {
53+
public
54+
static
55+
function
56+
myFunction() {}
57+
}

0 commit comments

Comments
 (0)