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

Collection   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 6
c 1
b 1
f 0
lcom 1
cbo 0
dl 0
loc 41
ccs 0
cts 25
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 3
A getIteratorReversed() 0 7 1
A value() 0 4 1
A toArray() 0 4 1
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