Completed
Push — master ( 42afef...5f18df )
by Dmitry
06:49 queued 03:50
created

Converter::toObject()   B

Complexity

Conditions 7
Paths 8

Size

Total Lines 21
Code Lines 11

Duplication

Lines 5
Ratio 23.81 %

Code Coverage

Tests 15
CRAP Score 7

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 5
loc 21
ccs 15
cts 15
cp 1
rs 7.551
cc 7
eloc 11
nc 8
nop 1
crap 7
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 1
                }
14 1
                return $data;
15
            }
16 8
        }
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 1
                $data->$k = $this->toObject($v);
23 1
            }
24 8
        }
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 2
        }
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 1
                $data[$k] = $this->toArray($v);
42 1
            }
43 2
        }
44
45 2
        return $data;
46
    }
47
}