@@ -74,25 +74,46 @@ public static function classPropertiesTokenIndexes(
74
74
*/
75
75
public static function variableIsProperty (File $ file , int $ position ): bool
76
76
{
77
- $ token = $ file ->getTokens ()[$ position ];
77
+ $ tokens = $ file ->getTokens ();
78
+ $ token = $ tokens [$ position ];
78
79
if ($ token ['code ' ] !== T_VARIABLE ) {
79
80
return false ;
80
81
}
81
82
82
- $ propertyPointer = $ file ->findPrevious (
83
- [T_STATIC , T_WHITESPACE , T_COMMENT ],
84
- $ position - 1 ,
85
- null ,
86
- true
87
- );
83
+ $ classes = [T_CLASS , T_ANON_CLASS , T_TRAIT ];
88
84
89
- $ propertyPointerToken = $ file ->getTokens ()[$ propertyPointer ] ?? [];
85
+ $ classPointer = $ file ->findPrevious ($ classes , $ position - 1 );
86
+ if (!$ classPointer
87
+ || !array_key_exists ($ classPointer , $ tokens )
88
+ || !in_array ($ tokens [$ classPointer ]['code ' ], $ classes , true )
89
+ ) {
90
+ return false ;
91
+ }
90
92
91
- return in_array (
92
- ($ propertyPointerToken ['code ' ] ?? '' ),
93
- [T_PRIVATE , T_PROTECTED , T_PUBLIC , T_VAR ],
94
- true
95
- );
93
+ $ opener = $ tokens [$ classPointer ]['scope_opener ' ] ?? -1 ;
94
+ $ closer = $ tokens [$ classPointer ]['scope_closer ' ] ?? -1 ;
95
+
96
+ if ($ opener <= 0
97
+ || $ closer <= 0
98
+ || $ closer <= $ opener
99
+ || $ closer <= $ position
100
+ || $ opener >= $ position
101
+ ) {
102
+ return false ;
103
+ }
104
+
105
+ $ exclude = Tokens::$ emptyTokens ;
106
+ $ exclude [] = T_STATIC ;
107
+ $ propertyModifierPointer = $ file ->findPrevious ($ exclude , $ position - 1 , null , true );
108
+ if (!$ propertyModifierPointer || !array_key_exists ($ propertyModifierPointer , $ tokens )) {
109
+ return false ;
110
+ }
111
+
112
+ $ propertyModifierCode = $ tokens [$ propertyModifierPointer ]['code ' ] ?? '' ;
113
+ $ modifiers = Tokens::$ scopeModifiers ;
114
+ $ modifiers [] = T_VAR ;
115
+
116
+ return in_array ($ propertyModifierCode , $ modifiers , true );
96
117
}
97
118
98
119
/**
0 commit comments