Passed
Push — master ( 506f67...f6d64e )
by Zbigniew
03:41
created

AbstractModel   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 6 1
A toJson() 0 4 1
A parseArray() 0 14 4
1
<?php
2
3
/*
4
 * This file is part of the zibios/wrike-php-jmsserializer package.
5
 *
6
 * (c) Zbigniew Ślązak
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Zibios\WrikePhpJmsserializer\Model;
13
14
/**
15
 * Abstract Model.
16
 */
17
abstract class AbstractModel implements ModelInterface
18
{
19
    /**
20
     * @return array
21
     */
22 26
    public function toArray()
23
    {
24 26
        $properties = get_object_vars($this);
25
26 26
        return $this->parseArray($properties);
27
    }
28
29
    /**
30
     * @return string
31
     */
32 1
    public function toJson()
33
    {
34 1
        return json_encode($this->toArray());
35
    }
36
37 26
    private function parseArray(array $values)
38
    {
39 26
        foreach ($values as $key => $value) {
40 26
            if (is_array($value)) {
41 2
                $values[$key] = $this->parseArray($value);
42
            }
43
44 26
            if ($value instanceof ModelInterface) {
45 26
                $values[$key] = $value->toArray();
46
            }
47
        }
48
49 26
        return $values;
50
    }
51
}
52