Completed
Push — master ( 76bcaf...afbf53 )
by Sérgio
04:13
created

Collection::concat()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Sergiors\Functional;
4
5
/**
6
 * @author Sérgio Rafael Siqueira <[email protected]>
7
 */
8
class Collection implements \ArrayAccess, \IteratorAggregate, \Countable
9
{
10
    /**
11
     * @var array
12
     */
13
    private $xs;
14
15
    /**
16
     * @param array $xs
17
     */
18 5
    public function __construct(array $xs)
19
    {
20 5
        $this->xs = $xs;
21 5
    }
22
23
    /**
24
     * @param array $xs
25
     *
26
     * @return Collection
27
     */
28 1
    public function concat($xs)
29
    {
30 1
        return new self(concat($this->xs, $xs));
31
    }
32
33
    /**
34
     * @param callable $fn
35
     *
36
     * @return Collection
37
     */
38 1
    public function filter(callable $fn)
39
    {
40 1
        return new self(filter($fn, $this->xs));
41
    }
42
43
    /**
44
     * @param callable $fn
45
     *
46
     * @return Collection
47
     */
48 1
    public function map(callable $fn)
49
    {
50 1
        return new self(map($fn, $this->xs));
51
    }
52
53
    /**
54
     * @param callable $fn
55
     *
56
     * @return Collection
57
     */
58 1
    public function each(callable $fn)
59
    {
60 1
        return new self(each($fn, $this->xs));
61
    }
62
63
    /**
64
     * @param callable $fn
65
     *
66
     * @return mixed
67
     */
68 1
    public function reduce(callable $fn)
69
    {
70 1
        return reduce($fn, $this->xs);
71
    }
72
73
    /**
74
     * @param mixed $value
75
     *
76
     * @return Collection
77
     */
78 1
    public function prepend($value)
79
    {
80 1
        return new self(prepend($value, $this->xs));
81
    }
82
83
    /**
84
     * @param mixed $x
85
     *
86
     * @return Collection
87
     */
88 1
    public function append($x)
89
    {
90 1
        return new self(append($x, $this->xs));
91
    }
92
93
    /**
94
     * @return int
95
     */
96 1
    public function count()
97
    {
98 1
        return count($this->xs);
99
    }
100
101
    /**
102
     * @return \ArrayIterator
103
     */
104 1
    public function getIterator()
105
    {
106 1
        return new \ArrayIterator($this->xs);
107
    }
108
109
    /**
110
     * @return array
111
     */
112 2
    public function toArray()
113
    {
114 2
        return $this->xs;
115
    }
116
117
    /**
118
     * @param mixed $offset
119
     *
120
     * @return bool
121
     */
122 1
    public function offsetExists($offset)
123
    {
124 1
        return has($offset, $this->xs);
125
    }
126
127
    /**
128
     * @param mixed $offset
129
     *
130
     * @return mixed
131
     */
132 1
    public function offsetGet($offset)
133
    {
134 1
        return get($this->xs, $offset, null);
135
    }
136
137
    /**
138
     * @param mixed $offset
139
     *
140
     * @param mixed $value
0 ignored issues
show
Bug introduced by
There is no parameter named $value. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
141
     */
142 1
    public function offsetSet($offset, $x)
143
    {
144 1
        if (null === $offset) {
145 1
            $this->xs[] = $x;
146 1
            return;
147
        }
148
149 1
        $this->xs[$offset] = $x;
150 1
    }
151
152
    /**
153
     * @param mixed $offset
154
     */
155 1
    public function offsetUnset($offset)
156
    {
157 1
        if ($this->offsetExists($offset)) {
158 1
            unset($this->xs[$offset]);
159 1
        }
160 1
    }
161
}
162