AbstractModel   A
last analyzed

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
 * @SuppressWarnings(PHPMD.NumberOfChildren)
18
 */
19
abstract class AbstractModel implements ModelInterface
20
{
21
    /**
22
     * @return array
23
     */
24 26
    public function toArray()
25
    {
26 26
        $properties = get_object_vars($this);
27
28 26
        return $this->parseArray($properties);
29
    }
30
31
    /**
32
     * @return string
33
     */
34 1
    public function toJson()
35
    {
36 1
        return json_encode($this->toArray());
37
    }
38
39 26
    private function parseArray(array $values)
40
    {
41 26
        foreach ($values as $key => $value) {
42 26
            if (is_array($value)) {
43 2
                $values[$key] = $this->parseArray($value);
44
            }
45
46 26
            if ($value instanceof ModelInterface) {
47 26
                $values[$key] = $value->toArray();
48
            }
49
        }
50
51 26
        return $values;
52
    }
53
}
54