@@ -67,7 +67,10 @@ public function offset() : array{
67
67
* Returns whether the direction is facing the positive of its axis.
68
68
*/
69
69
public function isPositive () : bool {
70
- return $ this === self ::UP || $ this === self ::SOUTH || $ this === self ::EAST ;
70
+ return match ($ this ){
71
+ self ::UP , self ::SOUTH , self ::EAST => true ,
72
+ self ::DOWN , self ::NORTH , self ::WEST => false ,
73
+ };
71
74
}
72
75
73
76
/**
@@ -96,24 +99,28 @@ public function rotate(Axis $axis, bool $clockwise) : Facing{
96
99
self ::EAST => self ::SOUTH ,
97
100
self ::SOUTH => self ::WEST ,
98
101
self ::WEST => self ::NORTH ,
99
- default => throw new \ InvalidArgumentException ( " Cannot rotate facing \"" . strtolower ( $ this -> name ) . "\" around axis \"" . strtolower ( $ axis -> name ) . "\"" )
102
+ default => null
100
103
},
101
104
Axis::Z => match ($ this ){
102
105
self ::UP => self ::EAST ,
103
106
self ::EAST => self ::DOWN ,
104
107
self ::DOWN => self ::WEST ,
105
108
self ::WEST => self ::UP ,
106
- default => throw new \ InvalidArgumentException ( " Cannot rotate facing \"" . strtolower ( $ this -> name ) . "\" around axis \"" . strtolower ( $ axis -> name ) . "\"" )
109
+ default => null
107
110
},
108
111
Axis::X => match ($ this ){
109
112
self ::UP => self ::NORTH ,
110
113
self ::NORTH => self ::DOWN ,
111
114
self ::DOWN => self ::SOUTH ,
112
115
self ::SOUTH => self ::UP ,
113
- default => throw new \ InvalidArgumentException ( " Cannot rotate facing \"" . strtolower ( $ this -> name ) . "\" around axis \"" . strtolower ( $ axis -> name ) . "\"" )
116
+ default => null
114
117
}
115
118
};
116
119
120
+ if ($ rotated === null ) {
121
+ throw new \InvalidArgumentException ("Cannot rotate facing \"" . strtolower ($ this ->name ) . "\" around axis \"" . strtolower ($ axis ->name ) . "\"" );
122
+ }
123
+
117
124
return $ clockwise ? $ rotated : $ rotated ->opposite ();
118
125
}
119
126
0 commit comments