Completed
Branch master (adbf7c)
by Ondrej
08:25
created

Set::remove()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
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
    public function add(Enum $enum)
16
    {
17
        if (!($enum instanceof $this->enumClass)) {
18
            throw new EnumSetMustContainEnumsException(sprintf("Expected %s, got %s", $this->enumClass, get_class($enum)));
19
        }
20
        $this->set[(string) $enum] = $enum;
21
        return $this;
22
    }
23
24
    /**
25
     * @param Enum $enum
26
     * @return $this
27
     */
28
    public function remove(Enum $enum)
29
    {
30
        if (!($enum instanceof $this->enumClass)) {
31
            throw new EnumSetMustContainEnumsException(sprintf("Expected %s, got %s", $this->enumClass, get_class($enum)));
32
        }
33
        unset($this->set[(string) $enum]);
34
        return $this;
35
    }
36
}
37