ArrayParser   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 0
dl 0
loc 34
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 4 1
A toObjectValue() 0 10 4
A toArrayValue() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the rafrsr/lib-array2object package.
5
 *
6
 * (c) Rafael SR <https://github.com/rafrsr>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
namespace Rafrsr\LibArray2Object\Parser;
12
13
class ArrayParser implements ValueParserInterface
14
{
15
    const NAME = 'array';
16
17
    /**
18
     * {@inheritdoc}
19
     */
20
    public function getName()
21
    {
22
        return self::NAME;
23
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function toObjectValue($value, $type, \ReflectionProperty $property, $object)
29
    {
30
        if ($type === 'array') {
31
            if (!is_array($value) && !$value) {
32
                return [];
33
            }
34
        }
35
36
        return $value;
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function toArrayValue($value, $type, \ReflectionProperty $property, $object)
43
    {
44
        return $value;
45
    }
46
}
47