Collection::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

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