Completed
Push — master ( dda000...a904dd )
by Daniel
02:11
created

BasicSalariu::setPreliminarySettings()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 14
rs 9.4285
cc 1
eloc 11
nc 1
nop 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 = '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
        return $this->setFooterCommon($this->setUpperRightBoxLanguages($appSettings['Available Languages'])
0 ignored issues
show
Documentation introduced by
$this->setUpperRightBoxL...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...
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
    }
81
82
    private function setHeaderHtml()
83
    {
84
        $headerParameters = [
85
            'css'        => [
86
                'vendor/components/flag-icon-css/css/flag-icon.min.css',
87
                'vendor/fortawesome/font-awesome/css/font-awesome.min.css',
88
                'Salariu/css/salariu.css',
89
            ],
90
            'javascript' => [
91
                'vendor/danielgp/common-lib/js/tabber/tabber-management.min.js',
92
                'vendor/danielgp/common-lib/js/tabber/tabber.min.js',
93
            ],
94
            'lang'       => str_replace('_', '-', $this->tCmnSession->get('lang')),
95
            'title'      => $this->tApp->gettext('i18n_ApplicationName'),
96
        ];
97
        return $this->setHeaderCommon($headerParameters)
98
            . '<h1>' . $this->tApp->gettext('i18n_ApplicationName') . '</h1>';
99
    }
100
101
    private function setLabel($labelId)
102
    {
103
        $labelInfo = $this->appFlags['FI'][$labelId]['Label'];
104
        $sReturn   = '';
105
        if (is_array($labelInfo)) {
106
            if (count($labelInfo) == 3) {
107
                $pieces  = [
108
                    $this->tApp->gettext($labelInfo[0]),
109
                    $this->tApp->gettext($labelInfo[1]),
110
                ];
111
                $sReturn = sprintf($pieces[0], $pieces[1], $labelInfo[2]);
112
            }
113
        } elseif (is_string($labelInfo)) {
114
            $sReturn = $this->tApp->gettext($labelInfo);
115
        }
116
        return $this->setLabelSuffix($sReturn);
117
    }
118
119
    private function setLabelSuffix($text)
120
    {
121
        $suffix = '';
122
        if (!in_array($text, ['', '&nbsp;']) && (strpos($text, '<input') === false) && (substr($text, -1) !== '!')) {
123
            $suffix = ':';
124
        }
125
        return $text . $suffix;
126
    }
127
128
    private function setPreliminarySettings($inElmnts)
129
    {
130
        $this->appFlags = [
131
            'DCTD' => $inElmnts['Application']['Default Currencies To Display'],
132
            'FI'   => $inElmnts['Form Input'],
133
            'TCAS' => $inElmnts['Table Cell Applied Style'],
134
            'TCSD' => $inElmnts['Table Cell Style Definitions'],
135
            'VFR'  => $inElmnts['Values Filter Rules'],
136
        ];
137
        $this->initializeSprGlbAndSession();
138
        $this->handleLocalizationSalariu($inElmnts['Application']);
139
        echo $this->setHeaderHtml();
140
        $this->establishLocalizationToDisplay();
0 ignored issues
show
Bug introduced by
It seems like establishLocalizationToDisplay() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
141
    }
142
}
143