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

ArrayAccessToArrayConverter   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 35
ccs 0
cts 20
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A toArray() 0 16 6
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