@@ -14,8 +14,13 @@ final class Modifiers {
1414 public const ABSTRACT = 16 ;
1515 public const FINAL = 32 ;
1616 public const READONLY = 64 ;
17+ public const PUBLIC_SET = 128 ;
18+ public const PROTECTED_SET = 256 ;
19+ public const PRIVATE_SET = 512 ;
1720
18- public const VISIBILITY_MASK = 1 | 2 | 4 ;
21+ public const VISIBILITY_MASK = self ::PUBLIC | self ::PROTECTED | self ::PRIVATE ;
22+
23+ public const VISIBILITY_SET_MASK = self ::PUBLIC_SET | self ::PROTECTED_SET | self ::PRIVATE_SET ;
1924
2025 private const TO_STRING_MAP = [
2126 self ::PUBLIC => 'public ' ,
@@ -25,6 +30,9 @@ final class Modifiers {
2530 self ::ABSTRACT => 'abstract ' ,
2631 self ::FINAL => 'final ' ,
2732 self ::READONLY => 'readonly ' ,
33+ self ::PUBLIC_SET => 'public(set) ' ,
34+ self ::PROTECTED_SET => 'protected(set) ' ,
35+ self ::PRIVATE_SET => 'private(set) ' ,
2836 ];
2937
3038 public static function toString (int $ modifier ): string {
@@ -34,15 +42,19 @@ public static function toString(int $modifier): string {
3442 return self ::TO_STRING_MAP [$ modifier ];
3543 }
3644
45+ private static function isValidModifier (int $ modifier ): bool {
46+ $ isPow2 = ($ modifier & ($ modifier - 1 )) == 0 && $ modifier != 0 ;
47+ return $ isPow2 && $ modifier <= self ::PRIVATE_SET ;
48+ }
49+
3750 /**
3851 * @internal
3952 */
4053 public static function verifyClassModifier (int $ a , int $ b ): void {
41- foreach ([Modifiers::ABSTRACT , Modifiers::FINAL , Modifiers::READONLY ] as $ modifier ) {
42- if ($ a & $ modifier && $ b & $ modifier ) {
43- throw new Error (
44- 'Multiple ' . self ::toString ($ modifier ) . ' modifiers are not allowed ' );
45- }
54+ assert (self ::isValidModifier ($ b ));
55+ if (($ a & $ b ) != 0 ) {
56+ throw new Error (
57+ 'Multiple ' . self ::toString ($ b ) . ' modifiers are not allowed ' );
4658 }
4759
4860 if ($ a & 48 && $ b & 48 ) {
@@ -54,15 +66,16 @@ public static function verifyClassModifier(int $a, int $b): void {
5466 * @internal
5567 */
5668 public static function verifyModifier (int $ a , int $ b ): void {
57- if ($ a & Modifiers::VISIBILITY_MASK && $ b & Modifiers::VISIBILITY_MASK ) {
69+ assert (self ::isValidModifier ($ b ));
70+ if (($ a & Modifiers::VISIBILITY_MASK && $ b & Modifiers::VISIBILITY_MASK ) ||
71+ ($ a & Modifiers::VISIBILITY_SET_MASK && $ b & Modifiers::VISIBILITY_SET_MASK )
72+ ) {
5873 throw new Error ('Multiple access type modifiers are not allowed ' );
5974 }
6075
61- foreach ([Modifiers::ABSTRACT , Modifiers::STATIC , Modifiers::FINAL , Modifiers::READONLY ] as $ modifier ) {
62- if ($ a & $ modifier && $ b & $ modifier ) {
63- throw new Error (
64- 'Multiple ' . self ::toString ($ modifier ) . ' modifiers are not allowed ' );
65- }
76+ if (($ a & $ b ) != 0 ) {
77+ throw new Error (
78+ 'Multiple ' . self ::toString ($ b ) . ' modifiers are not allowed ' );
6679 }
6780
6881 if ($ a & 48 && $ b & 48 ) {
0 commit comments