ResourceCollection::only()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 7
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Bavix\Router;
4
5
use Bavix\Iterator\Iterator;
6
7
class ResourceCollection extends Iterator
8
{
9
10
    /**
11
     * @param array $names
12
     * @return ResourceCollection
13
     */
14
    public function names(array $names): self
15
    {
16
        foreach ($names as $key => $name) {
17
            /**
18
             * @var Pattern $item
19
             */
20
            $item = $this->data[$key];
21
            $item->setName($name);
22
        }
23
        return $this;
24
    }
25
26
    /**
27
     * @param array $names
28
     * @return ResourceCollection
29
     */
30
    public function except(array $names): self
31
    {
32
        return $this->only(\array_diff(\array_keys($this->data), $names));
33
    }
34
35
    /**
36
     * @param array $names
37
     * @return ResourceCollection
38
     */
39
    public function only(array $names): self
40
    {
41
        $this->data = \array_filter($this->data, function (string $needle) use ($names) {
42
            return \in_array($needle, $names, true);
43
        }, \ARRAY_FILTER_USE_KEY);
44
45
        return $this;
46
    }
47
48
}
49