ImmutableCollection::addItem()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
/*
3
 * This file is part of Graze DataStructure
4
 *
5
 * Copyright (c) 2014 Nature Delivered Ltd. <http://graze.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @see  http://github.com/graze/data-structure/blob/master/LICENSE
11
 * @link http://github.com/graze/data-structure
12
 */
13
14
namespace Graze\DataStructure\Collection;
15
16
use Graze\Sort;
17
18
class ImmutableCollection extends Collection
19
{
20
    /**
21
     * @param mixed[] $items
22
     */
23 16
    public function __construct(array $items = [])
24
    {
25 16
        parent::__construct([]);
26
27 16
        foreach ($items as $item) {
28 14
            $this->addItem($item);
29
        }
30 16
    }
31
32
    /**
33
     * @param mixed $value
34
     *
35
     * @return ImmutableCollection
36
     */
37 2
    public function add($value)
38
    {
39 2
        $items = $this->items;
40 2
        $items[] = $value;
41
42 2
        return new self($items);
43
    }
44
45
    /**
46
     * @param callable $fn
47
     *
48
     * @return ImmutableCollection
49
     */
50 1
    public function filter(callable $fn)
51
    {
52 1
        return new self(array_filter($this->items, $fn));
53
    }
54
55
    /**
56
     * @param callable $fn
57
     *
58
     * @return ImmutableCollection
59
     */
60 1
    public function sort(callable $fn)
61
    {
62 1
        $items = $this->items;
63 1
        usort($items, $fn);
64
65 1
        return new self($items);
66
    }
67
68
    /**
69
     * @param callable $fn
70
     * @param int      $order
71
     *
72
     * @return ImmutableCollection
73
     */
74 2
    public function sortOn(callable $fn, $order = Sort\ASC)
75
    {
76 2
        return new self(Sort\comparison($this->items, $fn, $order));
77
    }
78
79
    /**
80
     * @param mixed $value
81
     */
82 14
    protected function addItem($value)
83
    {
84 14
        parent::add($value);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (add() instead of addItem()). Are you sure this is correct? If so, you might want to change this to $this->add().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
85 14
    }
86
}
87