Completed
Push — master ( 2dbfbb...b82522 )
by Daniel
04:36
created

BasicSalariu::setFormInputSelectPI()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 3
eloc 5
nc 3
nop 0
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 buildArrayOfFieldsStyled()
40
    {
41
        $sReturn = [];
42
        foreach ($this->appFlags['TCAS'] as $key => $value) {
43
            $sReturn[$this->tApp->gettext($key)]       = $value;
44
            $sReturn[$this->tApp->gettext($key) . ':'] = $value;
45
        }
46
        return $sReturn;
47
    }
48
49
    private function buildStyleForCellFormat($styleId)
50
    {
51
        $sReturn = [];
52
        foreach ($this->appFlags['TCSD'][$styleId] as $key => $value) {
53
            $sReturn[] = $key . ':' . $value;
54
        }
55
        return implode(';', $sReturn) . ';';
56
    }
57
58
    private function handleLocalizationSalariu($appSettings)
59
    {
60
        $this->handleLocalizationSalariuInputsIntoSession($appSettings);
61
        $this->handleLocalizationSalariuSafe($appSettings);
62
        $localizationFile = 'Salariu/locale/' . $this->tCmnSession->get('lang') . '/LC_MESSAGES/salariu.mo';
63
        $translations     = new \Gettext\Translations;
64
        $translations->addFromMoFile($localizationFile);
65
        $this->tApp       = new \Gettext\Translator();
66
        $this->tApp->loadTranslations($translations);
67
    }
68
69
    private function handleLocalizationSalariuInputsIntoSession($appSettings)
70
    {
71
        if (is_null($this->tCmnSuperGlobals->get('lang')) && is_null($this->tCmnSession->get('lang'))) {
72
            $this->tCmnSession->set('lang', $appSettings['Default Language']);
73
        } elseif (!is_null($this->tCmnSuperGlobals->get('lang'))) {
74
            $this->tCmnSession->set('lang', filter_var($this->tCmnSuperGlobals->get('lang'), FILTER_SANITIZE_STRING));
75
        }
76
    }
77
78
    /**
79
     * To avoid potential language injections from other applications that do not applies here
80
     *
81
     * @param type $appSettings
82
     */
83
    private function handleLocalizationSalariuSafe($appSettings)
84
    {
85
        if (!array_key_exists($this->tCmnSession->get('lang'), $appSettings['Available Languages'])) {
86
            $this->tCmnSession->set('lang', $appSettings['Default Language']);
87
        }
88
    }
89
90
    private function processFormInputDefaults($inDefaultValues)
91
    {
92
        if (is_null($this->tCmnSuperGlobals->get('ym'))) {
93
            $this->tCmnSuperGlobals->request->set('ym', mktime(0, 0, 0, date('m'), 1, date('Y')));
94
        }
95
        foreach ($inDefaultValues as $key => $value) {
96
            if (is_null($this->tCmnSuperGlobals->get($key))) {
97
                $this->tCmnSuperGlobals->request->set($key, $value);
98
            }
99
        }
100
    }
101
102
    private function setFooterHtml($appSettings)
103
    {
104
        $sReturn = $this->setUpperRightBoxLanguages($appSettings['Available Languages'])
105
            . '<div class="resetOnly author">&copy; ' . date('Y') . ' '
106
            . $appSettings['Copyright Holder'] . '</div>'
107
            . '<hr/>'
108
            . '<div class="disclaimer">'
109
            . $this->tApp->gettext('i18n_Disclaimer')
110
            . '</div>';
111
        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...
112
    }
113
114
    private function setFormInputSelectPC()
115
    {
116
        $choices = [
117
            $this->tApp->gettext('i18n_Form_Label_CatholicEasterFree_ChoiceNo'),
118
            $this->tApp->gettext('i18n_Form_Label_CatholicEasterFree_ChoiceYes'),
119
        ];
120
        return $this->setArrayToSelect($choices, $this->tCmnSuperGlobals->get('pc'), 'pc', ['size' => 1]);
121
    }
122
123
    private function setFormInputSelectPI()
124
    {
125
        $temp2 = [];
126
        for ($counter = 0; $counter <= 4; $counter++) {
127
            $temp2[$counter] = $counter . ($counter == 4 ? '+' : '');
128
        }
129
        return $this->setArrayToSelect($temp2, $this->tCmnSuperGlobals->get('pi'), 'pi', ['size' => 1]);
130
    }
131
132
    private function setFormInputSelectYM()
133
    {
134
        $temp = [];
135
        for ($counter = date('Y'); $counter >= 2001; $counter--) {
136
            for ($counter2 = 12; $counter2 >= 1; $counter2--) {
137
                $crtDate = mktime(0, 0, 0, $counter2, 1, $counter);
138
                if ($crtDate <= mktime(0, 0, 0, date('m'), 1, date('Y'))) {
139
                    $temp[$crtDate] = strftime('%Y, %m (%B)', $crtDate);
140
                }
141
            }
142
        }
143
        return $this->setArrayToSelect($temp, $this->tCmnSuperGlobals->get('ym'), 'ym', ['size' => 1]);
144
    }
145
146
    private function setFormatRow($text, $value)
147
    {
148
        $defaultCellStyle = [
149
            'class' => 'labelS',
150
            'style' => 'color:#000;',
151
        ];
152
        $fieldsStyled     = $this->buildArrayOfFieldsStyled();
153
        if (array_key_exists($text, $fieldsStyled)) {
154
            $defaultCellStyle['style'] = $this->buildStyleForCellFormat($fieldsStyled[$text]);
155
        }
156
        if ((is_numeric($value)) && ($value == 0)) {
157
            $defaultCellStyle['style'] = 'color:#666;';
158
        }
159
        return $defaultCellStyle;
160
    }
161
162
    private function setHeaderHtml()
163
    {
164
        $headerParameters = [
165
            'lang'  => str_replace('_', '-', $this->tCmnSession->get('lang')),
166
            'title' => $this->tApp->gettext('i18n_ApplicationName'),
167
            'css'   => [
168
                'vendor/components/flag-icon-css/css/flag-icon.min.css',
169
                'Salariu/css/salariu.css',
170
            ],
171
        ];
172
        return $this->setHeaderCommon($headerParameters)
173
            . '<h1>' . $this->tApp->gettext('i18n_ApplicationName') . '</h1>';
174
    }
175
176
    private function setLabel($labelId)
177
    {
178
        $labelInfo = $this->appFlags['FI'][$labelId]['Label'];
179
        $sReturn   = '';
180
        if (is_array($labelInfo)) {
181
            if (count($labelInfo) == 3) {
182
                $pieces  = [
183
                    $this->tApp->gettext($labelInfo[0]),
184
                    $this->tApp->gettext($labelInfo[1]),
185
                ];
186
                $sReturn = sprintf($pieces[0], $pieces[1], $labelInfo[2]);
187
            }
188
        } elseif (is_string($labelInfo)) {
189
            $sReturn = $this->tApp->gettext($labelInfo);
190
        }
191
        return $this->setLabelSuffix($sReturn);
192
    }
193
194
    private function setLabelSuffix($text)
195
    {
196
        $suffix = '';
197
        if (!in_array($text, ['', '&nbsp;']) && (strpos($text, '<input') === false) && (substr($text, -1) !== '!')) {
198
            $suffix = ':';
199
        }
200
        return $text . $suffix;
201
    }
202
}
203