@@ -127,67 +127,61 @@ private function countArguments( $phpcsFile, $stackPtr ) { // phpcs:ignore Gener
127127 continue ;
128128 }
129129
130- $ quantity ++;
131-
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 );
135-
136- if (
137- $ tokens [ $ currentPosition ]['code ' ] !== T_STATIC &&
138- $ tokens [ $ currentPosition + 1 ]['code ' ] !== T_OBJECT_OPERATOR
139- ) {
140- $ currentPosition ++;
141-
142- continue ;
130+ if ( in_array ( $ tokens [ $ currentPosition ]['code ' ], [ T_ARRAY , T_OPEN_SHORT_ARRAY ], true ) ) {
131+ $ quantity ++;
143132 }
144133
145- if ( $ tokens [ $ currentPosition + 3 ]['code ' ] === T_COMMA ) {
146- $ currentPosition += 4 ;
147-
134+ if ( $ this ->skip ( $ phpcsFile , $ currentPosition ) ) {
148135 continue ;
149136 }
150137
151- if ( ! empty ( $ tokens [ $ currentPosition + 3 ]['bracket_closer ' ] ) ) {
152- $ currentPosition = $ tokens [ $ currentPosition + 3 ]['bracket_closer ' ] + 1 ;
153-
154- continue ;
155- }
138+ $ quantity ++;
156139
157- if ( ! empty ( $ tokens [ $ currentPosition + 3 ]['parenthesis_closer ' ] ) ) {
158- $ currentPosition = $ tokens [ $ currentPosition + 3 ]['parenthesis_closer ' ] + 1 ;
140+ $ currentPosition = $ phpcsFile ->findNext ( T_COMMA , $ currentPosition + 1 );
159141
160- continue ;
142+ if ( ! $ currentPosition ) {
143+ break ;
161144 }
162-
163- $ currentPosition ++;
164145 }
165146
166147 return $ quantity ;
167148 }
168149
169150 /**
170- * Maybe skip some tokens.
151+ * Skip some tokens.
171152 *
172153 * @since 1.0.3
173154 *
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.
155+ * @param File $phpcsFile The PHP_CodeSniffer file where the token was found.
156+ * @param int $currentPosition Current position.
179157 *
180- * @return mixed
158+ * @return bool
181159 */
182- private function maybeSkip ( $ phpcsFile , $ currentPosition , $ startKey , $ endKey , $ count ) {
160+ private function skip ( $ phpcsFile , &$ currentPosition ) {
161+
162+ $ skipTokens = [
163+ 'parenthesis ' ,
164+ 'bracket ' ,
165+ 'scope ' ,
166+ ];
167+
168+ $ skip = false ;
183169
184170 $ tokens = $ phpcsFile ->getTokens ();
185171
186- if ( ! empty ( $ tokens [ $ currentPosition ][ $ startKey ] ) ) {
187- $ currentPosition = $ tokens [ $ currentPosition ][ $ endKey ] + $ count ;
172+ foreach ( $ skipTokens as $ skipToken ) {
173+ $ opener = $ skipToken . '_opener ' ;
174+ $ closer = $ skipToken . '_closer ' ;
175+
176+ if ( isset ( $ tokens [ $ currentPosition ][ $ opener ] ) ) {
177+ $ currentPosition = $ tokens [ $ currentPosition ][ $ closer ] + 1 ;
178+ $ skip = true ;
179+
180+ break ;
181+ }
188182 }
189183
190- return $ currentPosition ;
184+ return $ skip ;
191185 }
192186
193187 /**
0 commit comments