@@ -41,24 +41,31 @@ public function __construct(
4141 string $ namespace ,
4242 string $ name ,
4343 array $ arguments = [],
44- DerivingSet $ derivings = null ,
44+ array $ derivings = [] ,
4545 string $ messageName = null
4646 ) {
4747 if (empty ($ name )) {
4848 throw new \InvalidArgumentException ('Name cannot be empty string ' );
4949 }
5050
51- if ($ type ->is (Type::DATA ()) && null !== $ messageName ) {
51+ if ($ type ->sameAs (new Data ())
52+ && null !== $ messageName
53+ ) {
5254 throw new \InvalidArgumentException ('Message name cannot be passed to data type ' );
53- } elseif (! $ type ->is (Type::DATA ()) && empty ($ messageName )) {
55+ } elseif (! $ type ->sameAs (new Data ())
56+ && ! $ type ->sameAs (new Enum ())
57+ && empty ($ messageName )
58+ ) {
5459 throw new \InvalidArgumentException ('Message name cannot be empty string ' );
5560 }
5661
57- if (null === $ derivings ) {
58- $ derivings = new DerivingSet ( );
62+ if ($ type -> sameAs ( new Enum ()) && empty ( $ arguments ) ) {
63+ throw new \ InvalidArgumentException ( ' Enums need at least one implementation ' );
5964 }
6065
61- if (count ($ arguments ) > 1 && $ derivings ->contains (Deriving::STRING_CONVERTER ())) {
66+ if (count ($ arguments ) > 1
67+ && in_array ((new StringConverter )->value (), $ derivings )
68+ ) {
6269 throw new \InvalidArgumentException (sprintf (
6370 'Cannot derive from StringConverter using more than one argument for %s \\%s ' ,
6471 $ namespace ,
@@ -77,10 +84,15 @@ public function __construct(
7784 if ($ argument ->name () === $ name ) {
7885 throw new \InvalidArgumentException ('Argument name is not allowed to be same as object name ' );
7986 }
87+ if ($ argument ->typehint () !== null
88+ && $ type ->sameAs (new Enum ())
89+ ) {
90+ throw new \InvalidArgumentException ('Argument typehint is not allowed for enums ' );
91+ }
8092 $ this ->arguments [] = $ argument ;
8193 }
8294
83- $ this ->derivings = $ derivings ;
95+ $ this ->derivings = array_unique ( $ derivings) ;
8496 $ this ->messageName = $ messageName ;
8597 }
8698
@@ -116,7 +128,7 @@ public function arguments(): array
116128 return $ this ->arguments ;
117129 }
118130
119- public function derivings (): DerivingSet
131+ public function derivings (): array
120132 {
121133 return $ this ->derivings ;
122134 }
0 commit comments