ArrayAccessToArrayConverter::toArray()   A
last analyzed

Complexity

Conditions 6
Paths 6

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 16.6682

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 4
cts 12
cp 0.3333
rs 9.1111
c 0
b 0
f 0
cc 6
nc 6
nop 0
crap 16.6682
1
<?php
2
3
namespace Metabor\Statemachine\Util;
4
5
use MetaborStd\ArrayConvertableInterface;
6
use MetaborStd\MetadataInterface;
7
8
/**
9
 * @author Oliver Tischlinger
10
 */
11
class ArrayAccessToArrayConverter implements ArrayConvertableInterface
12
{
13
    /**
14
     * @var \ArrayAccess
15
     */
16
    private $object;
17
18
    /**
19
     * @param \ArrayAccess $object
20
     */
21 4
    public function __construct(\ArrayAccess $object)
22
    {
23 4
        $this->object = $object;
24 4
    }
25
26
    /**
27
     * @see \MetaborStd\ArrayConvertableInterface::toArray()
28
     */
29 4
    public function toArray()
30
    {
31 4
        if ($this->object instanceof MetadataInterface) {
32
            return $this->object->getMetadata();
33 4
        } elseif ($this->object instanceof ArrayConvertableInterface) {
34 4
            return $this->object->toArray();
35
        } elseif ($this->object instanceof \ArrayIterator) {
36
            return $this->object->getArrayCopy();
37
        } elseif ($this->object instanceof \ArrayObject) {
38
            return $this->object->getArrayCopy();
39
        } elseif ($this->object instanceof \Traversable) {
40
            return iterator_to_array($this->object);
41
        } else {
42
            throw new \RuntimeException('Unable to get MetaData!');
43
        }
44
    }
45
}
46