Skip to content

Commit db31b5b

Browse files
authored
Merge pull request #698 from PHPCSStandards/php-8.4/variables-getmemberproperties-support-abstract-properties
PHP 8.4 | BCFile|Variables::getMemberProperties(): sync with PHPCS 3.13.3 / handle abstract properties
2 parents 0f6b802 + f8203a8 commit db31b5b

File tree

9 files changed

+316
-14
lines changed

9 files changed

+316
-14
lines changed

PHPCSUtils/BackCompat/BCFile.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ public static function getMethodParameters(File $phpcsFile, $stackPtr)
524524
*
525525
* Changelog for the PHPCS native function:
526526
* - Introduced in PHPCS 0.0.5.
527-
* - The upstream method has received no significant updates since PHPCS 3.13.0.
527+
* - The upstream method has received no significant updates since PHPCS 3.13.3.
528528
*
529529
* @see \PHP_CodeSniffer\Files\File::getMethodProperties() Original source.
530530
* @see \PHPCSUtils\Utils\FunctionDeclarations::getProperties() PHPCSUtils native improved version.
@@ -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,
@@ -751,7 +761,7 @@ public static function getMemberProperties(File $phpcsFile, $stackPtr)
751761
*
752762
* Changelog for the PHPCS native function:
753763
* - Introduced in PHPCS 1.3.0.
754-
* - The upstream method has received no significant updates since PHPCS 3.13.0.
764+
* - The upstream method has received no significant updates since PHPCS 3.13.3.
755765
*
756766
* @see \PHP_CodeSniffer\Files\File::getClassProperties() Original source.
757767
* @see \PHPCSUtils\Utils\ObjectDeclarations::getClassProperties() PHPCSUtils native improved version.
@@ -779,7 +789,7 @@ public static function getClassProperties(File $phpcsFile, $stackPtr)
779789
*
780790
* Changelog for the PHPCS native function:
781791
* - Introduced in PHPCS 0.0.5.
782-
* - The upstream method has received no significant updates since PHPCS 3.13.0.
792+
* - The upstream method has received no significant updates since PHPCS 3.13.3.
783793
*
784794
* @see \PHP_CodeSniffer\Files\File::isReference() Original source.
785795
* @see \PHPCSUtils\Utils\Operators::isReference() PHPCSUtils native improved version.
@@ -805,7 +815,7 @@ public static function isReference(File $phpcsFile, $stackPtr)
805815
*
806816
* Changelog for the PHPCS native function:
807817
* - Introduced in PHPCS 0.0.5.
808-
* - The upstream method has received no significant updates since PHPCS 3.13.0.
818+
* - The upstream method has received no significant updates since PHPCS 3.13.3.
809819
*
810820
* @see \PHP_CodeSniffer\Files\File::getTokensAsString() Original source.
811821
* @see \PHPCSUtils\Utils\GetTokensAsString Related set of functions.
@@ -834,7 +844,7 @@ public static function getTokensAsString(File $phpcsFile, $start, $length, $orig
834844
*
835845
* Changelog for the PHPCS native function:
836846
* - Introduced in PHPCS 2.1.0.
837-
* - The upstream method has received no significant updates since PHPCS 3.13.0.
847+
* - The upstream method has received no significant updates since PHPCS 3.13.3.
838848
*
839849
* @see \PHP_CodeSniffer\Files\File::findStartOfStatement() Original source.
840850
*
@@ -858,7 +868,7 @@ public static function findStartOfStatement(File $phpcsFile, $start, $ignore = n
858868
*
859869
* Changelog for the PHPCS native function:
860870
* - Introduced in PHPCS 2.1.0.
861-
* - The upstream method has received no significant updates since PHPCS 3.13.0.
871+
* - The upstream method has received no significant updates since PHPCS 3.13.3.
862872
*
863873
* @see \PHP_CodeSniffer\Files\File::findEndOfStatement() Original source.
864874
*
@@ -882,7 +892,7 @@ public static function findEndOfStatement(File $phpcsFile, $start, $ignore = nul
882892
*
883893
* Changelog for the PHPCS native function:
884894
* - Introduced in PHPCS 0.0.5.
885-
* - The upstream method has received no significant updates since PHPCS 3.13.0.
895+
* - The upstream method has received no significant updates since PHPCS 3.13.3.
886896
*
887897
* @see \PHP_CodeSniffer\Files\File::hasCondition() Original source.
888898
* @see \PHPCSUtils\Utils\Conditions::hasCondition() PHPCSUtils native alternative.
@@ -907,7 +917,7 @@ public static function hasCondition(File $phpcsFile, $stackPtr, $types)
907917
*
908918
* Changelog for the PHPCS native function:
909919
* - Introduced in PHPCS 1.3.0.
910-
* - The upstream method has received no significant updates since PHPCS 3.13.0.
920+
* - The upstream method has received no significant updates since PHPCS 3.13.3.
911921
*
912922
* @see \PHP_CodeSniffer\Files\File::getCondition() Original source.
913923
* @see \PHPCSUtils\Utils\Conditions::getCondition() More versatile alternative.

PHPCSUtils/BackCompat/BCTokens.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ final class BCTokens
7272

7373
/**
7474
* Handle calls to (undeclared) methods for token arrays which haven't received any
75-
* changes since PHPCS 3.13.0.
75+
* changes since PHPCS 3.13.3.
7676
*
7777
* @since 1.0.0
7878
*

PHPCSUtils/Tokens/Collections.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@ final class Collections
478478
\T_VAR => \T_VAR,
479479
\T_READONLY => \T_READONLY,
480480
\T_FINAL => \T_FINAL,
481+
\T_ABSTRACT => \T_ABSTRACT,
481482
];
482483

483484
/**

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,

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Whether you need to split an `array` into the individual items, are trying to de
4646

4747
Includes improved versions of the PHPCS native utility functions and plenty of new utility functions.
4848

49-
These functions are compatible with PHPCS 3.13.0 up to PHPCS `4.x`.
49+
These functions are compatible with PHPCS 3.13.3 up to PHPCS `4.x`.
5050

5151
### A collection of static properties and methods for often-used token groups
5252

@@ -78,7 +78,7 @@ To see detailed information about all the available abstract sniffs, utility fun
7878
## Minimum Requirements
7979

8080
* PHP 5.4 or higher.
81-
* [PHP_CodeSniffer] 3.13.0+/4.0.0+.
81+
* [PHP_CodeSniffer] 3.13.3+/4.0.0+.
8282
* Recommended PHP extensions for optimal functionality:
8383
- PCRE with Unicode support (normally enabled by default)
8484

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)