@@ -76,7 +76,10 @@ public static function getName(File $phpcsFile, $stackPtr)
76
76
* Main differences with the PHPCS version:
77
77
* - Bugs fixed:
78
78
* - Handling of PHPCS annotations.
79
+ * - `has_body` index could be set to `true` for functions without body in the case of
80
+ * parse errors or live coding.
79
81
* - Defensive coding against incorrect calls to this method.
82
+ * - More efficient checking whether a function has a body.
80
83
*
81
84
* @see \PHP_CodeSniffer\Files\File::getMethodProperties() Original source.
82
85
* @see \PHPCSUtils\BackCompat\BCFile::getMethodProperties() Cross-version compatible version of the original.
@@ -150,7 +153,7 @@ public static function getProperties(File $phpcsFile, $stackPtr)
150
153
$ returnType = '' ;
151
154
$ returnTypeToken = false ;
152
155
$ nullableReturnType = false ;
153
- $ hasBody = true ;
156
+ $ hasBody = false ;
154
157
155
158
if (isset ($ tokens [$ stackPtr ]['parenthesis_closer ' ]) === true ) {
156
159
$ scopeOpener = null ;
@@ -159,10 +162,14 @@ public static function getProperties(File $phpcsFile, $stackPtr)
159
162
}
160
163
161
164
for ($ i = $ tokens [$ stackPtr ]['parenthesis_closer ' ]; $ i < $ phpcsFile ->numTokens ; $ i ++) {
162
- if (($ scopeOpener === null && $ tokens [$ i ]['code ' ] === \T_SEMICOLON )
163
- || ($ scopeOpener !== null && $ i === $ scopeOpener )
164
- ) {
165
+ if ($ i === $ scopeOpener ) {
165
166
// End of function definition.
167
+ $ hasBody = true ;
168
+ break ;
169
+ }
170
+
171
+ if ($ scopeOpener === null && $ tokens [$ i ]['code ' ] === \T_SEMICOLON ) {
172
+ // End of abstract/interface function definition.
166
173
break ;
167
174
}
168
175
@@ -181,12 +188,6 @@ public static function getProperties(File $phpcsFile, $stackPtr)
181
188
$ returnType .= $ tokens [$ i ]['content ' ];
182
189
}
183
190
}
184
-
185
- $ end = $ phpcsFile ->findNext (
186
- [\T_OPEN_CURLY_BRACKET , \T_SEMICOLON ],
187
- $ tokens [$ stackPtr ]['parenthesis_closer ' ]
188
- );
189
- $ hasBody = $ tokens [$ end ]['code ' ] === \T_OPEN_CURLY_BRACKET ;
190
191
}
191
192
192
193
if ($ returnType !== '' && $ nullableReturnType === true ) {
0 commit comments