Completed
Push — master ( b268cf...c6aad7 )
by Oliver
07:45
created

ArrayAccessToArrayConverter::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
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
    public function __construct(\ArrayAccess $object)
22
    {
23
        $this->object = $object;
24
    }
25
26
    /**
27
     * @see \MetaborStd\ArrayConvertableInterface::toArray()
28
     */
29
    public function toArray()
30
    {
31
        if ($this->object instanceof MetadataInterface) {
32
            return $this->object->getMetadata();
33
        } elseif ($this->object instanceof ArrayConvertableInterface) {
34
            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