Collection::offsetUnset()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace TomPHP\HalClient\Resource;
4
5
use Assert\Assertion;
6
use TomPHP\HalClient\Exception\MutabilityException;
7
8
trait Collection
9
{
10
    /** @var Matchable[] */
11
    protected $items;
12
13
    /** @var Matchable[] */
14
    public function __construct(array $items)
15
    {
16
        Assertion::allIsInstanceOf($items, Matchable::class);
17
        $this->assertItemTypesAreCorrect($items);
18
19
        $this->items = $items;
20
    }
21
22
    /**
23
     * @param array $criteria
24
     *
25
     * @return static
26
     */
27
    public function findMatching(array $criteria)
28
    {
29
        return new static(array_values(array_filter(
30
            $this->items,
31
            function (Matchable $node) use ($criteria) {
32
                return $node->matches($criteria);
33
            }
34
        )));
35
    }
36
37
    /**
38
     * @return bool
39
     */
40
    public function offsetExists($offset)
41
    {
42
        return isset($this->items[$offset]);
43
    }
44
45
    /**
46
     * @return Matchable
47
     */
48
    public function offsetGet($offset)
49
    {
50
        return $this->items[$offset];
51
    }
52
53
    /**
54
     * @throws MutabilityException
55
     */
56
    public function offsetSet($offset, $value)
0 ignored issues
show
Unused Code introduced by
The parameter $offset is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $value is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
57
    {
58
        throw new MutabilityException();
59
    }
60
61
    /**
62
     * @throws MutabilityException
63
     */
64
    public function offsetUnset($offset)
0 ignored issues
show
Unused Code introduced by
The parameter $offset is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
65
    {
66
        throw new MutabilityException();
67
    }
68
69
    public function count()
70
    {
71
        return count($this->items);
72
    }
73
74
    public function matches($criteria)
0 ignored issues
show
Unused Code introduced by
The parameter $criteria is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
75
    {
76
        return false;
77
    }
78
79
    abstract protected function assertItemTypesAreCorrect(array $items);
0 ignored issues
show
Documentation introduced by
For interfaces and abstract methods it is generally a good practice to add a @return annotation even if it is just @return void or @return null, so that implementors know what to do in the overridden method.

For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a @return doc comment to communicate to implementors of these methods what they are expected to return.

Loading history...
80
}
81