Skip to content

Commit 18807f2

Browse files
committed
Merge branch 'master' into 4.x
2 parents 87f19e9 + f34a543 commit 18807f2

File tree

6 files changed

+457
-30
lines changed

6 files changed

+457
-30
lines changed

src/Files/File.php

Lines changed: 58 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,6 +1402,10 @@ public function getDeclarationName($stackPtr)
14021402
* 'readonly_token' => integer, // The stack pointer to the readonly modifier token.
14031403
* // This index will only be set if the property is readonly.
14041404
*
1405+
* ... and if the promoted property uses asymmetric visibility, these additional array indexes will also be available:
1406+
* 'set_visibility' => string, // The property set-visibility as declared.
1407+
* 'set_visibility_token' => integer, // The stack pointer to the set-visibility modifier token.
1408+
*
14051409
* @param int $stackPtr The position in the stack of the function token
14061410
* to acquire the parameters for.
14071411
*
@@ -1453,10 +1457,11 @@ public function getMethodParameters($stackPtr)
14531457
$variadicToken = false;
14541458
$typeHint = '';
14551459
$typeHintToken = false;
1456-
$typeHintEndToken = false;
1457-
$nullableType = false;
1458-
$visibilityToken = null;
1459-
$readonlyToken = null;
1460+
$typeHintEndToken = false;
1461+
$nullableType = false;
1462+
$visibilityToken = null;
1463+
$setVisibilityToken = null;
1464+
$readonlyToken = null;
14601465

