@@ -99,9 +99,9 @@ public function getCases(): array
99
99
100
100
101
101
/** 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
103
103
{
104
- if (isset ($ this ->cases [$ name ])) {
104
+ if (! $ overwrite && isset ($ this ->cases [$ name ])) {
105
105
throw new Nette \InvalidStateException ("Cannot add cases ' $ name', because it already exists. " );
106
106
}
107
107
return $ this ->cases [$ name ] = (new EnumCase ($ name ))
@@ -116,7 +116,7 @@ public function removeCase(string $name): static
116
116
}
117
117
118
118
119
- public function addMember (Method |Constant |EnumCase |TraitUse $ member ): static
119
+ public function addMember (Method |Constant |EnumCase |TraitUse $ member, bool $ overwrite = false ): static
120
120
{
121
121
$ name = $ member ->getName ();
122
122
[$ type , $ n ] = match (true ) {
@@ -125,7 +125,7 @@ public function addMember(Method|Constant|EnumCase|TraitUse $member): static
125
125
$ member instanceof TraitUse => ['traits ' , $ name ],
126
126
$ member instanceof EnumCase => ['cases ' , $ name ],
127
127
};
128
- if (isset ($ this ->$ type [$ n ])) {
128
+ if (! $ overwrite && isset ($ this ->$ type [$ n ])) {
129
129
throw new Nette \InvalidStateException ("Cannot add member ' $ name', because it already exists. " );
130
130
}
131
131
$ this ->$ type [$ n ] = $ member ;
0 commit comments