Skip to content

Commit 022c1a1

Browse files
committed
PHP 8.4 | File::getMemberProperties(): add support for asymmetric visibility
Implements the suggested support per #851 (comment) with one difference: the `set_scope` key will always be available, but will be `false` if no set scope is specified. This is more in line with the other keys in the return array. Includes tests. Includes updated test expectation for the PSR2/PropertyDeclarationSniff. Mind: this sniff still needs further updates! Follow up on 871 Partial fix for 851 Related to 734
1 parent 30fdf53 commit 022c1a1

File tree

4 files changed

+286
-9
lines changed

4 files changed

+286
-9
lines changed

src/Files/File.php

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1827,6 +1827,9 @@ public function getMethodProperties($stackPtr)
18271827
* array(
18281828
* 'scope' => string, // Public, private, or protected.
18291829
* 'scope_specified' => boolean, // TRUE if the scope was explicitly specified.
1830+
* 'set_scope' => string|false, // Scope for asymmetric visibility.
1831+
* // Either public, private, or protected or
1832+
* // FALSE if no set scope is specified.
18301833
* 'is_static' => boolean, // TRUE if the static keyword was found.
18311834
* 'is_readonly' => boolean, // TRUE if the readonly keyword was found.
18321835
* 'is_final' => boolean, // TRUE if the final keyword was found.
@@ -1896,19 +1899,18 @@ public function getMemberProperties($stackPtr)
18961899
}
18971900

18981901
$valid = [
1899-
T_PUBLIC => T_PUBLIC,
1900-
T_PRIVATE => T_PRIVATE,
1901-
T_PROTECTED => T_PROTECTED,
1902-
T_STATIC => T_STATIC,
1903-
T_VAR => T_VAR,
1904-
T_READONLY => T_READONLY,
1905-
T_FINAL => T_FINAL,
1902+
T_STATIC => T_STATIC,
1903+
T_VAR => T_VAR,
1904+
T_READONLY => T_READONLY,
1905+
T_FINAL => T_FINAL,
19061906
];
19071907

1908+
$valid += Tokens::$scopeModifiers;
19081909
$valid += Tokens::$emptyTokens;
19091910

19101911
$scope = 'public';
19111912
$scopeSpecified = false;
1913+
$setScope = false;
19121914
$isStatic = false;
19131915
$isReadonly = false;
19141916
$isFinal = false;
@@ -1941,6 +1943,15 @@ public function getMemberProperties($stackPtr)
19411943
$scope = 'protected';
19421944
$scopeSpecified = true;
19431945
break;
1946+
case T_PUBLIC_SET:
1947+
$setScope = 'public';
1948+
break;
1949+
case T_PROTECTED_SET:
1950+
$setScope = 'protected';
1951+
break;
1952+
case T_PRIVATE_SET:
1953+
$setScope = 'private';
1954+
break;
19441955
case T_STATIC:
19451956
$isStatic = true;
19461957
break;
@@ -2004,6 +2015,7 @@ public function getMemberProperties($stackPtr)
20042015
return [
20052016
'scope' => $scope,
20062017
'scope_specified' => $scopeSpecified,
2018+
'set_scope' => $setScope,
20072019
'is_static' => $isStatic,
20082020
'is_readonly' => $isReadonly,
20092021
'is_final' => $isFinal,

src/Standards/PSR2/Tests/Classes/PropertyDeclarationUnitTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ public function getErrorList()
6464
101 => 2,
6565
105 => 1,
6666
107 => 1,
67-
109 => 1,
68-
111 => 1,
6967
];
7068

7169
}//end getErrorList()

tests/Core/Files/File/GetMemberPropertiesTest.inc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,3 +375,29 @@ class WithFinalProperties {
375375
/* testPHP84FinalComplexTypedProp */
376376
final public (Foo&\Bar)|bool $val9;
377377
}
378+
379+
class AsymVisibility {
380+
/* testPHP84AsymPublicSetProperty */
381+
public(set) mixed $prop1;
382+
/* testPHP84AsymPublicPublicSetProperty */
383+
public public(set) (A&B)|null $prop2;
384+
/* testPHP84AsymPublicSetPublicProperty */
385+
public(set) public bool $prop3;
386+
387+
/* testPHP84AsymProtectedSetProperty */
388+
protected(set) readonly mixed $prop4;
389+
/* testPHP84AsymPublicProtectedSetProperty */
390+
public protected(set) string $prop5;
391+
/* testPHP84AsymProtectedSetPublicProperty */
392+
protected(set) public ?float $prop6;
393+
394+
/* testPHP84AsymPrivateSetProperty */
395+
private(set) string|int $prop7;
396+
/* testPHP84AsymProtectedPrivateSetProperty */
397+
final protected private(set) $prop8;
398+
/* testPHP84AsymPrivateSetPublicProperty */
399+
private(set) public mixed $prop9;
400+
401+
/* testPHP84IllegalAsymPublicProtectedSetStaticProperty */
402+
public protected(set) static mixed $prop10;
403+
}

0 commit comments

Comments
 (0)