@@ -93,7 +93,7 @@ public function getFlags()
93
93
*/
94
94
public function attach ($ enum )
95
95
{
96
- $ this ->initEnum ($ enum );
96
+ $ enum = $ this ->initEnum ($ enum );
97
97
$ ordinal = $ enum ->getOrdinal ();
98
98
99
99
if (!($ this ->flags & self ::UNIQUE ) || !in_array ($ ordinal , $ this ->list , true )) {
@@ -112,7 +112,7 @@ public function attach($enum)
112
112
*/
113
113
public function contains ($ enum )
114
114
{
115
- $ this ->initEnum ($ enum );
115
+ $ enum = $ this ->initEnum ($ enum );
116
116
return in_array ($ enum ->getOrdinal (), $ this ->list , true );
117
117
}
118
118
@@ -124,7 +124,7 @@ public function contains($enum)
124
124
*/
125
125
public function detach ($ enum )
126
126
{
127
- $ this ->initEnum ($ enum );
127
+ $ enum = $ this ->initEnum ($ enum );
128
128
129
129
while (($ index = array_search ($ enum ->getOrdinal (), $ this ->list , true )) !== false ) {
130
130
unset($ this ->list [$ index ]);
@@ -187,20 +187,19 @@ public function count()
187
187
* @return Enum
188
188
* @throws InvalidArgumentException On an invalid given enum
189
189
*/
190
- private function initEnum (& $ enum )
190
+ private function initEnum ($ enum )
191
191
{
192
192
// auto instantiate
193
193
if (is_scalar ($ enum )) {
194
194
$ enumClass = $ this ->enumClass ;
195
- $ enum = $ enumClass ::get ($ enum );
196
- return ;
195
+ return $ enumClass ::get ($ enum );
197
196
}
198
197
199
198
// allow only enums of the same type
200
199
// (don't allow instance of)
201
200
$ enumClass = get_class ($ enum );
202
201
if ($ enumClass && strcasecmp ($ enumClass , $ this ->enumClass ) === 0 ) {
203
- return ;
202
+ return $ enum ;
204
203
}
205
204
206
205
throw new InvalidArgumentException (sprintf (
0 commit comments