Passed
Push — main ( 996ebb...3a3fc1 )
by Daniel
12:26
created

TraitCompanies::getPostalAddress()   A

Complexity

Conditions 6
Paths 32

Size

Total Lines 25
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 15
c 0
b 0
f 0
nc 32
nop 1
dl 0
loc 25
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 TraitCompanies
32
{
33
34
    use TraitBasic;
35
36
    private function getAccountingCustomerParty($child2): array
37
    {
38
        $arrayMainOutput = [
39
            'PostalAddress'    => $this->getElements($child2->children('cac', true)->PostalAddress),
40
            'PartyLegalEntity' => $this->getPartyLegalEntity($child2->children('cac', true)->PartyLegalEntity),
41
        ];
42
        // optional components =========================================================================================
43
        if (isset($child2->children('cac', true)->PartyName)) {
44
            $arrayMainOutput['PartyName'] = $this->getPartyName($child2->children('cac', true)->PartyName);
45
        }
46
        if (isset($child2->children('cac', true)->PartyTaxScheme)) {
47
            $arrayMainOutput['PartyTaxScheme'] = $this->getPartyTaxScheme($child2
48
                    ->children('cac', true)->PartyTaxScheme);
49
        }
50
        if (isset($child2->children('cac', true)->PartyIdentification)) {
51
            $arrayMainOutput['PartyIdentification'] = $this->getPartyIdentification($child2
52
                    ->children('cac', true)->PartyIdentification);
53
        }
54
        if (isset($child2->children('cbc', true)->EndpointID)) {
55
            $arrayMainOutput['EndpointID'] = [
56
                'schemeID' => $child2->children('cbc', true)->EndpointID->attributes()->schemeID->__toString(),
57
                'value'    => $child2->children('cbc', true)->EndpointID->__toString(),
58
            ];
59
        }
60
        $arrayContact = $this->getContact($child2->children('cac', true)->Contact);
61
        if ($arrayContact != []) {
62
            $arrayMainOutput['Contact'] = $arrayContact;
63
        }
64
        return ['Party' => $arrayMainOutput];
65
    }
66
67
    private function getAccountingSupplierParty($child2): array
68
    {
69
        $arrayMainOutput = [
70
            'PostalAddress'    => $this->getElements($child2->children('cac', true)->PostalAddress),
71
            'PartyLegalEntity' => $this->getPartyLegalEntity($child2->children('cac', true)->PartyLegalEntity),
72
        ];
73
        if (isset($child2->children('cac', true)->PartyTaxScheme)) {
74
            $arrayMainOutput['PartyTaxScheme'] = $this->getPartyTaxScheme($child2->children('cac', true)->PartyTaxScheme);
75
        }
76
        if (isset($child2->children('cac', true)->PartyName)) {
77
            $arrayMainOutput['PartyName'] = $this->getPartyName($child2->children('cac', true)->PartyName);
78
        }
79
        // optional components =========================================================================================
80
        $arrayContact = $this->getContact($child2->children('cac', true)->Contact);
81
        if ($arrayContact != []) {
82
            $arrayMainOutput['Contact'] = $arrayContact;
83
        }
84
        if (isset($child2->children('cbc', true)->EndpointID)) {
85
            $arrayMainOutput['EndpointID'] = [
86
                'schemeID' => $child2->children('cbc', true)->EndpointID->attributes()->schemeID->__toString(),
87
                'value'    => $child2->children('cbc', true)->EndpointID->__toString(),
88
            ];
89
        }
90
        if (isset($child2->children('cac', true)->PartyIdentification)) {
91
            $arrayMainOutput['PartyIdentification'] = $this->getPartyIdentification($child2
92
                    ->children('cac', true)->PartyIdentification);
93
        }
94
        return ['Party' => $arrayMainOutput];
95
    }
96
97
    private function getContact($child3): array
98
    {
99
        // optional components =========================================================================================
100
        $arrayOutput = [];
101
        if (isset($child3->children('cbc', true)->Name)) {
102
            $arrayOutput['Name'] = $child3->children('cbc', true)->Name->__toString();
103
        }
104
        if (isset($child3->children('cbc', true)->Telephone)) {
105
            $arrayOutput['Telephone'] = $child3->children('cbc', true)->Telephone->__toString();
106
        }
107
        if (isset($child3->children('cbc', true)->ElectronicMail)) {
108
            $arrayOutput['ElectronicMail'] = $child3->children('cbc', true)->ElectronicMail->__toString();
109
        }
110
        return $arrayOutput;
111
    }
112
113
    private function getPartyIdentification($child3): array
114
    {
115
        $arrayToReturn = $child3->children('cbc', true)->ID->__toString();
116
        if (isset($child3->children('cbc', true)->ID->attributes()->schemeID)) {
117
            $arrayToReturn = [
118
                'schemeID' => $child3->children('cbc', true)->ID->attributes()->schemeID->__toString(),
119
                'value'    => $child3->children('cbc', true)->ID->__toString(),
120
            ];
121
        }
122
        return ['ID' => $arrayToReturn];
123
    }
124
125
    private function getPartyLegalEntity($child3): array
126
    {
127
        $arrayOutput = [
128
            'RegistrationName' => $child3->children('cbc', true)->RegistrationName->__toString(),
129
        ];
130
        // optional components =========================================================================================
131
        if (isset($child3->children('cbc', true)->CompanyID)) {
132
            $arrayOutput['CompanyID'] = $child3->children('cbc', true)->CompanyID->__toString();
133
        }
134
        if (isset($child3->children('cbc', true)->CompanyLegalForm)) {
135
            $arrayOutput['CompanyLegalForm'] = $child3->children('cbc', true)->CompanyLegalForm->__toString();
136
        }
137
        return $arrayOutput;
138
    }
139
140
    private function getPartyName($child3): array
141
    {
142
        $arrayOutput         = [];
143
        $arrayOutput['Name'] = $child3->children('cbc', true)->Name->__toString();
144
        return $arrayOutput;
145
    }
146
147
    private function getPartyTaxScheme($child3): array
148
    {
149
        return [
150
            'CompanyID' => $child3->children('cbc', true)->CompanyID->__toString(),
151
            'TaxScheme' => [
152
                'ID' => $child3->children('cac', true)->TaxScheme->children('cbc', true)->ID->__toString(),
153
            ]
154
        ];
155
    }
156
}
157