Skip to content

Commit

Permalink
Allow bare static property declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
sirbrillig committed Mar 25, 2019
1 parent f12701e commit fa48318
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion VariableAnalysis/Sniffs/CodeAnalysis/VariableAnalysisSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,18 @@ protected function checkForClassProperty(File $phpcsFile, $stackPtr, $varName, $
}
$stopAtPtr = $staticPtr - 2;
$visibilityPtr = $phpcsFile->findPrevious($propertyDeclarationKeywords, $staticPtr - 1, $stopAtPtr > 0 ? $stopAtPtr : 0);
return boolval($visibilityPtr);
if ($visibilityPtr) {
return true;
}
// it's legal to use `static` to define properties as well as to
// define variables, so make sure we are not in a function before
// assuming it's a property.
$tokens = $phpcsFile->getTokens();
$token = $tokens[$stackPtr];
if ($token && !empty($token['conditions']) && end($token['conditions']) !== T_FUNCTION) {
return Helpers::areAnyConditionsAClass($token['conditions']);
}
return false;
}

protected function checkForCatchBlock(File $phpcsFile, $stackPtr, $varName, $currScope) {
Expand Down

0 comments on commit fa48318

Please sign in to comment.