Completed
Push — master ( 9f9125...d63efc )
by Rafael
02:27
created

ArrayParser   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

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
 * LICENSE: This file is subject to the terms and conditions defined in
5
 * file 'LICENSE', which is part of this source code package.
6
 *
7
 * @copyright 2016 Copyright(c) - All rights reserved.
8
 */
9
10
namespace Rafrsr\LibArray2Object\Parser;
11
12
class ArrayParser implements ValueParserInterface
13
{
14
    const NAME = 'array';
15
16
    /**
17
     * @inheritDoc
18
     */
19
    public function getName()
20
    {
21
        return self::NAME;
22
    }
23
24
    /**
25
     * @inheritDoc
26
     */
27
    public function toObjectValue($value, $type, \ReflectionProperty $property, $object)
28
    {
29
        if ($type === 'array') {
30
            if (!is_array($value) && !$value) {
31
                return [];
32
            }
33
        }
34
35
        return $value;
36
    }
37
38
    /**
39
     * @inheritDoc
40
     */
41
    public function toArrayValue($value, $type, \ReflectionProperty $property, $object)
42
    {
43
        return $value;
44
    }
45
}