Skip to content

Commit e4ae9c1

Browse files
committed
PHP 8.4 | BCFile|Variables::getMemberProperties(): sync with PHPCS 3.13.3 / handle abstract properties
Refs: * https://wiki.php.net/rfc/property-hooks#abstract_properties * PHPCSStandards/PHP_CodeSniffer 1184
1 parent c13813c commit e4ae9c1

File tree

4 files changed

+301
-0
lines changed

4 files changed

+301
-0
lines changed

PHPCSUtils/BackCompat/BCFile.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,7 @@ public static function getMethodProperties(File $phpcsFile, $stackPtr)
559559
* 'is_static' => boolean, // TRUE if the static keyword was found.
560560
* 'is_readonly' => boolean, // TRUE if the readonly keyword was found.
561561
* 'is_final' => boolean, // TRUE if the final keyword was found.
562+
* 'is_abstract' => boolean, // TRUE if the abstract keyword was found.
562563
* 'type' => string, // The type of the var (empty if no type specified).
563564
* 'type_token' => integer|false, // The stack pointer to the start of the type
564565
* // or FALSE if there is no type.
@@ -573,13 +574,16 @@ public static function getMethodProperties(File $phpcsFile, $stackPtr)
573574
*
574575
* Changelog for the PHPCS native function:
575576
* - Introduced in PHPCS 0.0.5.
577+
* - PHPCS 3.13.3: support for PHP 8.4 abstract properties.
576578
* - PHPCS 4.0: properties in interfaces (PHP 8.4+) are accepted.
577579
* - PHPCS 4.0: will no longer throw a parse error warning.
578580
*
579581
* @see \PHP_CodeSniffer\Files\File::getMemberProperties() Original source.
580582
* @see \PHPCSUtils\Utils\Variables::getMemberProperties() PHPCSUtils native improved version.
581583
*
582584
* @since 1.0.0
585+
* @since 1.1.0 Sync with PHPCS 4.0.0, remove parse error warning and support PHP 8.4 properties in interfaces. PHPCS(new)#991
586+
* @since 1.1.2 Sync with PHPCS 3.13.3, support for abstract properties. PHPCS(new)#xxx
583587
*
584588
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
585589
* @param int $stackPtr The position in the stack of the `T_VARIABLE` token to
@@ -626,6 +630,7 @@ public static function getMemberProperties(File $phpcsFile, $stackPtr)
626630
T_VAR => T_VAR,
627631
T_READONLY => T_READONLY,
628632
T_FINAL => T_FINAL,
633+
T_ABSTRACT => T_ABSTRACT,
629634
];
630635

631636
$valid += Tokens::$scopeModifiers;
@@ -637,6 +642,7 @@ public static function getMemberProperties(File $phpcsFile, $stackPtr)
637642
$isStatic = false;
638643
$isReadonly = false;
639644
$isFinal = false;
645+
$isAbstract = false;
640646

641647
$startOfStatement = $phpcsFile->findPrevious(
642648
[
@@ -684,6 +690,9 @@ public static function getMemberProperties(File $phpcsFile, $stackPtr)
684690
case T_FINAL:
685691
$isFinal = true;
686692
break;
693+
case T_ABSTRACT:
694+
$isAbstract = true;
695+
break;
687696
}
688697
}
689698

@@ -728,6 +737,7 @@ public static function getMemberProperties(File $phpcsFile, $stackPtr)
728737
'is_static' => $isStatic,
729738
'is_readonly' => $isReadonly,
730739
'is_final' => $isFinal,
740+
'is_abstract' => $isAbstract,
731741
'type' => $type,
732742
'type_token' => $typeToken,
733743
'type_end_token' => $typeEndToken,

PHPCSUtils/Utils/Variables.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ final class Variables
108108
* 'is_static' => boolean, // TRUE if the static keyword was found.
109109
* 'is_readonly' => boolean, // TRUE if the readonly keyword was found.
110110
* 'is_final' => boolean, // TRUE if the final keyword was found.
111+
* 'is_abstract' => boolean, // TRUE if the abstract keyword was found.
111112
* 'type' => string, // The type of the var (empty if no type specified).
112113
* 'type_token' => integer|false, // The stack pointer to the start of the type
113114
* // or FALSE if there is no type.
@@ -155,6 +156,7 @@ public static function getMemberProperties(File $phpcsFile, $stackPtr)
155156
$isStatic = false;
156157
$isReadonly = false;
157158
$isFinal = false;
159+
$isAbstract = false;
158160

159161
$startOfStatement = $phpcsFile->findPrevious(
160162
[
@@ -211,6 +213,9 @@ public static function getMemberProperties(File $phpcsFile, $stackPtr)
211213
case \T_FINAL:
212214
$isFinal = true;
213215
break;
216+
case \T_ABSTRACT:
217+
$isAbstract = true;
218+
break;
214219
}
215220
}
216221

@@ -254,6 +259,7 @@ public static function getMemberProperties(File $phpcsFile, $stackPtr)
254259
'is_static' => $isStatic,
255260
'is_readonly' => $isReadonly,
256261
'is_final' => $isFinal,
262+
'is_abstract' => $isAbstract,
257263
'type' => $type,
258264
'type_token' => $typeToken,
259265
'type_end_token' => $typeEndToken,

Tests/BackCompat/BCFile/GetMemberPropertiesTest.inc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,3 +401,27 @@ class AsymVisibility {
401401
/* testPHP84IllegalAsymPublicProtectedSetStaticProperty */
402402
public protected(set) static mixed $prop10;
403403
}
404+
405+
abstract class WithAbstractProperties {
406+
/* testPHP84AbstractPublicTypedProp */
407+
abstract public string $val1 { get; }
408+
/* testPHP84AbstractProtectedTypedProp */
409+
abstract protected Union|Type $val2 { set; }
410+
/* testPHP84AbstractMiddleTypedProp */
411+
public abstract Intersection&Type $val3 { get; }
412+
/* testPHP84AbstractImplicitVisibilityTypedProp */
413+
abstract int $val4 { set; }
414+
/* testPHP84AbstractImplicitVisibilityProp */
415+
abstract $val5 { get; }
416+
/* testPHP84AbstractNullableTypedProp */
417+
abstract public ?string $val6 { set; }
418+
/* testPHP84AbstractComplexTypedProp */
419+
abstract protected (Foo&\Bar)|false $val7 { get; }
420+
421+
/* testPHP84IllegalAbstractPrivateProp */
422+
private abstract string $val8 { get; }
423+
/* testPHP84IllegalAbstractReadonlyProp */
424+
public readonly abstract string $val9 { get; }
425+
/* testPHP84IllegalAbstractStaticProp */
426+
public abstract static string $val10 { get; }
427+
}

0 commit comments

Comments
 (0)