Test Failed
Push — main ( 577f79...66b7bb )
by Daniel
02:12
created

TraitLines::getLine()   B

Complexity

Conditions 11
Paths 12

Size

Total Lines 32
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 11
eloc 24
nc 12
nop 1
dl 0
loc 32
rs 7.3166
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 *
5
 * The MIT License (MIT)
6
 *
7
 * Copyright (c) 2024 Daniel Popiniuc
8
 *
9
 * Permission is hereby granted, free of charge, to any person obtaining a copy
10
 * of this software and associated documentation files (the "Software"), to deal
11
 * in the Software without restriction, including without limitation the rights
12
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
 * copies of the Software, and to permit persons to whom the Software is
14
 * furnished to do so, subject to the following conditions:
15
 *
16
 * The above copyright notice and this permission notice shall be included in all
17
 * copies or substantial portions of the Software.
18
 *
19
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
 *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
 * SOFTWARE.
26
 *
27
 */
28
29
namespace danielgp\efactura;
30
31
trait TraitLines
32
{
33
34
    use TraitBasic,
35
        TraitTax;
36
37
    private function getDocumentLines(\SimpleXMLElement $arrayDataIn, string $strTag): array
38
    {
39
        $arrayLines = [];
40
        $intLineNo  = 0;
41
        foreach ($arrayDataIn->children('cac', true) as $strNodeName => $child) {
42
            if ($strNodeName === ($strTag . 'Line')) {
43
                $intLineNo++;
44
                $intLineStr              = ($intLineNo < 10 ? '0' : '') . $intLineNo;
45
                $arrayLines[$intLineStr] = $this->getLine($child);
0 ignored issues
show
Bug introduced by
It seems like $child can also be of type null; however, parameter $child of danielgp\efactura\TraitLines::getLine() does only seem to accept SimpleXMLElement, maybe add an additional type check? ( Ignorable by Annotation )

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

45
                $arrayLines[$intLineStr] = $this->getLine(/** @scrutinizer ignore-type */ $child);
Loading history...
46
            }
47
        }
48
        return $arrayLines;
49
    }
50
51
    private function getLine(\SimpleXMLElement $child): array
52
    {
53
        $arrayOutput = [];
54
        foreach ($this->arraySettings['CustomOrder']['Lines@Read'] as $strElement => $strType) {
55
            switch ($strType) {
56
                case 'Item':
57
                    $arrayOutput['Item'] = $this->getLineItem($child->children('cac', true)->Item);
58
                    break;
59
                case 'Multiple':
60
                    $intLineNo           = 0;
61
                    foreach ($child->children('cac', true)->$strElement as $value2) {
62
                        $intLineNo++;
63
                        $intLineStr                            = ($intLineNo < 10 ? '0' : '') . $intLineNo;
64
                        $arrayOutput[$strElement][$intLineStr] = $this->getElements($value2);
65
                    }
66
                    break;
67
                case 'Single':
68
                    if (count($child->children('cbc', true)->$strElement) !== 0) {
69
                        $arrayOutput[$strElement] = $child->children('cbc', true)->$strElement->__toString();
70
                    }
71
                    if (count($child->children('cac', true)->$strElement) !== 0) {
72
                        $arrayOutput[$strElement] = $this->getElements($child->children('cac', true)->$strElement);
73
                    }
74
                    break;
75
                case 'SingleTag':
76
                    if (count($child->children('cbc', true)->$strElement) !== 0) {
77
                        $arrayOutput[$strElement] = $this->getElementSingle($child->children('cbc', true)->$strElement);
78
                    }
79
                    break;
80
            }
81
        }
82
        return $arrayOutput;
83
    }
84
85
    private function getLineItem(\SimpleXMLElement $child3): array
86
    {
87
        $arrayOutput = [];
88
        foreach ($this->arraySettings['CustomOrder']['Lines_Item@Read'] as $key => $value) {
89
            switch ($value) {
90
                case 'MultipleAggregate':
91
                    $intLineNo = 0;
92
                    foreach ($child3->children('cac', true)->$key as $value2) {
93
                        $intLineNo++;
94
                        $intLineStr                     = ($intLineNo < 10 ? '0' : '') . $intLineNo;
95
                        $arrayOutput[$key][$intLineStr] = $this->getElements($value2);
96
                    }
97
                    break;
98
                case 'SingleAggregate':
99
                    if (count($child3->children('cac', true)->$key) !== 0) {
100
                        $arrayOutput[$key] = $this->getElements($child3->children('cac', true)->$key);
101
                    }
102
                    break;
103
                case 'SingleBasic':
104
                    if (count($child3->children('cbc', true)->$key) !== 0) {
105
                        $arrayOutput[$key] = $child3->children('cbc', true)->$key->__toString();
106
                    }
107
                    break;
108
                case 'TaxCategory':
109
                    $arrayOutput[$key] = $this->getTaxCategory($child3->children('cac', true)->$key);
110
                    break;
111
            }
112
        }
113
        return $arrayOutput;
114
    }
115
}
116