Skip to content

Commit 916eb08

Browse files
authored
Merge pull request #1183 from PHPCSStandards/php-8.4/tokenizer-php-support-abstract-properties
PHP 8.4 | Tokenizer/PHP: fix union/intersection/DNF type tokenization with abstract properties
2 parents 9033cfc + e3978cd commit 916eb08

File tree

9 files changed

+47
-5
lines changed

9 files changed

+47
-5
lines changed

src/Tokenizers/PHP.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3499,7 +3499,8 @@ protected function processAdditional()
34993499
|| $this->tokens[$x]['code'] === T_VAR
35003500
|| $this->tokens[$x]['code'] === T_STATIC
35013501
|| $this->tokens[$x]['code'] === T_READONLY
3502-
|| $this->tokens[$x]['code'] === T_FINAL)
3502+
|| $this->tokens[$x]['code'] === T_FINAL
3503+
|| $this->tokens[$x]['code'] === T_ABSTRACT)
35033504
) {
35043505
// This will also confirm constructor property promotion parameters, but that's fine.
35053506
$confirmed = true;

tests/Core/Tokenizers/PHP/BitwiseOrTest.inc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/* testBitwiseOr1 */
88
$result = $value | $test /* testBitwiseOr2 */ | $another;
99

10-
class TypeUnion
10+
abstract class TypeUnion
1111
{
1212
/* testTypeUnionOOConstSimple */
1313
public const Foo|Bar SIMPLE = new Foo;
@@ -96,6 +96,15 @@ class TypeUnion
9696
/* testTypeUnionPropertyPublicProtected */
9797
public protected(set) Foo|Bar $asym4;
9898

99+
/* testTypeUnionWithPHP84AbstractKeyword */
100+
abstract int|string $abstractKeywordA { get; }
101+
102+
/* testTypeUnionWithPHP84AbstractKeywordFirst */
103+
abstract protected float|null $abstractKeywordB { set; }
104+
105+
/* testTypeUnionWithPHP84AbstractKeywordAndFQN */
106+
abstract \MyClass|false $abstractKeywordC { get; }
107+
99108
public function paramTypes(
100109
/* testTypeUnionParam1 */
101110
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
@@ -132,6 +132,9 @@ public static function dataTypeUnion()
132132
'type for public private(set) property' => ['/* testTypeUnionPropertyPublicPrivateSet */'],
133133
'type for protected(set) property' => ['/* testTypeUnionPropertyProtected */'],
134134
'type for public protected(set) property' => ['/* testTypeUnionPropertyPublicProtected */'],
135+
'type for abstract property, no visibility' => ['/* testTypeUnionWithPHP84AbstractKeyword */'],
136+
'type for abstract property, reversed modifier order' => ['/* testTypeUnionWithPHP84AbstractKeywordFirst */'],
137+
'type for abstract property, no visibility, FQN type' => ['/* testTypeUnionWithPHP84AbstractKeywordAndFQN */'],
135138
'type for method parameter' => ['/* testTypeUnionParam1 */'],
136139
'type for method parameter, first in multi-union' => ['/* testTypeUnionParam2 */'],
137140
'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
@@ -193,6 +193,12 @@ abstract class DNFTypes {
193193
/* testDNFTypePropertyWithPublicProtectedSet */
194194
public protected(set) (A&B&C)|true $asym4;
195195

196+
/* testDNFTypeWithPHP84AbstractKeyword */
197+
abstract (className&InterfaceName)|false $abstractKeywordA { set; }
198+
199+
/* testDNFTypeWithPHP84AbstractKeywordAndPublic */
200+
abstract public (\className&\InterfaceName)|false $abstractKeywordB { get; }
201+
196202
public function paramTypes(
197203
/* testDNFTypeParam1WithAttribute */
198204
#[MyAttribute]

tests/Core/Tokenizers/PHP/DNFTypesTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,13 @@ public static function dataDNFTypeParentheses()
462462
'OO property type: asymmetric vis, public protected(set)' => [
463463
'testMarker' => '/* testDNFTypePropertyWithPublicProtectedSet */',
464464
],
465+
'OO property type: with only abstract keyword' => [
466+
'testMarker' => '/* testDNFTypeWithPHP84AbstractKeyword */',
467+
],
468+
'OO property type: with abstract and public keyword' => [
469+
'testMarker' => '/* testDNFTypeWithPHP84AbstractKeywordAndPublic */',
470+
],
471+
465472
'OO method param type: first param' => [
466473
'testMarker' => '/* testDNFTypeParam1WithAttribute */',
467474
],

tests/Core/Tokenizers/PHP/NullableVsInlineThenTest.inc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
class Nullable
3+
abstract class Nullable
44
{
55
/* testNullableReadonlyOnly */
66
readonly ?int $prop;
@@ -10,6 +10,12 @@ class Nullable
1010

1111
/* testNullablePublicProtectedSet */
1212
public protected(set) ?int $prop3;
13+
14+
/* testNullableFinalOnly */
15+
final ?bool $prop4;
16+
17+
/* testNullableAbstractOnly */
18+
abstract ?string $prop5 { get; }
1319
}
1420

1521
class InlineThen

tests/Core/Tokenizers/PHP/NullableVsInlineThenTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,15 @@ public static function dataNullable()
5353
'property declaration, readonly, no visibility' => ['/* testNullableReadonlyOnly */'],
5454
'property declaration, private set' => ['/* testNullablePrivateSet */'],
5555
'property declaration, public and protected set' => ['/* testNullablePublicProtectedSet */'],
56+
'property declaration, final, no visibility' => ['/* testNullableFinalOnly */'],
57+
'property declaration, abstract, no visibility' => ['/* testNullableAbstractOnly */'],
5658
];
5759

5860
}//end dataNullable()
5961

6062

6163
/**
62-
* Test that "readonly" when not used as the keyword is still tokenized as `T_STRING`.
64+
* Test that a "?" when used as part of a ternary expression is tokenized as `T_INLINE_THEN`.
6365
*
6466
* @param string $testMarker The comment which prefaces the target token in the test file.
6567
*

tests/Core/Tokenizers/PHP/TypeIntersectionTest.inc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/* testBitwiseAnd1 */
88
$result = $value & $test /* testBitwiseAnd2 */ & $another;
99

10-
class TypeIntersection
10+
abstract class TypeIntersection
1111
{
1212
/* testTypeIntersectionOOConstSimple */
1313
public const Foo&Bar SIMPLE = new Foo();
@@ -81,6 +81,12 @@ class TypeIntersection
8181
/* testTypeIntersectionPropertyWithPublicProtectedSet */
8282
public protected(set) Foo&Bar $asym4;
8383

84+
/* testTypeIntersectionWithPHP84AbstractKeyword */
85+
abstract className&InterfaceName $abstractKeywordA { get; }
86+
87+
/* testTypeIntersectionWithPHP84AbstractKeywordFirst */
88+
abstract protected \className&InterfaceName $abstractKeywordB { set; }
89+
8490
public function paramTypes(
8591
/* testTypeIntersectionParam1 */
8692
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
@@ -130,6 +130,8 @@ public static function dataTypeIntersection()
130130
'type for asymmetric visibility (public private(set)) prop' => ['/* testTypeIntersectionPropertyWithPublicPrivateSet */'],
131131
'type for asymmetric visibility (protected(set)) property' => ['/* testTypeIntersectionPropertyWithProtectedSet */'],
132132
'type for asymmetric visibility (public protected(set)) prop' => ['/* testTypeIntersectionPropertyWithPublicProtectedSet */'],
133+
'type for abstract property' => ['/* testTypeIntersectionWithPHP84AbstractKeyword */'],
134+
'type for abstract property reversed modifier order' => ['/* testTypeIntersectionWithPHP84AbstractKeywordFirst */'],
133135
'type for method parameter' => ['/* testTypeIntersectionParam1 */'],
134136
'type for method parameter, first in multi-intersect' => ['/* testTypeIntersectionParam2 */'],
135137
'type for method parameter, last in multi-intersect' => ['/* testTypeIntersectionParam3 */'],

0 commit comments

Comments
 (0)