UnorderedList::withoutValue()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 13
Ratio 100 %

Code Coverage

Tests 7
CRAP Score 2
Metric Value
dl 13
loc 13
ccs 7
cts 7
cp 1
rs 9.4285
cc 2
eloc 7
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Equip\Structure;
4
5
use Equip\Structure\Traits\CanStructure;
6
7
class UnorderedList implements ListInterface
8
{
9
    use CanStructure;
10
11 3
    public function hasValue($value)
12
    {
13 3
        return in_array($value, $this->values, true);
14
    }
15
16 4 View Code Duplication
    public function withValues(array $values)
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...
17
    {
18 4
        $this->assertValid($values);
19
20 3
        if ($this->values === $values) {
21 1
            return $this;
22
        }
23
24 3
        $copy = clone $this;
25 3
        $copy->values = $values;
26
27 3
        return $copy;
28
    }
29
30 1 View Code Duplication
    public function withValue($value)
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 1
        $this->assertValid([$value]);
33
34 1
        $copy = clone $this;
35 1
        $copy->values[] = $value;
36
37 1
        return $copy;
38
    }
39
40 1 View Code Duplication
    public function withoutValue($value)
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...
41
    {
42 1
        $key = array_search($value, $this->values, true);
43
44 1
        if ($key === false) {
45 1
            return $this;
46
        }
47
48 1
        $copy = clone $this;
49 1
        unset($copy->values[$key]);
50
51 1
        return $copy;
52
    }
53
54 7
    protected function assertValid(array $values)
55
    {
56 7
        if (empty($values)) {
57 1
            return;
58
        }
59
60 7
        if ($values !== array_values($values)) {
61 1
            throw ValidationException::invalid(
62
                'List structures cannot have distinct keys'
63 1
            );
64
        }
65 7
    }
66
}
67