BasicSalariu   A
last analyzed

Complexity

Total Complexity 20

Size/Duplication

Total Lines 121
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 20
lcom 1
cbo 3
dl 0
loc 121
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A handleLocalizationSalariu() 0 10 1
A handleLocalizationSalariuInputsIntoSession() 0 8 4
A handleLocalizationSalariuSafe() 0 6 2
A setAnalyticsToInclude() 0 7 2
A setFooterHtml() 0 12 1
A setHeaderHtml() 0 18 1
A setLabel() 0 17 4
A setLabelSuffix() 0 8 4
A setPreliminarySettings() 0 13 1
1
<?php
2
3
/**
4
 *
5
 * The MIT License (MIT)
6
 *
7
 * Copyright (c) 2017 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\salariu;
30
31
trait BasicSalariu
32
{
33
34
    use \danielgp\common_lib\CommonCode;
35
36
    protected $appFlags;
37
    protected $tApp = null;
38
39
    private function handleLocalizationSalariu($appSettings)
40
    {
41
        $this->handleLocalizationSalariuInputsIntoSession($appSettings);
42
        $this->handleLocalizationSalariuSafe($appSettings);
43
        $localizationFile = 'static/locale/' . $this->tCmnSession->get('lang') . '/LC_MESSAGES/salariu.mo';
44
        $translations     = new \Gettext\Translations();
45
        $translations->addFromMoFile($localizationFile);
46
        $this->tApp       = new \Gettext\Translator();
47
        $this->tApp->loadTranslations($translations);
48
    }
49
50
    private function handleLocalizationSalariuInputsIntoSession($appSettings)
51
    {
52
        if (is_null($this->tCmnSuperGlobals->get('lang')) && is_null($this->tCmnSession->get('lang'))) {
53
            $this->tCmnSession->set('lang', $appSettings['Default Language']);
54
        } elseif (!is_null($this->tCmnSuperGlobals->get('lang'))) {
55
            $this->tCmnSession->set('lang', filter_var($this->tCmnSuperGlobals->get('lang'), FILTER_SANITIZE_STRING));
56
        }
57
    }
58
59
    /**
60
     * To avoid potential language injections from other applications that do not applies here
61
     *
62
     * @param type $appSettings
63
     */
64
    private function handleLocalizationSalariuSafe($appSettings)
65
    {
66
        if (!array_key_exists($this->tCmnSession->get('lang'), $appSettings['Available Languages'])) {
67
            $this->tCmnSession->set('lang', $appSettings['Default Language']);
68
        }
69
    }
70
71
    private function setAnalyticsToInclude()
72
    {
73
        if (file_exists('analytics.min.html')) {
74
            return file_get_contents('analytics.min.html');
75
        }
76
        return '';
77
    }
78
79
    private function setFooterHtml($appSettings)
80
    {
81
        return $this->setFooterCommon(''
0 ignored issues
show
Documentation introduced by
'' . $this->setUpperRigh...Disclaimer') . '</div>' is of type string, but the function expects a array|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
82
                . $this->setUpperRightBoxLanguages($appSettings['Available Languages'])
83
                . '<div class="resetOnly author">&copy; ' . date('Y') . ' '
84
                . $appSettings['Copyright Holder'] . '</div>'
85
                . '<hr/>'
86
                . $this->setAnalyticsToInclude()
87
                . '<div class="disclaimer">'
88
                . $this->tApp->gettext('i18n_Disclaimer')
89
                . '</div>');
90
    }
91
92
    private function setHeaderHtml()
93
    {
94
        $headerParameters = [
95
            'css'        => [
96
                'vendor/components/flag-icon-css/css/flag-icon.min.css',
97
                'vendor/fortawesome/font-awesome/css/font-awesome.min.css',
98
                'static/css/salariu.css',
99
            ],
100
            'javascript' => [
101
                'vendor/danielgp/common-lib/js/tabber/tabber-management.min.js',
102
                'vendor/danielgp/common-lib/js/tabber/tabber.min.js',
103
            ],
104
            'lang'       => str_replace('_', '-', $this->tCmnSession->get('lang')),
105
            'title'      => $this->tApp->gettext('i18n_ApplicationName'),
106
        ];
107
        return $this->setHeaderCommon($headerParameters)
108
            . '<h1>' . $this->tApp->gettext('i18n_ApplicationName') . '</h1>';
109
    }
110
111
    private function setLabel($labelId)
112
    {
113
        $labelInfo = $this->appFlags['FI'][$labelId]['Label'];
114
        $sReturn   = '';
115
        if (is_array($labelInfo)) {
116
            if (count($labelInfo) == 3) {
117
                $pieces  = [
118
                    $this->tApp->gettext($labelInfo[0]),
119
                    $this->tApp->gettext($labelInfo[1]),
120
                ];
121
                $sReturn = sprintf($pieces[0], $pieces[1], $labelInfo[2]);
122
            }
123
        } elseif (is_string($labelInfo)) {
124
            $sReturn = $this->tApp->gettext($labelInfo);
125
        }
126
        return $this->setLabelSuffix($sReturn);
127
    }
128
129
    private function setLabelSuffix($text)
130
    {
131
        $suffix = '';
132
        if (!in_array($text, ['', '&nbsp;']) && (strpos($text, '<input') === false) && (substr($text, -1) !== '!')) {
133
            $suffix = ':';
134
        }
135
        return $text . $suffix;
136
    }
137
138
    private function setPreliminarySettings($inElmnts)
139
    {
140
        $this->appFlags = [
141
            'DCTD' => $inElmnts['Application']['Default Currencies To Display'],
142
            'FI'   => $inElmnts['Form Input'],
143
            'TCAS' => $inElmnts['Table Cell Applied Style'],
144
            'TCSD' => $inElmnts['Table Cell Style Definitions'],
145
            'VFR'  => $inElmnts['Values Filter Rules'],
146
        ];
147
        $this->initializeSprGlbAndSession();
148
        $this->handleLocalizationSalariu($inElmnts['Application']);
149
        echo $this->setHeaderHtml();
150
    }
151
}
152