ArrayDeserializationVisitor   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 4
c 2
b 0
f 1
lcom 0
cbo 2
dl 0
loc 21
ccs 10
cts 10
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A decode() 0 18 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