Code Duplication    Length = 19-19 lines in 4 locations

src/EnumSet.php 4 locations

@@ 248-266 (lines=19) @@
245
     * @param EnumSet $other,... Other EnumSet(s) of the same enumeration to produce the union
246
     * @return EnumSet
247
     */
248
    public function union(EnumSet $other)
249
    {
250
        $bitset = $this->bitset;
251
        foreach (func_get_args() as $other) {
252
            if ($this->enumeration !== $other->enumeration) {
253
                throw new InvalidArgumentException(sprintf(
254
                    "Others should be an %s of the same enumeration as this '%s'",
255
                    __CLASS__,
256
                    $this->enumeration
257
                ));
258
            }
259
260
            $bitset |= $other->bitset;
261
        }
262
263
        $clone = clone $this;
264
        $clone->bitset = $bitset;
265
        return $clone;
266
    }
267
268
    /**
269
     * Produce a new set with enumerators common to both this and other (this & other)
@@ 273-291 (lines=19) @@
270
     * @param EnumSet $other,... Other EnumSet(s) of the same enumeration to produce the union
271
     * @return EnumSet
272
     */
273
    public function intersect(EnumSet $other)
274
    {
275
        $bitset = $this->bitset;
276
        foreach (func_get_args() as $other) {
277
            if ($this->enumeration !== $other->enumeration) {
278
                throw new InvalidArgumentException(sprintf(
279
                    "Others should be an %s of the same enumeration as this '%s'",
280
                    __CLASS__,
281
                    $this->enumeration
282
                ));
283
            }
284
285
            $bitset &= $other->bitset;
286
        }
287
288
        $clone = clone $this;
289
        $clone->bitset = $bitset;
290
        return $clone;
291
    }
292
293
    /**
294
     * Produce a new set with enumerators in this but not in other (this - (other | other))
@@ 298-316 (lines=19) @@
295
     * @param EnumSet $other,... Other EnumSet(s) of the same enumeration to produce the union
296
     * @return EnumSet
297
     */
298
    public function diff(EnumSet $other)
299
    {
300
        $bitset = '';
301
        foreach (func_get_args() as $other) {
302
            if ($this->enumeration !== $other->enumeration) {
303
                throw new InvalidArgumentException(sprintf(
304
                    "Others should be an %s of the same enumeration as this '%s'",
305
                    __CLASS__,
306
                    $this->enumeration
307
                ));
308
            }
309
310
            $bitset |= $other->bitset;
311
        }
312
313
        $clone = clone $this;
314
        $clone->bitset = $this->bitset & ~$bitset;
315
        return $clone;
316
    }
317
318
    /**
319
     * Produce a new set with enumerators in either this and other but not in both (this ^ (other | other))
@@ 323-341 (lines=19) @@
320
     * @param EnumSet $other,... Other EnumSet(s) of the same enumeration to produce the union
321
     * @return EnumSet
322
     */
323
    public function symDiff(EnumSet $other)
324
    {
325
        $bitset = '';
326
        foreach (func_get_args() as $other) {
327
            if ($this->enumeration !== $other->enumeration) {
328
                throw new InvalidArgumentException(sprintf(
329
                    "Others should be an %s of the same enumeration as this '%s'",
330
                    __CLASS__,
331
                    $this->enumeration
332
                ));
333
            }
334
335
            $bitset |= $other->bitset;
336
        }
337
338
        $clone = clone $this;
339
        $clone->bitset = $this->bitset ^ $bitset;
340
        return $clone;
341
    }
342
343
    /**
344
     * Get ordinal numbers of the defined enumerators as array