Passed
Push — main ( 38ac7b...8cd4e0 )
by Daniel
02:08
created

getCommentsIntoArrayForVerifications()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 7
c 1
b 0
f 0
nc 3
nop 0
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, sub-license, 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
class ElectronicInvoiceComments
32
{
33
34
    use TraitComments;
0 ignored issues
show
introduced by
The trait danielgp\efactura\TraitComments requires some properties which are not provided by danielgp\efactura\ElectronicInvoiceComments: $currencyID, $unitCode
Loading history...
35
36
    public function getCommentsIntoArrayForTable()
37
    {
38
        $arrayCommentsRaw      = $this->getCommentsFromFileAsArray();
39
        $arrayCommentsForTable = [];
40
        foreach ($arrayCommentsRaw as $key => $value) {
41
            $arrayTemp = [
42
                'ID'                 => $key,
43
                'ID_Type'            => $this->getTypeOfIdentifier(substr($key, 0, 3)),
44
                'Level'              => $value['Level'],
45
                'Cardinality'        => $value['Cardinality'],
46
                'OperationalTerm_EN' => $this->getKeyFromArrayOrAlternative('en_US', $value['OperationalTerm'], '-'),
47
                'OperationalTerm_RO' => $this->getKeyFromArrayOrAlternative('ro_RO', $value['OperationalTerm'], '-'),
48
                'Description_EN'     => $this->getKeyFromArrayOrAlternative('en_US', $value['Description'], '-'),
49
                'Description_RO'     => $this->getKeyFromArrayOrAlternative('ro_RO', $value['Description'], '-'),
50
                'UsageNote_EN'       => '-',
51
                'UsageNote_RO'       => '-',
52
                'RequirementID'      => $value['RequirementID'],
53
                'SemanticDataType'   => $this->getKeyFromArrayOrAlternative('SemanticDataType', $value, '-'),
54
            ];
55
            if (array_key_exists('UsageNote', $value)) {
56
                $arrayTemp['UsageNote_EN'] = $this->getKeyFromArrayOrAlternative('en_US', $value['UsageNote'], '-');
57
                $arrayTemp['UsageNote_RO'] = $this->getKeyFromArrayOrAlternative('ro_RO', $value['UsageNote'], '-');
58
            }
59
            $arrayCommentsForTable[] = $this->getOneOrMultipleTags($value['HierarchycalTagName'], $arrayTemp);
60
        }
61
        return $arrayCommentsForTable;
62
    }
63
64
    public function getCommentsIntoArrayForVerifications()
65
    {
66
        $arrayCommentsRaw      = $this->getCommentsFromFileAsArray();
67
        $arrayCommentsForTable = [];
68
        foreach ($arrayCommentsRaw as $key => $value) {
69
            if (array_key_exists('SemanticDataType', $value)) {
70
                $arrayCommentsForTable[$value['SemanticDataType']] = [
71
                    'ID' => $key,
72
                ];
73
            }
74
        }
75
        return $arrayCommentsForTable;
76
    }
77
78
    public function getKeyFromArrayOrAlternative(string $strKey, array $arrayIn, string $strAlternative): string
79
    {
80
        $strToReturn = $strAlternative;
81
        if (array_key_exists($strKey, $arrayIn)) {
82
            $strToReturn = $arrayIn[$strKey];
83
        }
84
        return $strToReturn;
85
    }
86
87
    private function getOneOrMultipleTags(array|string $inElement, array $arrayIn): array
88
    {
89
        $arrayToReturn = [];
90
        if (is_array($inElement)) {
0 ignored issues
show
introduced by
The condition is_array($inElement) is always true.
Loading history...
91
            foreach ($inElement as $value2) {
92
                $arrayToReturn = array_merge(['Tag' => $value2], $arrayIn);
93
            }
94
        } else {
95
            $arrayToReturn = array_merge(['Tag' => $inElement], $arrayIn);
96
        }
97
        return $arrayToReturn;
98
    }
99
100
    private function getTypeOfIdentifier(string $strKeyPrefix): string
101
    {
102
        $arrayMapping = [
103
            'BG-' => 'Group',
104
            'BT-' => 'Field',
105
        ];
106
        $strIdType    = 'unknown';
107
        if (in_array($strKeyPrefix, array_keys($arrayMapping))) {
108
            $strIdType = $arrayMapping[$strKeyPrefix];
109
        }
110
        return $strIdType;
111
    }
112
}
113