Passed
Push — master ( 65b336...1323cd )
by Бабичев
44s
created

ResourceCollection   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 39
ccs 0
cts 11
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A only() 0 7 1
A except() 0 3 1
A names() 0 10 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 only(array $names): self
31
    {
32
        $this->data = \array_filter($this->data, function (string $needle) use ($names) {
33
            return \in_array($needle, $names, true);
34
        }, \ARRAY_FILTER_USE_KEY);
35
36
        return $this;
37
    }
38
39
    /**
40
     * @param array $names
41
     * @return ResourceCollection
42
     */
43
    public function except(array $names): self
44
    {
45
        return $this->only(\array_diff(\array_keys($this->data), $names));
46
    }
47
48
}
49