@@ -52,7 +52,7 @@ public static function classPropertiesTokenIndexes(
52
52
$ pointer = (int )$ token ['scope_opener ' ];
53
53
54
54
while ($ pointer ) {
55
- if (self ::isProperty ($ file , $ pointer )) {
55
+ if (self ::variableIsProperty ($ file , $ pointer )) {
56
56
$ propertyList [] = $ pointer ;
57
57
}
58
58
$ pointer = (int )$ file ->findNext (
@@ -67,14 +67,19 @@ public static function classPropertiesTokenIndexes(
67
67
68
68
/**
69
69
* @param File $file
70
- * @param int $variablePosition
70
+ * @param int $position
71
71
* @return bool
72
72
*/
73
- public static function isProperty (File $ file , int $ variablePosition ): bool
73
+ public static function variableIsProperty (File $ file , int $ position ): bool
74
74
{
75
+ $ token = $ file ->getTokens ()[$ position ];
76
+ if ($ token ['code ' ] !== T_VARIABLE ) {
77
+ return false ;
78
+ }
79
+
75
80
$ propertyPointer = $ file ->findPrevious (
76
81
[T_STATIC , T_WHITESPACE , T_COMMENT ],
77
- $ variablePosition - 1 ,
82
+ $ position - 1 ,
78
83
null ,
79
84
true
80
85
);
@@ -88,6 +93,44 @@ public static function isProperty(File $file, int $variablePosition): bool
88
93
);
89
94
}
90
95
96
+ /**
97
+ * @param File $file
98
+ * @param int $position
99
+ * @return bool
100
+ */
101
+ public static function functionIsMethod (File $ file , int $ position )
102
+ {
103
+ $ tokens = $ file ->getTokens ();
104
+ $ functionToken = $ tokens [$ position ];
105
+ if ($ functionToken ['code ' ] !== T_FUNCTION ) {
106
+ return false ;
107
+ }
108
+
109
+ $ classPointer = $ file ->findPrevious (
110
+ [T_CLASS , T_INTERFACE , T_TRAIT ],
111
+ $ position - 1
112
+ );
113
+
114
+ if (!$ classPointer ) {
115
+ return false ;
116
+ }
117
+
118
+ $ classToken = $ tokens [$ classPointer ];
119
+ if ($ classToken ['level ' ] !== $ functionToken ['level ' ] - 1 ) {
120
+ return false ;
121
+ }
122
+
123
+ $ openerPosition = $ classToken ['scope_opener ' ] ?? -1 ;
124
+ $ closerPosition = $ classToken ['scope_closer ' ] ?? -1 ;
125
+
126
+ return
127
+ $ openerPosition > 0
128
+ && $ closerPosition > 0
129
+ && $ closerPosition > ($ openerPosition + 1 )
130
+ && $ openerPosition < ($ position - 1 )
131
+ && $ closerPosition > $ position + 4 ; // 4 because: (){}
132
+ }
133
+
91
134
/**
92
135
* @param File $file
93
136
* @param int $position
@@ -102,7 +145,7 @@ public static function tokenTypeName(File $file, int $position): string
102
145
}
103
146
104
147
if ($ token ['code ' ] === T_VARIABLE ) {
105
- if (self ::isProperty ($ file , $ position )) {
148
+ if (self ::variableIsProperty ($ file , $ position )) {
106
149
return 'Property ' ;
107
150
}
108
151
0 commit comments