Passed
Push — main ( bf08fb...375d1e )
by Daniel
02:06
created

TraitTax   A

Complexity

Total Complexity 19

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 1
Metric Value
eloc 49
dl 0
loc 81
rs 10
c 4
b 0
f 1
wmc 19

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getTaxSubTotal() 0 18 5
A getTaxTotal() 0 21 6
A getTax() 0 10 2
A getTaxCategory() 0 22 6
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 TraitTax
32
{
33
    use TraitBasic;
34
35
    private function getTax(\SimpleXMLElement $child): array
36
    {
37
        $arrayOut  = [];
38
        $intLineNo = 0;
39
        foreach ($child as $child2) {
40
            $intLineNo++;
41
            $intLineStr            = $this->getLineStringFromNumber($intLineNo);
42
            $arrayOut[$intLineStr] = $this->getTaxTotal($child2);
0 ignored issues
show
Bug introduced by
It seems like $child2 can also be of type null; however, parameter $child of danielgp\efactura\TraitTax::getTaxTotal() 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

42
            $arrayOut[$intLineStr] = $this->getTaxTotal(/** @scrutinizer ignore-type */ $child2);
Loading history...
43
        }
44
        return $arrayOut;
45
    }
46
47
    private function getTaxCategory(\SimpleXMLElement $child3, string $strElementWithChildrens): array
48
    {
49
        $arrayOut = [];
50
        foreach ($this->arrayProcessing[$strElementWithChildrens] as $strElement => $strType) {
51
            switch ($strType) {
52
                case 'Elements':
53
                    if (isset($child3->children('cac', true)->$strElement)) {
54
                        $arrayOut[$strElement] = $this->getElements($child3->children('cac', true)->$strElement);
55
                    }
56
                    break;
57
                /* case 'Multiple':
58
                  $arrayOut[$strElement] = $this->getTaxCategory($child3->children('cac', true)
59
                  ->$strElement, $strElement);
60
                  break; */
61
                case 'Single':
62
                    if (isset($child3->children('cbc', true)->$strElement)) {
63
                        $arrayOut[$strElement] = $this->getElementSingle($child3->children('cbc', true)->$strElement);
64
                    }
65
                    break;
66
            }
67
        }
68
        return $arrayOut;
69
    }
70
71
    private function getTaxSubTotal(\SimpleXMLElement $child)
72
    {
73
        $arrayOut = [];
74
        foreach ($this->arrayProcessing['TaxSubtotal'] as $strElementChild => $strTypeChild) {
75
            switch ($strTypeChild) {
76
                case 'Single':
77
                    if (isset($child->children('cbc', true)->$strElementChild)) {
78
                        $arrayOut[$strElementChild] = $this
79
                            ->getElementSingle($child->children('cbc', true)->$strElementChild);
80
                    }
81
                    break;
82
                case 'Multiple':
83
                    $arrayOut[$strElementChild] = $this->getTaxCategory($child->children('cac', true)
84
                        ->$strElementChild, $strElementChild);
85
                    break;
86
            }
87
        }
88
        return $arrayOut;
89
    }
90
91
    private function getTaxTotal(\SimpleXMLElement $child): array
92
    {
93
        $arrayOut = [];
94
        foreach ($this->arrayProcessing['TaxTotal'] as $strElement => $strType) {
95
            switch ($strType) {
96
                case 'Single':
97
                    if (isset($child->children('cbc', true)->$strElement)) {
98
                        $arrayOut[$strElement] = $this->getElementSingle($child->children('cbc', true)->$strElement);
99
                    }
100
                    break;
101
                case 'Multiple':
102
                    $intLineNo = 0;
103
                    foreach ($child->children('cac', true)->$strElement as $child3) {
104
                        $intLineNo++;
105
                        $intLineStr                         = $this->getLineStringFromNumber($intLineNo);
106
                        $arrayOut[$strElement][$intLineStr] = $this->getTaxSubTotal($child3);
107
                    }
108
                    break;
109
            }
110
        }
111
        return $arrayOut;
112
    }
113
}
114