Completed
Push — master ( c132c8...42afef )
by Dmitry
06:08
created

Converter::toArray()   B

Complexity

Conditions 6
Paths 7

Size

Total Lines 18
Code Lines 9

Duplication

Lines 5
Ratio 27.78 %

Code Coverage

Tests 8
CRAP Score 6.0493

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 5
loc 18
ccs 8
cts 9
cp 0.8889
rs 8.8571
cc 6
eloc 9
nc 7
nop 1
crap 6.0493
1
<?php
2
3
namespace Basis;
4
5
class Converter
6
{
7 8
    function toObject($data)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
8
    {
9 8
        if(is_array($data)) {
10 8
            if(array_keys($data) === range(0, count($data) -1)) {
11 1
                foreach($data as $k => $v) {
12 1
                    $data[$k] = $this->toObject($v);
13
                }
14 1
                return $data;
15
            }
16
        }
17
18 8
        $data = (object) $data;
19
20 8 View Code Duplication
        foreach ($data as $k => $v) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
21 8
            if (is_array($v) || is_object($v)) {
22 8
                $data->$k = $this->toObject($v);
23
            }
24
        }
25
26 8
        return $data;
27
    }
28
29 2
    function toArray($data)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
30
    {
31 2
        if (!$data) {
32
            return [];
33
        }
34
35 2
        if (is_object($data)) {
36 2
            $data = get_object_vars($data);
37
        }
38
39 2 View Code Duplication
        foreach ($data as $k => $v) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
40 2
            if (is_array($v) || is_object($v)) {
41 2
                $data[$k] = $this->toArray($v);
42
            }
43
        }
44
45 2
        return $data;
46
    }
47
}