1111
1212namespace PHPCfg ;
1313
14+ use RuntimeException ;
15+
1416class Assertion
1517{
1618 public const MODE_NONE = 0 ;
@@ -19,41 +21,49 @@ class Assertion
1921
2022 public const MODE_INTERSECTION = 2 ;
2123
22- public $ mode = self :: MODE_NONE ;
24+ public readonly int $ mode ;
2325
2426 /**
2527 * @var Assertion[]|Operand
2628 */
27- public $ value ;
29+ public readonly array | Operand $ value ;
2830
29- /**
30- * @param Assertion[]|Operand $value
31- */
32- public function __construct ($ value , $ mode = self ::MODE_NONE )
31+ public function __construct (array |Operand $ value , $ mode = self ::MODE_NONE )
3332 {
3433 if (empty ($ value )) {
35- throw new \ RuntimeException ('Empty value supplied for Assertion ' );
34+ throw new RuntimeException ('Empty value supplied for Assertion ' );
3635 }
3736 if (is_array ($ value )) {
3837 foreach ($ value as $ v ) {
3938 if (! $ v instanceof self) {
40- throw new \ RuntimeException ('Invalid array key supplied for Assertion ' );
39+ throw new RuntimeException ('Invalid array key supplied for Assertion ' );
4140 }
4241 }
4342 if ($ mode !== self ::MODE_UNION && $ mode !== self ::MODE_INTERSECTION ) {
44- throw new \ RuntimeException ('Invalid mode supplied for Assertion ' );
43+ throw new RuntimeException ('Invalid mode supplied for Assertion ' );
4544 }
46- $ this ->mode = $ mode ;
47- } elseif (! $ value instanceof Operand) {
48- throw new \RuntimeException ('Invalid value supplied for Assertion: ' );
45+ $ this ->setMode ($ mode );
4946 } else {
50- $ this ->mode = self ::MODE_NONE ;
47+ $ this ->setMode ( self ::MODE_NONE ) ;
5148 }
5249 $ this ->value = $ value ;
5350 }
5451
55- public function getKind ()
52+ public function getKind (): string
5653 {
5754 return '' ;
5855 }
56+
57+ protected function setMode (int $ mode ): void
58+ {
59+ switch ($ mode ) {
60+ case self ::MODE_NONE :
61+ case self ::MODE_UNION :
62+ case self ::MODE_INTERSECTION :
63+ break ;
64+ default :
65+ throw new RuntimeException ("Invalid mode supplied for Assertion " );
66+ }
67+ $ this ->mode = $ mode ;
68+ }
5969}
0 commit comments