Passed
Push — main ( d81296...64f1fd )
by Daniel
02:41
created

getKeyFromArrayOrAlternative()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 3
dl 0
loc 7
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 TraitVersions;
0 ignored issues
show
introduced by
The trait danielgp\efactura\TraitVersions requires some properties which are not provided by danielgp\efactura\ElectronicInvoiceComments: $objXmlWriter, $currencyID, $unitCode
Loading history...
35
36
    public function getCommentsIntoArrayForTable()
37
    {
38
        $arrayCommentsRaw      = $this->getCommentsFromFileAsArray();
39
        $arrayCommentsForTable = [];
40
        $arrayMapping          = [
41
            'BG-' => 'Group',
42
            'BT-' => 'Field',
43
        ];
44
        foreach ($arrayCommentsRaw as $key => $value) {
45
            $strKeyPrefix = substr($key, 0, 3);
46
            $strIdType    = (in_array($strKeyPrefix, array_keys($arrayMapping)) ? $arrayMapping[$strKeyPrefix] : '?');
47
            $arrayTemp    = [
48
                'ID'                 => $key,
49
                'IT_Type'            => $strIdType,
50
                'Level'              => $value['Level'],
51
                'Cardinality'        => $value['Cardinality'],
52
                'OperationalTerm_EN' => $this->getKeyFromArrayOrAlternative('en_US', $value['OperationalTerm'], '-'),
53
                'OperationalTerm_RO' => $this->getKeyFromArrayOrAlternative('ro_RO', $value['OperationalTerm'], '-'),
54
                'Description_EN'     => $this->getKeyFromArrayOrAlternative('en_US', $value['Description'], '-'),
55
                'Description_RO'     => $this->getKeyFromArrayOrAlternative('ro_RO', $value['Description'], '-'),
56
                'UsageNote_EN'       => $this->getKeyFromArrayOrAlternative('en_US', $value['UsageNote'], $value, '-'),
0 ignored issues
show
Unused Code introduced by
The call to danielgp\efactura\Electr...romArrayOrAlternative() has too many arguments starting with '-'. ( Ignorable by Annotation )

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

56
                'UsageNote_EN'       => $this->/** @scrutinizer ignore-call */ getKeyFromArrayOrAlternative('en_US', $value['UsageNote'], $value, '-'),

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
57
                'UsageNote_RO'       => $this->getKeyFromArrayOrAlternative('ro_RO', $value['UsageNote'], $value, '-'),
58
                'RequirementID'      => $value['RequirementID'],
59
                'SemanticDataType'   => $this->getKeyFromArrayOrAlternative('SemanticDataType', $value, '-'),
60
            ];
61
            if (is_array($value['HierarchycalTagName'])) {
62
                foreach ($value['HierarchycalTagName'] as $value2) {
63
                    $arrayCommentsForTable[] = array_merge(['Tag' => $value2], $arrayTemp);
64
                }
65
            } else {
66
                $arrayCommentsForTable[] = array_merge(['Tag' => $value['HierarchycalTagName']], $arrayTemp);
67
            }
68
        }
69
        return $arrayCommentsForTable;
70
    }
71
72
    public function getCommentsIntoArrayForVerifications()
73
    {
74
        $arrayCommentsRaw      = $this->getCommentsFromFileAsArray();
75
        $arrayCommentsForTable = [];
76
        foreach ($arrayCommentsRaw as $key => $value) {
77
            if (array_key_exists('SemanticDataType', $value)) {
78
                $arrayCommentsForTable[$value['SemanticDataType']] = [
79
                    'ID' => $key,
80
                ];
81
            }
82
        }
83
        return $arrayCommentsForTable;
84
    }
85
86
    public function getKeyFromArrayOrAlternative(string $strKey, array $arrayIn, string $strAlternative): string
87
    {
88
        $strToReturn = $strAlternative;
89
        if (array_key_exists($strKey, $arrayIn)) {
90
            $strToReturn = $arrayIn[$strKey];
91
        }
92
        return $strToReturn;
93
    }
94
}
95