@@ -129,23 +129,9 @@ private function countArguments( $phpcsFile, $stackPtr ) { // phpcs:ignore Gener
129129
130130 $ quantity ++;
131131
132- if ( ! empty ( $ tokens [ $ currentPosition ]['parenthesis_opener ' ] ) ) {
133- $ currentPosition = $ tokens [ $ currentPosition ]['parenthesis_closer ' ] + 1 ;
134-
135- continue ;
136- }
137-
138- if ( ! empty ( $ tokens [ $ currentPosition ]['bracket_closer ' ] ) ) {
139- $ currentPosition = $ tokens [ $ currentPosition ]['bracket_closer ' ] + 2 ;
140-
141- continue ;
142- }
143-
144- if ( ! empty ( $ tokens [ $ currentPosition ]['scope_closer ' ] ) ) {
145- $ currentPosition = $ tokens [ $ currentPosition ]['scope_closer ' ] + 2 ;
146-
147- continue ;
148- }
132+ $ currentPosition = $ this ->maybeSkip ( $ phpcsFile , $ currentPosition , 'parenthesis_opener ' , 'parenthesis_closer ' , 1 );
133+ $ currentPosition = $ this ->maybeSkip ( $ phpcsFile , $ currentPosition , 'bracket_closer ' , 'bracket_closer ' , 2 );
134+ $ currentPosition = $ this ->maybeSkip ( $ phpcsFile , $ currentPosition , 'scope_closer ' , 'scope_closer ' , 2 );
149135
150136 if (
151137 $ tokens [ $ currentPosition ]['code ' ] !== T_STATIC &&
@@ -180,6 +166,30 @@ private function countArguments( $phpcsFile, $stackPtr ) { // phpcs:ignore Gener
180166 return $ quantity ;
181167 }
182168
169+ /**
170+ * Maybe skip some tokens.
171+ *
172+ * @since 1.0.3
173+ *
174+ * @param File $phpcsFile The PHP_CodeSniffer file where the token was found.
175+ * @param int $currentPosition Current position.
176+ * @param string $startKey Start key.
177+ * @param string $endKey End key.
178+ * @param int $count Count.
179+ *
180+ * @return mixed
181+ */
182+ private function maybeSkip ( $ phpcsFile , $ currentPosition , $ startKey , $ endKey , $ count ) {
183+
184+ $ tokens = $ phpcsFile ->getTokens ();
185+
186+ if ( ! empty ( $ tokens [ $ currentPosition ][ $ startKey ] ) ) {
187+ $ currentPosition = $ tokens [ $ currentPosition ][ $ endKey ] + $ count ;
188+ }
189+
190+ return $ currentPosition ;
191+ }
192+
183193 /**
184194 * Process params tag.
185195 *
0 commit comments