Skip to content

Commit 538b96a

Browse files
authored
Merge pull request #473 from PHPCSStandards/php-8.2/file-getmemberproperties-support-dnf
PHP 8.2 | File::getMemberProperties(): add support for DNF types
2 parents 583fd65 + 36b1bb5 commit 538b96a

File tree

3 files changed

+80
-11
lines changed

3 files changed

+80
-11
lines changed

src/Files/File.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1958,17 +1958,19 @@ public function getMemberProperties($stackPtr)
19581958
if ($i < $stackPtr) {
19591959
// We've found a type.
19601960
$valid = [
1961-
T_STRING => T_STRING,
1962-
T_CALLABLE => T_CALLABLE,
1963-
T_SELF => T_SELF,
1964-
T_PARENT => T_PARENT,
1965-
T_FALSE => T_FALSE,
1966-
T_TRUE => T_TRUE,
1967-
T_NULL => T_NULL,
1968-
T_NAMESPACE => T_NAMESPACE,
1969-
T_NS_SEPARATOR => T_NS_SEPARATOR,
1970-
T_TYPE_UNION => T_TYPE_UNION,
1971-
T_TYPE_INTERSECTION => T_TYPE_INTERSECTION,
1961+
T_STRING => T_STRING,
1962+
T_CALLABLE => T_CALLABLE,
1963+
T_SELF => T_SELF,
1964+
T_PARENT => T_PARENT,
1965+
T_FALSE => T_FALSE,
1966+
T_TRUE => T_TRUE,
1967+
T_NULL => T_NULL,
1968+
T_NAMESPACE => T_NAMESPACE,
1969+
T_NS_SEPARATOR => T_NS_SEPARATOR,
1970+
T_TYPE_UNION => T_TYPE_UNION,
1971+
T_TYPE_INTERSECTION => T_TYPE_INTERSECTION,
1972+
T_TYPE_OPEN_PARENTHESIS => T_TYPE_OPEN_PARENTHESIS,
1973+
T_TYPE_CLOSE_PARENTHESIS => T_TYPE_CLOSE_PARENTHESIS,
19721974
];
19731975

19741976
for ($i; $i < $stackPtr; $i++) {

tests/Core/File/GetMemberPropertiesTest.inc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,3 +339,18 @@ class WhitespaceAndCommentsInTypes {
339339
/* testIntersectionTypeWithWhitespaceAndComment */
340340
public \Foo /*comment*/ & Bar $hasWhitespaceAndComment;
341341
}
342+
343+
trait DNFTypes {
344+
/* testPHP82DNFTypeStatic */
345+
public static (Foo&\Bar)|bool $propA;
346+
347+
/* testPHP82DNFTypeReadonlyA */
348+
protected readonly float|(Partially\Qualified&Traversable) $propB;
349+
350+
/* testPHP82DNFTypeReadonlyB */
351+
private readonly (namespace\Foo&Bar)|string $propC;
352+
353+
/* testPHP82DNFTypeIllegalNullable */
354+
// Intentional fatal error - nullable operator cannot be combined with DNF.
355+
var ?(A&\Pck\B)|bool $propD;
356+
}

tests/Core/File/GetMemberPropertiesTest.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,6 +1075,58 @@ public static function dataGetMemberProperties()
10751075
],
10761076
],
10771077

1078+
'php8.2-dnf-with-static' => [
1079+
'identifier' => '/* testPHP82DNFTypeStatic */',
1080+
'expected' => [
1081+
'scope' => 'public',
1082+
'scope_specified' => true,
1083+
'is_static' => true,
1084+
'is_readonly' => false,
1085+
'type' => '(Foo&\Bar)|bool',
1086+
'type_token' => -9,
1087+
'type_end_token' => -2,
1088+
'nullable_type' => false,
1089+
],
1090+
],
1091+
'php8.2-dnf-with-readonly-1' => [
1092+
'identifier' => '/* testPHP82DNFTypeReadonlyA */',
1093+
'expected' => [
1094+
'scope' => 'protected',
1095+
'scope_specified' => true,
1096+
'is_static' => false,
1097+
'is_readonly' => true,
1098+
'type' => 'float|(Partially\Qualified&Traversable)',
1099+
'type_token' => -10,
1100+
'type_end_token' => -2,
1101+
'nullable_type' => false,
1102+
],
1103+
],
1104+
'php8.2-dnf-with-readonly-2' => [
1105+
'identifier' => '/* testPHP82DNFTypeReadonlyB */',
1106+
'expected' => [
1107+
'scope' => 'private',
1108+
'scope_specified' => true,
1109+
'is_static' => false,
1110+
'is_readonly' => true,
1111+
'type' => '(namespace\Foo&Bar)|string',
1112+
'type_token' => -10,
1113+
'type_end_token' => -2,
1114+
'nullable_type' => false,
1115+
],
1116+
],
1117+
'php8.2-dnf-with-illegal-nullable' => [
1118+
'identifier' => '/* testPHP82DNFTypeIllegalNullable */',
1119+
'expected' => [
1120+
'scope' => 'public',
1121+
'scope_specified' => false,
1122+
'is_static' => false,
1123+
'is_readonly' => false,
1124+
'type' => '?(A&\Pck\B)|bool',
1125+
'type_token' => -11,
1126+
'type_end_token' => -2,
1127+
'nullable_type' => true,
1128+
],
1129+
],
10781130
];
10791131

10801132
}//end dataGetMemberProperties()

0 commit comments

Comments
 (0)