Passed
Push — main ( ec9792...45a540 )
by Daniel
02:11
created

TraitTax::getTax()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 10
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 TraitTax
32
{
33
34
    use TraitBasic;
35
36
    private function getTax(\SimpleXMLElement $child): array
37
    {
38
        $arrayOutput = [];
39
        $intLineNo   = 0;
40
        foreach ($child as $child2) {
41
            $intLineNo++;
42
            $intLineStr               = $this->getLineStringFromNumber($intLineNo);
43
            $arrayOutput[$intLineStr] = $this->getTaxTotal($child2);
0 ignored issues
show
Bug introduced by
It seems like $child2 can also be of type null; however, parameter $child2 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

43
            $arrayOutput[$intLineStr] = $this->getTaxTotal(/** @scrutinizer ignore-type */ $child2);
Loading history...
44
        }
45
        return $arrayOutput;
46
    }
47
48
    private function getTaxCategory(\SimpleXMLElement $child3): array
49
    {
50
        $arrayOutput = [
51
            'ID'        => $child3->children('cbc', true)->ID->__toString(),
52
            'TaxScheme' => [
53
                'ID' => $child3->children('cac', true)->TaxScheme->children('cbc', true)->ID->__toString(),
54
            ],
55
        ];
56
        // optional components =========================================================================================
57
        if (isset($child3->children('cbc', true)->Percent)) {
58
            $arrayOutput['Percent'] = $child3->children('cbc', true)->Percent->__toString();
59
        }
60
        if (isset($child3->children('cbc', true)->TaxExemptionReason)) {
61
            $arrayOutput['TaxExemptionReason'] = $child3->children('cbc', true)->TaxExemptionReason->__toString();
62
        }
63
        return $arrayOutput;
64
    }
65
66
    private function getTaxTotal(\SimpleXMLElement $child2): array
67
    {
68
        $arrayOutput = [
69
            'TaxAmount' => $this->getElementSingle($child2->children('cbc', true)->TaxAmount)
70
        ];
71
        if (isset($child2->children('cac', true)->TaxSubtotal)) {
72
            $intLineNo = 0;
73
            foreach ($child2->children('cac', true)->TaxSubtotal as $child3) {
74
                $intLineNo++;
75
                $intLineStr                              = $this->getLineStringFromNumber($intLineNo);
76
                $arrayOutput['TaxSubtotal'][$intLineStr] = [
77
                    'TaxAmount'     => $this->getElementSingle($child3->children('cbc', true)->TaxAmount),
0 ignored issues
show
Bug introduced by
The method children() does not exist on null. ( Ignorable by Annotation )

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

77
                    'TaxAmount'     => $this->getElementSingle($child3->/** @scrutinizer ignore-call */ children('cbc', true)->TaxAmount),

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
78
                    'TaxableAmount' => $this->getElementSingle($child3->children('cbc', true)->TaxableAmount),
79
                    'TaxCategory'   => $this->getTaxCategory($child3->children('cac', true)->TaxCategory),
80
                ];
81
            }
82
        }
83
        return $arrayOutput;
84
    }
85
}
86