@@ -99,9 +99,9 @@ public function getCases(): array
9999
100100
101101 /** Adds case to enum */
102- public function addCase (string $ name , string |int |Literal |null $ value = null ): EnumCase
102+ public function addCase (string $ name , string |int |Literal |null $ value = null , bool $ overwrite = false ): EnumCase
103103 {
104- if (isset ($ this ->cases [$ name ])) {
104+ if (! $ overwrite && isset ($ this ->cases [$ name ])) {
105105 throw new Nette \InvalidStateException ("Cannot add cases ' $ name', because it already exists. " );
106106 }
107107 return $ this ->cases [$ name ] = (new EnumCase ($ name ))
@@ -116,7 +116,7 @@ public function removeCase(string $name): static
116116 }
117117
118118
119- public function addMember (Method |Constant |EnumCase |TraitUse $ member ): static
119+ public function addMember (Method |Constant |EnumCase |TraitUse $ member, bool $ overwrite = false ): static
120120 {
121121 $ name = $ member ->getName ();
122122 [$ type , $ n ] = match (true ) {
@@ -125,7 +125,7 @@ public function addMember(Method|Constant|EnumCase|TraitUse $member): static
125125 $ member instanceof TraitUse => ['traits ' , $ name ],
126126 $ member instanceof EnumCase => ['cases ' , $ name ],
127127 };
128- if (isset ($ this ->$ type [$ n ])) {
128+ if (! $ overwrite && isset ($ this ->$ type [$ n ])) {
129129 throw new Nette \InvalidStateException ("Cannot add member ' $ name', because it already exists. " );
130130 }
131131 $ this ->$ type [$ n ] = $ member ;
0 commit comments