Passed
Branch master (6e2713)
by Zangra
14:31
created

Model::encodeLines()   A

Complexity

Conditions 6
Paths 5

Size

Total Lines 30
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 11
c 0
b 0
f 0
nc 5
nop 1
dl 0
loc 30
rs 9.2222
1
<?php
2
declare(strict_types=1);
3
4
namespace GeodisBundle\Domain\Base;
5
6
/**
7
 * Author: Nils méchin <[email protected]>
8
 * Author: Maxime Lambot <[email protected]>.
9
 */
10
abstract class Model
11
{
12
    public function toJson($skipNullValues = null): bool|string
0 ignored issues
show
Unused Code introduced by
The parameter $skipNullValues is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

12
    public function toJson(/** @scrutinizer ignore-unused */ $skipNullValues = null): bool|string

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
13
    {
14
        $json = array();
15
        foreach ($this as $key => $value) {
16
            if ('url' === $key or 'primaryKey' === $key) {
17
                continue;
18
            }
19
20
            if (null === $value) {
21
                continue;
22
            }
23
24
            // If an array of entity is passed to the json, it squizzed it,
25
            // rebuild an proper array without being entity and pass it to the $json array
26
            if ('listEnvois' == $key) {
27
                $value = $this->encodeLines($value);
28
            }
29
30
            $json[$key] = $value;
31
        }
32
33
        return json_encode($json);
34
    }
35
36
    private function encodeLines($value)
37
    {
38
        $salesOrderLines = array();
39
        foreach ($value as $line) {
40
            $salesOrderLine = array();
41
            foreach ($line as $entryKey => $entry) {
42
                if ('url' === $entryKey or 'primaryKey' === $entryKey) {
43
                    continue;
44
                }
45
                if (null === $entry) {
46
                    continue;
47
                }
48
                
49
                /*
50
                if ('destinataire' == $entryKey) {
51
                    $entry = $this->encodeSubLines($value);
52
                }
53
                if ('expediteur' == $entryKey) {
54
                    $entry = $this->encodeSubLines($value);
55
                }
56
                if ('listUmgs' == $entryKey) {
57
                    $entry = $this->encodeSubLines($value);
58
                }
59
                */
60
                $salesOrderLine[$entryKey] = $entry;
61
            }
62
            array_push($salesOrderLines, $salesOrderLine);
63
        }
64
65
        return $salesOrderLines;
66
    }
67
68
    private function encodeSubLines($value)
0 ignored issues
show
Unused Code introduced by
The method encodeSubLines() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
69
    {
70
        $salesOrderLines = array();
71
        foreach ($value as $line) {
72
            $salesOrderLine = array();
73
            foreach ($line as $entryKey => $entry) {
74
                if ('url' === $entryKey or 'primaryKey' === $entryKey) {
75
                    continue;
76
                }
77
                if (null === $entry) {
78
                    continue;
79
                }
80
                $salesOrderLine[$entryKey] = $entry;
81
            }
82
            array_push($salesOrderLines, $salesOrderLine);
83
        }
84
85
        return $salesOrderLines;
86
    }
87
}
88