14611466
for ($i = $paramStart; $i <= $closer; $i++) {
14621467
// Check to see if this token has a parenthesis or bracket opener. If it does
@@ -1591,6 +1596,13 @@ public function getMethodParameters($stackPtr)
15911596
$visibilityToken = $i;
15921597
}
15931598
break;
1599+
case T_PUBLIC_SET:
1600+
case T_PROTECTED_SET:
1601+
case T_PRIVATE_SET:
1602+
if ($defaultStart === null) {
1603+
$setVisibilityToken = $i;
1604+
}
1605+
break;
15941606
case T_READONLY:
15951607
if ($defaultStart === null) {
15961608
$readonlyToken = $i;
@@ -1625,16 +1637,21 @@ public function getMethodParameters($stackPtr)
16251637
$vars[$paramCount]['type_hint_end_token'] = $typeHintEndToken;
16261638
$vars[$paramCount]['nullable_type'] = $nullableType;
16271639

1628-
if ($visibilityToken !== null || $readonlyToken !== null) {
1640+
if ($visibilityToken !== null || $setVisibilityToken !== null || $readonlyToken !== null) {
16291641
$vars[$paramCount]['property_visibility'] = 'public';
16301642
$vars[$paramCount]['visibility_token'] = false;
1631-
$vars[$paramCount]['property_readonly'] = false;
16321643

16331644
if ($visibilityToken !== null) {
16341645
$vars[$paramCount]['property_visibility'] = $this->tokens[$visibilityToken]['content'];
16351646
$vars[$paramCount]['visibility_token'] = $visibilityToken;
16361647
}
16371648

1649+
if ($setVisibilityToken !== null) {
1650+
$vars[$paramCount]['set_visibility'] = $this->tokens[$setVisibilityToken]['content'];
1651+
$vars[$paramCount]['set_visibility_token'] = $setVisibilityToken;
1652+
}
1653+
1654+
$vars[$paramCount]['property_readonly'] = false;
16381655
if ($readonlyToken !== null) {
16391656
$vars[$paramCount]['property_readonly'] = true;
16401657
$vars[$paramCount]['readonly_token'] = $readonlyToken;
@@ -1648,21 +1665,22 @@ public function getMethodParameters($stackPtr)
16481665
}
16491666

16501667
// Reset the vars, as we are about to process the next parameter.
1651-
$currVar = null;
1652-
$paramStart = ($i + 1);
1653-
$defaultStart = null;
1654-
$equalToken = null;
1655-
$hasAttributes = false;
1656-
$passByReference = false;
1657-
$referenceToken = false;
1658-
$variableLength = false;
1659-
$variadicToken = false;
1660-
$typeHint = '';
1661-
$typeHintToken = false;
1662-
$typeHintEndToken = false;
1663-
$nullableType = false;
1664-
$visibilityToken = null;
1665-
$readonlyToken = null;
1668+
$currVar = null;
1669+
$paramStart = ($i + 1);
1670+
$defaultStart = null;
1671+
$equalToken = null;
1672+
$hasAttributes = false;
1673+
$passByReference = false;
1674+
$referenceToken = false;
1675+
$variableLength = false;
1676+
$variadicToken = false;
1677+
$typeHint = '';
1678+
$typeHintToken = false;
1679+
$typeHintEndToken = false;
1680+
$nullableType = false;
1681+
$visibilityToken = null;
1682+
$setVisibilityToken = null;
1683+
$readonlyToken = null;
16661684

16671685
$paramCount++;
16681686
break;
@@ -1870,6 +1888,9 @@ public function getMethodProperties($stackPtr)
18701888
* array(
18711889
* 'scope' => string, // Public, private, or protected.
18721890
* 'scope_specified' => boolean, // TRUE if the scope was explicitly specified.
1891+
* 'set_scope' => string|false, // Scope for asymmetric visibility.
1892+
* // Either public, private, or protected or
1893+
* // FALSE if no set scope is specified.
18731894
* 'is_static' => boolean, // TRUE if the static keyword was found.
18741895
* 'is_readonly' => boolean, // TRUE if the readonly keyword was found.
18751896
* 'is_final' => boolean, // TRUE if the final keyword was found.
@@ -1920,19 +1941,18 @@ public function getMemberProperties($stackPtr)
19201941
}
19211942

19221943
$valid = [
1923-
T_PUBLIC => T_PUBLIC,
1924-
T_PRIVATE => T_PRIVATE,
1925-
T_PROTECTED => T_PROTECTED,
1926-
T_STATIC => T_STATIC,
1927-
T_VAR => T_VAR,
1928-
T_READONLY => T_READONLY,
1929-
T_FINAL => T_FINAL,
1944+
T_STATIC => T_STATIC,
1945+
T_VAR => T_VAR,
1946+
T_READONLY => T_READONLY,
1947+
T_FINAL => T_FINAL,
19301948
];
19311949

1950+
$valid += Tokens::SCOPE_MODIFIERS;
19321951
$valid += Tokens::EMPTY_TOKENS;
19331952

19341953
$scope = 'public';
19351954
$scopeSpecified = false;
1955+
$setScope = false;
19361956
$isStatic = false;
19371957
$isReadonly = false;
19381958
$isFinal = false;
@@ -1965,6 +1985,15 @@ public function getMemberProperties($stackPtr)
19651985
$scope = 'protected';
19661986
$scopeSpecified = true;
19671987
break;
1988+
case T_PUBLIC_SET:
1989+
$setScope = 'public';
1990+
break;
1991+
case T_PROTECTED_SET:
1992+
$setScope = 'protected';
1993+
break;
1994+
case T_PRIVATE_SET:
1995+
$setScope = 'private';
1996+
break;
19681997
case T_STATIC:
19691998
$isStatic = true;
19701999
break;
@@ -2026,6 +2055,7 @@ public function getMemberProperties($stackPtr)
20262055
return [
20272056
'scope' => $scope,
20282057
'scope_specified' => $scopeSpecified,
2058+
'set_scope' => $setScope,
20292059
'is_static' => $isStatic,
20302060
'is_readonly' => $isReadonly,
20312061
'is_final' => $isFinal,

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ public function getErrorList($testFile='')
6868
106 => 2,
6969
110 => 1,
7070
112 => 1,
71-
114 => 1,
72-
116 => 1,
7371
];
7472

7573
default:

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)