@@ -185,6 +185,12 @@ public static function getDeclarationName(File $phpcsFile, $stackPtr)
185185 * // This index will only be set if the property is readonly.
186186 * ```
187187 *
188+ * ... and if the promoted property uses asymmetric visibility, these additional array indexes will also be available:
189+ * ```php
190+ * 'set_visibility' => string, // The property set-visibility as declared.
191+ * 'set_visibility_token' => integer, // The stack pointer to the set-visibility modifier token.
192+ * ```
193+ *
188194 * PHPCS cross-version compatible version of the `File::getMethodParameters()` method.
189195 *
190196 * Changelog for the PHPCS native function:
@@ -196,6 +202,7 @@ public static function getDeclarationName(File $phpcsFile, $stackPtr)
196202 *
197203 * @since 1.0.0
198204 * @since 1.0.6 Sync with PHPCS 3.8.0, support for readonly properties without explicit visibility. PHPCS#3801.
205+ * @since 1.1.0 Sync with PHPCS 3.13.1, support for asymmetric properties. PHPCS(new)#851
199206 *
200207 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
201208 * @param int $stackPtr The position in the stack of the function token
@@ -242,23 +249,24 @@ public static function getMethodParameters(File $phpcsFile, $stackPtr)
242249
243250 $ closer = $ tokens [$ opener ]['parenthesis_closer ' ];
244251
245- $ vars = [];
246- $ currVar = null ;
247- $ paramStart = ($ opener + 1 );
248- $ defaultStart = null ;
249- $ equalToken = null ;
250- $ paramCount = 0 ;
251- $ hasAttributes = false ;
252- $ passByReference = false ;
253- $ referenceToken = false ;
254- $ variableLength = false ;
255- $ variadicToken = false ;
256- $ typeHint = '' ;
257- $ typeHintToken = false ;
258- $ typeHintEndToken = false ;
259- $ nullableType = false ;
260- $ visibilityToken = null ;
261- $ readonlyToken = null ;
252+ $ vars = [];
253+ $ currVar = null ;
254+ $ paramStart = ($ opener + 1 );
255+ $ defaultStart = null ;
256+ $ equalToken = null ;
257+ $ paramCount = 0 ;
258+ $ hasAttributes = false ;
259+ $ passByReference = false ;
260+ $ referenceToken = false ;
261+ $ variableLength = false ;
262+ $ variadicToken = false ;
263+ $ typeHint = '' ;
264+ $ typeHintToken = false ;
265+ $ typeHintEndToken = false ;
266+ $ nullableType = false ;
267+ $ visibilityToken = null ;
268+ $ setVisibilityToken = null ;
269+ $ readonlyToken = null ;
262270
263271 for ($ i = $ paramStart ; $ i <= $ closer ; $ i ++) {
264272 // Check to see if this token has a parenthesis or bracket opener. If it does
@@ -392,6 +400,13 @@ public static function getMethodParameters(File $phpcsFile, $stackPtr)
392400 $ visibilityToken = $ i ;
393401 }
394402 break ;
403+ case T_PUBLIC_SET :
404+ case T_PROTECTED_SET :
405+ case T_PRIVATE_SET :
406+ if ($ defaultStart === null ) {
407+ $ setVisibilityToken = $ i ;
408+ }
409+ break ;
395410 case T_READONLY :
396411 if ($ defaultStart === null ) {
397412 $ readonlyToken = $ i ;
@@ -426,16 +441,21 @@ public static function getMethodParameters(File $phpcsFile, $stackPtr)
426441 $ vars [$ paramCount ]['type_hint_end_token ' ] = $ typeHintEndToken ;
427442 $ vars [$ paramCount ]['nullable_type ' ] = $ nullableType ;
428443
429- if ($ visibilityToken !== null || $ readonlyToken !== null ) {
444+ if ($ visibilityToken !== null || $ setVisibilityToken !== null || $ readonlyToken !== null ) {
430445 $ vars [$ paramCount ]['property_visibility ' ] = 'public ' ;
431446 $ vars [$ paramCount ]['visibility_token ' ] = false ;
432- $ vars [$ paramCount ]['property_readonly ' ] = false ;
433447
434448 if ($ visibilityToken !== null ) {
435449 $ vars [$ paramCount ]['property_visibility ' ] = $ tokens [$ visibilityToken ]['content ' ];
436450 $ vars [$ paramCount ]['visibility_token ' ] = $ visibilityToken ;
437451 }
438452
453+ if ($ setVisibilityToken !== null ) {
454+ $ vars [$ paramCount ]['set_visibility ' ] = $ tokens [$ setVisibilityToken ]['content ' ];
455+ $ vars [$ paramCount ]['set_visibility_token ' ] = $ setVisibilityToken ;
456+ }
457+
458+ $ vars [$ paramCount ]['property_readonly ' ] = false ;
439459 if ($ readonlyToken !== null ) {
440460 $ vars [$ paramCount ]['property_readonly ' ] = true ;
441461 $ vars [$ paramCount ]['readonly_token ' ] = $ readonlyToken ;
@@ -449,21 +469,22 @@ public static function getMethodParameters(File $phpcsFile, $stackPtr)
449469 }
450470
451471 // Reset the vars, as we are about to process the next parameter.
452- $ currVar = null ;
453- $ paramStart = ($ i + 1 );
454- $ defaultStart = null ;
455- $ equalToken = null ;
456- $ hasAttributes = false ;
457- $ passByReference = false ;
458- $ referenceToken = false ;
459- $ variableLength = false ;
460- $ variadicToken = false ;
461- $ typeHint = '' ;
462- $ typeHintToken = false ;
463- $ typeHintEndToken = false ;
464- $ nullableType = false ;
465- $ visibilityToken = null ;
466- $ readonlyToken = null ;
472+ $ currVar = null ;
473+ $ paramStart = ($ i + 1 );
474+ $ defaultStart = null ;
475+ $ equalToken = null ;
476+ $ hasAttributes = false ;
477+ $ passByReference = false ;
478+ $ referenceToken = false ;
479+ $ variableLength = false ;
480+ $ variadicToken = false ;
481+ $ typeHint = '' ;
482+ $ typeHintToken = false ;
483+ $ typeHintEndToken = false ;
484+ $ nullableType = false ;
485+ $ visibilityToken = null ;
486+ $ setVisibilityToken = null ;
487+ $ readonlyToken = null ;
467488
468489 ++$ paramCount ;
469490 break ;
@@ -532,6 +553,9 @@ public static function getMethodProperties(File $phpcsFile, $stackPtr)
532553 * array(
533554 * 'scope' => string, // Public, private, or protected.
534555 * 'scope_specified' => boolean, // TRUE if the scope was explicitly specified.
556+ * 'set_scope' => string|false, // Scope for asymmetric visibility.
557+ * // Either public, private, or protected or
558+ * // FALSE if no set scope is specified.
535559 * 'is_static' => boolean, // TRUE if the static keyword was found.
536560 * 'is_readonly' => boolean, // TRUE if the readonly keyword was found.
537561 * 'is_final' => boolean, // TRUE if the final keyword was found.
@@ -598,19 +622,18 @@ public static function getMemberProperties(File $phpcsFile, $stackPtr)
598622 }
599623
600624 $ valid = [
601- T_PUBLIC => T_PUBLIC ,
602- T_PRIVATE => T_PRIVATE ,
603- T_PROTECTED => T_PROTECTED ,
604- T_STATIC => T_STATIC ,
605- T_VAR => T_VAR ,
606- T_READONLY => T_READONLY ,
607- T_FINAL => T_FINAL ,
625+ T_STATIC => T_STATIC ,
626+ T_VAR => T_VAR ,
627+ T_READONLY => T_READONLY ,
628+ T_FINAL => T_FINAL ,
608629 ];
609630
631+ $ valid += Tokens::$ scopeModifiers ;
610632 $ valid += Tokens::$ emptyTokens ;
611633
612634 $ scope = 'public ' ;
613635 $ scopeSpecified = false ;
636+ $ setScope = false ;
614637 $ isStatic = false ;
615638 $ isReadonly = false ;
616639 $ isFinal = false ;
@@ -643,6 +666,15 @@ public static function getMemberProperties(File $phpcsFile, $stackPtr)
643666 $ scope = 'protected ' ;
644667 $ scopeSpecified = true ;
645668 break ;
669+ case T_PUBLIC_SET :
670+ $ setScope = 'public ' ;
671+ break ;
672+ case T_PROTECTED_SET :
673+ $ setScope = 'protected ' ;
674+ break ;
675+ case T_PRIVATE_SET :
676+ $ setScope = 'private ' ;
677+ break ;
646678 case T_STATIC :
647679 $ isStatic = true ;
648680 break ;
@@ -692,6 +724,7 @@ public static function getMemberProperties(File $phpcsFile, $stackPtr)
692724 return [
693725 'scope ' => $ scope ,
694726 'scope_specified ' => $ scopeSpecified ,
727+ 'set_scope ' => $ setScope ,
695728 'is_static ' => $ isStatic ,
696729 'is_readonly ' => $ isReadonly ,
697730 'is_final ' => $ isFinal ,
0 commit comments