Completed
Push — master ( bf4509...0aeec2 )
by Daniel
03:40
created

BasicSalariu   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 95
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 17
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 95
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A handleLocalizationSalariu() 0 10 1
A handleLocalizationSalariuInputsIntoSession() 0 8 4
A handleLocalizationSalariuSafe() 0 6 2
A setFooterHtml() 0 11 1
A setHeaderHtml() 0 15 1
A setLabel() 0 17 4
A setLabelSuffix() 0 8 4
1
<?php
2
3
/**
4
 *
5
 * The MIT License (MIT)
6
 *
7
 * Copyright (c) 2016 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 = 'Salariu/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 setFooterHtml($appSettings)
72
    {
73
        $sReturn = $this->setUpperRightBoxLanguages($appSettings['Available Languages'])
74
            . '<div class="resetOnly author">&copy; ' . date('Y') . ' '
75
            . $appSettings['Copyright Holder'] . '</div>'
76
            . '<hr/>'
77
            . '<div class="disclaimer">'
78
            . $this->tApp->gettext('i18n_Disclaimer')
79
            . '</div>';
80
        return $this->setFooterCommon($sReturn);
0 ignored issues
show
Documentation introduced by
$sReturn 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...
81
    }
82
83
    private function setHeaderHtml()
84
    {
85
        $headerParameters = [
86
            'lang'  => str_replace('_', '-', $this->tCmnSession->get('lang')),
87
            'title' => $this->tApp->gettext('i18n_ApplicationName'),
88
            'css'   => [
89
                'vendor/components/flag-icon-css/css/flag-icon.min.css',
90
                'vendor/fortawesome/font-awesome/css/font-awesome.min.css',
91
                'Salariu/css/salariu.css',
92
            ],
93
        ];
94
        return $this->setHeaderCommon($headerParameters)
95
            . '<h1>' . $this->tApp->gettext('i18n_ApplicationName') . '</h1>'
96
            . '<p>&nbsp;</p>';
97
    }
98
99
    private function setLabel($labelId)
100
    {
101
        $labelInfo = $this->appFlags['FI'][$labelId]['Label'];
102
        $sReturn   = '';
103
        if (is_array($labelInfo)) {
104
            if (count($labelInfo) == 3) {
105
                $pieces  = [
106
                    $this->tApp->gettext($labelInfo[0]),
107
                    $this->tApp->gettext($labelInfo[1]),
108
                ];
109
                $sReturn = sprintf($pieces[0], $pieces[1], $labelInfo[2]);
110
            }
111
        } elseif (is_string($labelInfo)) {
112
            $sReturn = $this->tApp->gettext($labelInfo);
113
        }
114
        return $this->setLabelSuffix($sReturn);
115
    }
116
117
    private function setLabelSuffix($text)
118
    {
119
        $suffix = '';
120
        if (!in_array($text, ['', '&nbsp;']) && (strpos($text, '<input') === false) && (substr($text, -1) !== '!')) {
121
            $suffix = ':';
122
        }
123
        return $text . $suffix;
124
    }
125
}
126