@@ -155,8 +155,7 @@ public function getFlags()
155
155
*/
156
156
public function attach ($ enum , $ data = null )
157
157
{
158
- $ this ->initEnum ($ enum );
159
- parent ::attach ($ enum , $ data );
158
+ parent ::attach ($ this ->initEnum ($ enum ), $ data );
160
159
}
161
160
162
161
/**
@@ -167,8 +166,7 @@ public function attach($enum, $data = null)
167
166
public function contains ($ enum )
168
167
{
169
168
try {
170
- $ this ->initEnum ($ enum );
171
- return parent ::contains ($ enum );
169
+ return parent ::contains ($ this ->initEnum ($ enum ));
172
170
} catch (InvalidArgumentException $ e ) {
173
171
// On an InvalidArgumentException the given argument can't be contained in this map
174
172
return false ;
@@ -183,8 +181,7 @@ public function contains($enum)
183
181
*/
184
182
public function detach ($ enum )
185
183
{
186
- $ this ->initEnum ($ enum );
187
- parent ::detach ($ enum );
184
+ parent ::detach ($ this ->initEnum ($ enum ));
188
185
}
189
186
190
187
/**
@@ -195,10 +192,8 @@ public function detach($enum)
195
192
*/
196
193
public function getHash ($ enum )
197
194
{
198
- $ this ->initEnum ($ enum );
199
-
200
195
// getHash is available since PHP 5.4
201
- return spl_object_hash ($ enum );
196
+ return spl_object_hash ($ this -> initEnum ( $ enum) );
202
197
}
203
198
204
199
/**
@@ -220,8 +215,7 @@ public function offsetExists($enum)
220
215
*/
221
216
public function offsetGet ($ enum )
222
217
{
223
- $ this ->initEnum ($ enum );
224
- return parent ::offsetGet ($ enum );
218
+ return parent ::offsetGet ($ this ->initEnum ($ enum ));
225
219
}
226
220
227
221
/**
@@ -234,8 +228,7 @@ public function offsetGet($enum)
234
228
*/
235
229
public function offsetSet ($ enum , $ data = null )
236
230
{
237
- $ this ->initEnum ($ enum );
238
- parent ::offsetSet ($ enum , $ data );
231
+ parent ::offsetSet ($ this ->initEnum ($ enum ), $ data );
239
232
}
240
233
241
234
/**
@@ -247,8 +240,7 @@ public function offsetSet($enum, $data = null)
247
240
*/
248
241
public function offsetUnset ($ enum )
249
242
{
250
- $ this ->initEnum ($ enum );
251
- parent ::offsetUnset ($ enum );
243
+ parent ::offsetUnset ($ this ->initEnum ($ enum ));
252
244
}
253
245
254
246
/**
@@ -301,20 +293,19 @@ public function key()
301
293
* @return Enum
302
294
* @throws InvalidArgumentException On an invalid given enum
303
295
*/
304
- private function initEnum (& $ enum )
296
+ private function initEnum ($ enum )
305
297
{
306
298
// auto instantiate
307
299
if (is_scalar ($ enum )) {
308
300
$ enumClass = $ this ->enumClass ;
309
- $ enum = $ enumClass ::get ($ enum );
310
- return ;
301
+ return $ enumClass ::get ($ enum );
311
302
}
312
303
313
304
// allow only enums of the same type
314
305
// (don't allow instance of)
315
306
$ enumClass = get_class ($ enum );
316
307
if ($ enumClass && strcasecmp ($ enumClass , $ this ->enumClass ) === 0 ) {
317
- return ;
308
+ return $ enum ;
318
309
}
319
310
320
311
throw new InvalidArgumentException (sprintf (
0 commit comments