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 ( db3255...800171 )
by Jasper
14:47
created

Vector::map()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 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
    public function __construct(array $values = [])
20
    {
21
        foreach ($values as $value) {
22
            $this->guardAgainstInvalidValue($value);
23
            $this->items[] = $value;
24
        }
25
    }
26
27 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
        $items = [];
30
31
        foreach ($this->items as $item) {
32
            if (is_object($item)) {
33
                $items[] = clone $item;
34
            } else {
35
                $items[] = $item;
36
            }
37
        }
38
39
        $this->items = $items;
40
    }
41
42
    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
        if (!isset($this->items[$index])) {
45
            throw OutOfRangeException::indexOutOfRange($index);
46
        }
47
48
        return $this->items[$index];
49
    }
50
51 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
        foreach ($this->items as $index => $item) {
54
            if ($this->theseAreEqual($item, $value)) {
55
                return $index;
56
            }
57
        }
58
59
        throw OutOfRangeException::valueOutOfRange($value);
60
    }
61
62
    public function equals($other): bool
63
    {
64
        if (!$other instanceof static) {
65
            return false;
66
        }
67
68
        if ($this->count() !== $other->count()) {
69
            return false;
70
        }
71
72
        foreach ($this->items as $item) {
73
            if ($this->countItem($item) !== $other->countItem($item)) {
74
                return false;
75
            }
76
        }
77
78
        return true;
79
    }
80
81
    public function add($value): self
82
    {
83
        $items = $this->items;
84
85
        $items[] = $value;
86
87
        return new self($items);
88
    }
89
90 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
        $items = $this->items;
93
        $index = $this->search($searchValue);
94
95
        $items[$index] = $replacementValue;
96
97
        return new self($items);
98
    }
99
100 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
        $items   = $this->items;
103
        $indexes = $this->searchAll($searchValue);
104
105
        if ($indexes->isEmpty()) {
106
            return $this;
107
        }
108
109
        foreach ($indexes as $index) {
110
            $items[$index] = $replacementValue;
111
        }
112
113
        return new self($items);
114
    }
115
116 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
        $items = $this->items;
119
        $index = $this->search($value);
120
121
        unset($items[$index]);
122
123
        return new self($items);
124
    }
125
126 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
        $items   = $this->items;
129
        $indexes = $this->searchAll($value);
130
131
        if ($indexes->isEmpty()) {
132
            return $this;
133
        }
134
135
        foreach ($indexes as $index) {
136
            unset($items[$index]);
137
        }
138
139
        return new self($items);
140
    }
141
142 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
        $items = [];
145
146
        foreach ($this->items as $item) {
147
            if ($other->contains($item)) {
148
                $items[] = $item;
149
            }
150
        }
151
152
        return new self($items);
153
    }
154
155 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
        $items = [];
158
159
        foreach ($this->items as $item) {
160
            if (!$other->contains($item)) {
161
                $items[] = $item;
162
            }
163
        }
164
165
        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
    public function filter(callable $filter): self
177
    {
178
        $items = array_filter($this->items, $filter);
179
180
        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
    public function map(callable $mapper): self
192
    {
193
        $items = array_map($mapper, $this->items);
194
195
        return new self($items);
196
    }
197
}
198