Test Failed
Push — main ( 2ad17d...7bbdc7 )
by Daniel
02:34
created

TraitLines::getLine()   A

Complexity

Conditions 6
Paths 15

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 11
c 0
b 0
f 0
nc 15
nop 1
dl 0
loc 18
rs 9.2222
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($objFile, string $strTag): array
38
    {
39
        $arrayLines = [];
40
        $intLineNo  = 0;
41
        foreach ($objFile->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);
46
            }
47
        }
48
        return $arrayLines;
49
    }
50
51
    private function getLine($child): array
52
    {
53
        $arrayOutput = [];
54
        foreach (['CreditedQuantity', 'ID', 'InvoicedQuantity', 'LineExtensionAmount'] as $strElement) {
55
            if (count($child->children('cbc', true)->$strElement) !== 0) {
56
                $arrayOutput[$strElement] = $this->getElementSingle($child->children('cbc', true)->$strElement);
57
            }
58
        }
59
        foreach (['AccountingCost', 'DocumentReference', 'InvoicePeriod', 'Note', 'OrderLineReference', 'Price'] as $strElement) {
60
            if (count($child->children('cbc', true)->$strElement) !== 0) {
61
                $arrayOutput[$strElement] = $child->children('cbc', true)->$strElement->__toString();
62
            }
63
            if (count($child->children('cac', true)->$strElement) !== 0) {
64
                $arrayOutput[$strElement] = $this->getElements($child->children('cac', true)->$strElement);
65
            }
66
        }
67
        $arrayOutput['Item'] = $this->getLineItem($child->children('cac', true)->Item);
68
        return $arrayOutput;
69
    }
70
71
    private function getLineItem($child3): array
72
    {
73
        $arrayOutput = [];
74
        foreach ($this->arraySettings['CustomOrder']['Lines_Item@Read'] as $key => $value) {
75
            switch ($value) {
76
                case 'MultipleAggregate':
77
                    $intLineNo = 0;
78
                    foreach ($child3->children('cac', true)->$key as $value2) {
79
                        $intLineNo++;
80
                        $intLineStr                     = ($intLineNo < 10 ? '0' : '') . $intLineNo;
81
                        $arrayOutput[$key][$intLineStr] = $this->getElements($value2);
82
                    }
83
                    break;
84
                case 'SingleAggregate':
85
                    if (count($child3->children('cac', true)->$key) !== 0) {
86
                        $arrayOutput[$key] = $this->getElements($child3->children('cac', true)->$key);
87
                    }
88
                    break;
89
                case 'SingleBasic':
90
                    if (count($child3->children('cbc', true)->$key) !== 0) {
91
                        $arrayOutput[$key] = $child3->children('cbc', true)->$key->__toString();
92
                    }
93
                    break;
94
                case 'TaxCategory':
95
                    $arrayOutput[$key] = $this->getTaxCategory($child3->children('cac', true)->$key);
96
                    break;
97
            }
98
        }
99
        return $arrayOutput;
100
    }
101
}
102