Completed
Pull Request — master (#72)
by Ivan
14:40 queued 12:19
created

Collection::value()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Underscore;
4
5
class Collection extends \ArrayObject
6
{
7
    public function __construct($input)
8
    {
9
        if (is_object($input)) {
10
            if ($input instanceof \Traversable) {
11
                $input = iterator_to_array($input);
12
            } else {
13
                $input = get_object_vars($input);
14
            }
15
        }
16
        parent::__construct($input, static::ARRAY_AS_PROPS);
17
    }
18
19
    /**
20
     * @return \ArrayIterator
21
     */
22
    public function getIteratorReversed()
23
    {
24
        $iterator = $this->getIteratorClass();
25
        $collection = array_reverse($this->getArrayCopy());
26
27
        return new $iterator($collection);
28
    }
29
30
    /**
31
     * @return mixed
32
     */
33
    public function value()
34
    {
35
        return $this->toArray();
36
    }
37
38
    /**
39
     * @return mixed[]
40
     */
41
    public function toArray()
42
    {
43
        return $this->getArrayCopy();
44
    }
45
}
46