Skip to content

Commit ee099da

Browse files
authored
Merge pull request #907 from PHPCSStandards/feature/tokenizer-php-follow-up-final-properties
PHP 8.4 | Tokenizer/PHP: fix union/intersection/DNF type tokenization with `final` properties
2 parents 32f7d88 + cdfa1d4 commit ee099da

File tree

7 files changed

+35
-2
lines changed

7 files changed

+35
-2
lines changed

src/Tokenizers/PHP.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3379,7 +3379,8 @@ protected function processAdditional()
33793379
&& (isset(Tokens::$scopeModifiers[$this->tokens[$x]['code']]) === true
33803380
|| $this->tokens[$x]['code'] === T_VAR
33813381
|| $this->tokens[$x]['code'] === T_STATIC
3382-
|| $this->tokens[$x]['code'] === T_READONLY)
3382+
|| $this->tokens[$x]['code'] === T_READONLY
3383+
|| $this->tokens[$x]['code'] === T_FINAL)
33833384
) {
33843385
// This will also confirm constructor property promotion parameters, but that's fine.
33853386
$confirmed = true;

tests/Core/Tokenizers/PHP/BitwiseOrTest.inc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,15 @@ class TypeUnion
7575
/* testTypeUnionPropertyWithOnlyStaticKeyword */
7676
static Foo|Bar $obj;
7777

78+
/* testTypeUnionWithPHP84FinalKeyword */
79+
final int|string $finalKeywordA;
80+
81+
/* testTypeUnionWithPHP84FinalKeywordFirst */
82+
final private float|null $finalKeywordB;
83+
84+
/* testTypeUnionWithPHP84FinalKeywordAndFQN */
85+
final \MyClass|false $finalKeywordC;
86+
7887
public function paramTypes(
7988
/* testTypeUnionParam1 */
8089
int|float $paramA /* testBitwiseOrParamDefaultValue */ = CONSTANT_A | CONSTANT_B,

tests/Core/Tokenizers/PHP/BitwiseOrTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ public static function dataTypeUnion()
125125
'type for readonly property, reversed modifier order' => ['/* testTypeUnionPropertyWithReadOnlyKeywordFirst */'],
126126
'type for readonly property, no visibility' => ['/* testTypeUnionPropertyWithOnlyReadOnlyKeyword */'],
127127
'type for static property, no visibility' => ['/* testTypeUnionPropertyWithOnlyStaticKeyword */'],
128+
'type for final property, no visibility' => ['/* testTypeUnionWithPHP84FinalKeyword */'],
129+
'type for final property, reversed modifier order' => ['/* testTypeUnionWithPHP84FinalKeywordFirst */'],
130+
'type for final property, no visibility, FQN type' => ['/* testTypeUnionWithPHP84FinalKeywordAndFQN */'],
128131
'type for method parameter' => ['/* testTypeUnionParam1 */'],
129132
'type for method parameter, first in multi-union' => ['/* testTypeUnionParam2 */'],
130133
'type for method parameter, last in multi-union' => ['/* testTypeUnionParam3 */'],

tests/Core/Tokenizers/PHP/DNFTypesTest.inc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,12 @@ abstract class DNFTypes {
175175
/* testDNFTypePropertyWithOnlyStaticKeyword */
176176
static (A&B&C)|true $onlyStaticModified;
177177

178+
/* testDNFTypeWithPHP84FinalKeyword */
179+
final (className&InterfaceName)|false $finalKeywordA;
180+
181+
/* testDNFTypeWithPHP84FinalKeywordAndStatic */
182+
final static (\className&\InterfaceName)|false $finalKeywordB;
183+
178184
public function paramTypes(
179185
/* testDNFTypeParam1WithAttribute */
180186
#[MyAttribute]

tests/Core/Tokenizers/PHP/DNFTypesTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,6 @@ public static function dataDNFTypeParentheses()
432432
'OO property type: multi-dnf fully qualified classes' => [
433433
'testMarker' => '/* testDNFTypePropertyMultiFullyQualified */',
434434
],
435-
436435
'OO property type: multi-dnf with readonly keyword 1' => [
437436
'testMarker' => '/* testDNFTypePropertyWithReadOnlyKeyword1 */',
438437
],
@@ -445,6 +444,13 @@ public static function dataDNFTypeParentheses()
445444
'OO property type: with only static keyword' => [
446445
'testMarker' => '/* testDNFTypePropertyWithOnlyStaticKeyword */',
447446
],
447+
'OO property type: with only final keyword' => [
448+
'testMarker' => '/* testDNFTypeWithPHP84FinalKeyword */',
449+
],
450+
'OO property type: with final and static keyword' => [
451+
'testMarker' => '/* testDNFTypeWithPHP84FinalKeywordAndStatic */',
452+
],
453+
448454
'OO method param type: first param' => [
449455
'testMarker' => '/* testDNFTypeParam1WithAttribute */',
450456
],

tests/Core/Tokenizers/PHP/TypeIntersectionTest.inc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ class TypeIntersection
6363
/* testTypeIntersectionPropertyWithStaticKeyword */
6464
static Foo&Bar $obj;
6565

66+
/* testTypeIntersectionWithPHP84FinalKeyword */
67+
final className&InterfaceName $finalKeywordA;
68+
69+
/* testTypeIntersectionWithPHP84FinalKeywordFirst */
70+
final private \className&InterfaceName $finalKeywordB;
71+
6672
public function paramTypes(
6773
/* testTypeIntersectionParam1 */
6874
Foo&Bar $paramA /* testBitwiseAndParamDefaultValue */ = CONSTANT_A & CONSTANT_B,

tests/Core/Tokenizers/PHP/TypeIntersectionTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ public static function dataTypeIntersection()
124124
'type for property using fully qualified names' => ['/* testTypeIntersectionPropertyFullyQualified */'],
125125
'type for readonly property' => ['/* testTypeIntersectionPropertyWithReadOnlyKeyword */'],
126126
'type for static readonly property' => ['/* testTypeIntersectionPropertyWithStaticKeyword */'],
127+
'type for final property' => ['/* testTypeIntersectionWithPHP84FinalKeyword */'],
128+
'type for final property reversed modifier order' => ['/* testTypeIntersectionWithPHP84FinalKeywordFirst */'],
127129
'type for method parameter' => ['/* testTypeIntersectionParam1 */'],
128130
'type for method parameter, first in multi-intersect' => ['/* testTypeIntersectionParam2 */'],
129131
'type for method parameter, last in multi-intersect' => ['/* testTypeIntersectionParam3 */'],

0 commit comments

Comments
 (0)