Passed
Push — main ( 164d6f...fc3426 )
by Daniel
02:12
created

TraitLines::getDocumentLines()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 8
c 0
b 0
f 0
nc 3
nop 2
dl 0
loc 12
rs 10
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
    use TraitBasic;
34
    use TraitTax;
35
36
    private function getDocumentLines(\SimpleXMLElement $arrayDataIn, string $strTag): array
37
    {
38
        $arrayLines = [];
39
        $intLineNo  = 0;
40
        foreach ($arrayDataIn->children('cac', true) as $strNodeName => $child) {
41
            if ($strNodeName === ($strTag . 'Line')) {
42
                $intLineNo++;
43
                $intLineStr              = $this->getLineStringFromNumber($intLineNo);
44
                $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

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