Skip to content

Commit 168e2c2

Browse files
committed
Remove search for visibility keywords to find properties
This defaults to only using the condition: if a variable is defined inside a class and not inside a method within a class, then it's a property.
1 parent b63cb8a commit 168e2c2

File tree

1 file changed

+1
-23
lines changed

1 file changed

+1
-23
lines changed

VariableAnalysis/Sniffs/CodeAnalysis/VariableAnalysisSniff.php

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -864,29 +864,7 @@ protected function processVariableAsUseImportDefinition(File $phpcsFile, $stackP
864864
*/
865865
protected function processVariableAsClassProperty(File $phpcsFile, $stackPtr)
866866
{
867-
$propertyDeclarationKeywords = [
868-
T_PUBLIC,
869-
T_PRIVATE,
870-
T_PROTECTED,
871-
T_VAR,
872-
];
873-
$stopAtPtr = $stackPtr - 2;
874-
$visibilityPtr = $phpcsFile->findPrevious($propertyDeclarationKeywords, $stackPtr - 1, $stopAtPtr > 0 ? $stopAtPtr : 0);
875-
if ($visibilityPtr) {
876-
return true;
877-
}
878-
$staticPtr = $phpcsFile->findPrevious(T_STATIC, $stackPtr - 1, $stopAtPtr > 0 ? $stopAtPtr : 0);
879-
if (! $staticPtr) {
880-
return false;
881-
}
882-
$stopAtPtr = $staticPtr - 2;
883-
$visibilityPtr = $phpcsFile->findPrevious($propertyDeclarationKeywords, $staticPtr - 1, $stopAtPtr > 0 ? $stopAtPtr : 0);
884-
if ($visibilityPtr) {
885-
return true;
886-
}
887-
// it's legal to use `static` to define properties as well as to
888-
// define variables, so make sure we are not in a function before
889-
// assuming it's a property.
867+
// Make sure we are not in a class method before assuming it's a property.
890868
$tokens = $phpcsFile->getTokens();
891869

892870
/** @var array{conditions?: (int|string)[], content?: string}|null */

0 commit comments

Comments
 (0)