GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( f54279...375002 )
by Jasper
01:45
created

Vector::containsIndex()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
/**
4
 * @license https://github.com/f500/equatable/blob/master/LICENSE MIT
5
 */
6
7
declare(strict_types=1);
8
9
namespace F500\Equatable;
10
11
use F500\Equatable\Exceptions\OutOfRangeException;
12
13
/**
14
 * @copyright Copyright (c) 2015 Future500 B.V.
15
 * @author    Jasper N. Brouwer <[email protected]>
16
 */
17
final class Vector extends Collection
18
{
19 267
    public function __construct(array $values = [])
20
    {
21 267
        foreach ($values as $value) {
22 234
            $this->guardAgainstInvalidValue($value);
23 231
            $this->items[] = $value;
24
        }
25 264
    }
26
27 3 View Code Duplication
    public function __clone()
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...
28
    {
29 3
        $items = [];
30
31 3
        foreach ($this->items as $item) {
32 3
            if (is_object($item)) {
33 3
                $items[] = clone $item;
34
            } else {
35 3
                $items[] = $item;
36
            }
37
        }
38
39 3
        $this->items = $items;
40 3
    }
41
42 78
    public function get(int $index)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
43
    {
44 78
        if (!$this->containsIndex($index)) {
45 3
            throw OutOfRangeException::doesNotContainIndex($index);
46
        }
47
48 75
        return $this->items[$index];
49
    }
50
51 66 View Code Duplication
    public function search($value): int
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...
52
    {
53 66
        foreach ($this->items as $index => $item) {
54 63
            if ($this->theseAreEqual($item, $value)) {
55 63
                return $index;
56
            }
57
        }
58
59 33
        throw OutOfRangeException::doesNotContainValue($value);
60
    }
61
62 60
    public function equals($other): bool
63
    {
64 60
        if (!$other instanceof static) {
65 3
            return false;
66
        }
67
68 57
        if ($this->count() !== $other->count()) {
69 6
            return false;
70
        }
71
72 51
        foreach ($this->items as $item) {
73 42
            if ($this->countItem($item) !== $other->countItem($item)) {
74 42
                return false;
75
            }
76
        }
77
78 39
        return true;
79
    }
80
81 9
    public function add($value): self
82
    {
83 9
        $items = $this->items;
84
85 9
        $items[] = $value;
86
87 9
        return new self($items);
88
    }
89
90 12 View Code Duplication
    public function replace($searchValue, $replacementValue): self
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...
91
    {
92 12
        $items = $this->items;
93 12
        $index = $this->search($searchValue);
94
95 9
        $items[$index] = $replacementValue;
96
97 9
        return new self($items);
98
    }
99
100 12 View Code Duplication
    public function replaceAll($searchValue, $replacementValue): self
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...
101
    {
102 12
        $items   = $this->items;
103 12
        $indexes = $this->searchAll($searchValue);
104
105 12
        if ($indexes->isEmpty()) {
106 3
            return $this;
107
        }
108
109 9
        foreach ($indexes as $index) {
110 9
            $items[$index] = $replacementValue;
111
        }
112
113 9
        return new self($items);
114
    }
115
116 12 View Code Duplication
    public function remove($value): self
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...
117
    {
118 12
        $items = $this->items;
119 12
        $index = $this->search($value);
120
121 9
        unset($items[$index]);
122
123 9
        return new self($items);
124
    }
125
126 12 View Code Duplication
    public function removeAll($value): self
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...
127
    {
128 12
        $items   = $this->items;
129 12
        $indexes = $this->searchAll($value);
130
131 12
        if ($indexes->isEmpty()) {
132 3
            return $this;
133
        }
134
135 9
        foreach ($indexes as $index) {
136 9
            unset($items[$index]);
137
        }
138
139 9
        return new self($items);
140
    }
141
142 6 View Code Duplication
    public function intersect(self $other): self
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...
143
    {
144 6
        $items = [];
145
146 6
        foreach ($this->items as $item) {
147 6
            if ($other->contains($item)) {
148 6
                $items[] = $item;
149
            }
150
        }
151
152 6
        return new self($items);
153
    }
154
155 6 View Code Duplication
    public function diff(self $other): self
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...
156
    {
157 6
        $items = [];
158
159 6
        foreach ($this->items as $item) {
160 6
            if (!$other->contains($item)) {
161 6
                $items[] = $item;
162
            }
163
        }
164
165 6
        return new self($items);
166
    }
167
168
    /**
169
     * The filter callable is given an item, and should return
170
     * a boolean indicating whether the item remains or not.
171
     *
172
     * function ($item): bool {
173
     *     return true;
174
     * }
175
     */
176 6
    public function filter(callable $filter): self
177
    {
178 6
        $items = array_filter($this->items, $filter);
179
180 6
        return new self($items);
181
    }
182
183
    /**
184
     * The mapper callable is given an item, and should return
185
     * a new value to use in it's place.
186
     *
187
     * function ($item) {
188
     *     return $item;
189
     * }
190
     */
191 6
    public function map(callable $mapper): self
192
    {
193 6
        $items = array_map($mapper, $this->items);
194
195 6
        return new self($items);
196
    }
197
198 78
    private function containsIndex(int $index): bool
199
    {
200 78
        return isset($this->items[$index]);
201
    }
202
}
203