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

Set   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 30
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 8 2
A remove() 0 8 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