Completed
Pull Request — master (#7)
by Ondrej
05:55
created

Set::remove()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
ccs 5
cts 5
cp 1
cc 2
eloc 5
nc 2
nop 1
crap 2
1
<?php
2
namespace SpareParts\Enum\Set;
3
4
use SpareParts\Enum\Enum;
5
use SpareParts\Enum\Exception\EnumSetMustContainEnumsException;
6
7
class Set implements ISet
8
{
9
    use SetTrait;
10
11
    /**
12
     * @param Enum $enum
13
     * @return $this
14
     */
15 3
    public function add(Enum $enum)
16
    {
17 3
        if (!($enum instanceof $this->enumClass)) {
18 1
            throw new EnumSetMustContainEnumsException(sprintf("Expected %s, got %s", $this->enumClass, get_class($enum)));
19
        }
20 2
        $this->set[(string) $enum] = $enum;
21 2
        return $this;
22
    }
23
24
    /**
25
     * @param Enum $enum
26
     * @return $this
27
     */
28 4
    public function remove(Enum $enum)
29
    {
30 4
        if (!($enum instanceof $this->enumClass)) {
31 1
            throw new EnumSetMustContainEnumsException(sprintf("Expected %s, got %s", $this->enumClass, get_class($enum)));
32
        }
33 3
        unset($this->set[(string) $enum]);
34 3
        return $this;
35
    }
36
}
37