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

ImmutableSet   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 58.82 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 10 10 2
A remove() 10 10 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
namespace SpareParts\Enum\Set;
3
4
use SpareParts\Enum\Enum;
5
use SpareParts\Enum\Exception\EnumSetMustContainEnumsException;
6
7
class ImmutableSet implements ISet
8
{
9
    use SetTrait;
10
11
    /**
12
     * @param Enum $enum
13
     * @return self
14
     */
15 3 View Code Duplication
    public function add(Enum $enum)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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
        $set = $this->set;
21 2
        $set[(string) $enum] = $enum;
22
23 2
        return new ImmutableSet($this->enumClass, $set);
24
    }
25
26
    /**
27
     * @param Enum $enum
28
     * @return self
29
     */
30 5 View Code Duplication
    public function remove(Enum $enum)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
31
    {
32 4
        if (!($enum instanceof $this->enumClass)) {
33 1
            throw new EnumSetMustContainEnumsException(sprintf("Expected %s, got %s", $this->enumClass, get_class($enum)));
34
        }
35 3
        $set = $this->set;
36 5
        unset($set[(string) $enum]);
37
38 3
        return new ImmutableSet($this->enumClass, $set);
39
    }
40
}
41