Skip to content

Commit 187e5dc

Browse files
committed
PHP 8.1 | Squiz/ScopeKeywordSpacing: allow for readonly keyword
Includes tests.
1 parent 67c82d9 commit 187e5dc

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

src/Standards/Squiz/Sniffs/WhiteSpace/ScopeKeywordSpacingSniff.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public function register()
2626
{
2727
$register = Tokens::$scopeModifiers;
2828
$register[] = T_STATIC;
29+
$register[] = T_READONLY;
2930
return $register;
3031

3132
}//end register()

src/Standards/Squiz/Tests/WhiteSpace/ScopeKeywordSpacingUnitTest.inc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,16 @@ class ConstructorPropertyPromotionTest {
126126
class ConstructorPropertyPromotionWithTypesTest {
127127
public function __construct(protected float|int $x, public?string &$y = 'test', private mixed $z) {}
128128
}
129+
130+
// PHP 8.1 readonly keywords.
131+
class ReadonlyTest {
132+
public readonly int $publicReadonlyProperty;
133+
134+
protected readonly int $protectedReadonlyProperty;
135+
136+
readonly protected int $protectedReadonlyProperty;
137+
138+
readonly private int $privateReadonlyProperty;
139+
140+
public function __construct(readonly protected float|int $x, public readonly?string &$y = 'test') {}
141+
}

src/Standards/Squiz/Tests/WhiteSpace/ScopeKeywordSpacingUnitTest.inc.fixed

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,16 @@ class ConstructorPropertyPromotionTest {
120120
class ConstructorPropertyPromotionWithTypesTest {
121121
public function __construct(protected float|int $x, public ?string &$y = 'test', private mixed $z) {}
122122
}
123+
124+
// PHP 8.1 readonly keywords.
125+
class ReadonlyTest {
126+
public readonly int $publicReadonlyProperty;
127+
128+
protected readonly int $protectedReadonlyProperty;
129+
130+
readonly protected int $protectedReadonlyProperty;
131+
132+
readonly private int $privateReadonlyProperty;
133+
134+
public function __construct(readonly protected float|int $x, public readonly ?string &$y = 'test') {}
135+
}

src/Standards/Squiz/Tests/WhiteSpace/ScopeKeywordSpacingUnitTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ public function getErrorList()
4444
119 => 1,
4545
121 => 1,
4646
127 => 2,
47+
134 => 2,
48+
138 => 2,
49+
140 => 3,
4750
];
4851

4952
}//end getErrorList()

0 commit comments

Comments
 (0)