ArrayDeserializationVisitor::decode()   A
last analyzed

Complexity

Conditions 4
Paths 5

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 4

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 18
ccs 10
cts 10
cp 1
rs 9.2
cc 4
eloc 9
nc 5
nop 1
crap 4
1
<?php
2
namespace Wonnova\SDK\Serializer;
3
4
use JMS\Serializer\GenericDeserializationVisitor;
5
use JMS\Serializer\Exception\RuntimeException;
6
7
/**
8
 * This deserialization visitor just bypasses arrays, so that objects can be hydrated with data arrays
9
 * @author Wonnova
10
 * @link http://www.wonnova.com
11
 */
12
class ArrayDeserializationVisitor extends GenericDeserializationVisitor
13
{
14 18
    protected function decode($str)
15
    {
16 18
        if (empty($str)) {
17 1
            return [];
18
        }
19
20 17
        if ($str instanceof \Traversable) {
21 1
            $str = iterator_to_array($str);
22 1
        }
23
24 17
        if (! is_array($str)) {
25 1
            throw new RuntimeException(
26
                'Provided value is not an array or Traversable instance and could not be deserialized'
27 1
            );
28
        }
29
30 16
        return $str;
31
    }
32
}
33