File tree Expand file tree Collapse file tree 1 file changed +68
-0
lines changed Expand file tree Collapse file tree 1 file changed +68
-0
lines changed Original file line number Diff line number Diff line change @@ -131,6 +131,74 @@ public static function functionIsMethod(File $file, int $position)
131131 && $ closerPosition > $ position + 4 ; // 4 because: (){}
132132 }
133133
134+ /**
135+ * @param File $file
136+ * @param int $position
137+ * @return bool
138+ */
139+ public static function isFunctionCall (File $ file , int $ position ): bool
140+ {
141+ $ tokens = $ file ->getTokens ();
142+ $ code = $ tokens [$ position ]['code ' ] ?? -1 ;
143+ if (!in_array ($ code , [T_VARIABLE , T_STRING ], true )) {
144+ return false ;
145+ }
146+
147+ $ nextNonWhitePosition = $ file ->findNext (
148+ [T_WHITESPACE ],
149+ $ position + 1 ,
150+ null ,
151+ true ,
152+ null ,
153+ true
154+ );
155+
156+ if (!$ nextNonWhitePosition
157+ || $ tokens [$ nextNonWhitePosition ]['code ' ] !== T_OPEN_PARENTHESIS
158+ ) {
159+ return false ;
160+ }
161+
162+ $ previousNonWhite = $ file ->findPrevious (
163+ [T_WHITESPACE ],
164+ $ position - 1 ,
165+ null ,
166+ true ,
167+ null ,
168+ true
169+ );
170+
171+ if ($ previousNonWhite && ($ tokens [$ previousNonWhite ]['code ' ] ?? -1 ) === T_NS_SEPARATOR ) {
172+ $ previousNonWhite = $ file ->findPrevious (
173+ [T_WHITESPACE , T_STRING , T_NS_SEPARATOR ],
174+ $ previousNonWhite - 1 ,
175+ null ,
176+ true ,
177+ null ,
178+ true
179+ );
180+ }
181+
182+ if ($ previousNonWhite && $ tokens [$ previousNonWhite ]['code ' ] === T_NEW ) {
183+ return false ;
184+ }
185+
186+ $ closeParenthesisPosition = $ file ->findNext (
187+ [T_CLOSE_PARENTHESIS ],
188+ $ position + 2 ,
189+ null ,
190+ false ,
191+ null ,
192+ true
193+ );
194+
195+ $ parenthesisCloserPosition = $ tokens [$ nextNonWhitePosition ]['parenthesis_closer ' ] ?? -1 ;
196+
197+ return
198+ $ closeParenthesisPosition
199+ && $ closeParenthesisPosition === $ parenthesisCloserPosition ;
200+ }
201+
134202 /**
135203 * @param File $file
136204 * @param int $position
You can’t perform that action at this time.
0 commit comments