Completed
Push — master ( 8251f2...4b9f77 )
by Daniel
02:23
created

Salariu::setFormInputSelect()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 13
rs 9.2
cc 4
eloc 8
nc 4
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
class Salariu
32
{
33
34
    use \danielgp\bank_holidays\Romanian,
35
        \danielgp\common_lib\CommonCode,
36
        \danielgp\salariu\Bonuses,
37
        \danielgp\salariu\Taxation;
38
39
    private $appFlags;
40
    private $tApp = null;
41
42
    public function __construct()
0 ignored issues
show
Coding Style introduced by
__construct uses the super-global variable $_REQUEST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
43
    {
44
        $this->appFlags = [
45
            'available_languages' => [
46
                'en_US' => 'US English',
47
                'ro_RO' => 'Română',
48
            ],
49
            'default_language'    => 'ro_RO'
50
        ];
51
        $this->handleLocalizationSalariu();
52
        echo $this->setHeaderHtml();
53
        echo $this->setFormInput();
54
        if (isset($_REQUEST['ym'])) {
55
            $this->refreshExchangeRatesFile();
56
            $aryStngs = $this->readSettingsFromJsonFile('static');
57
            $this->setCurrencyExchangeVariables($aryStngs['Relevant Currencies']);
58
            $this->getExchangeRates();
59
            echo $this->setFormOutput($aryStngs);
60
        }
61
        echo $this->setFooterHtml();
62
    }
63
64
    private function getExchangeRates()
65
    {
66
        $xml = new \XMLReader();
67
        if ($xml->open(EXCHANGE_RATES_LOCAL, 'UTF-8')) {
68
            while ($xml->read()) {
69
                if ($xml->nodeType == \XMLReader::ELEMENT) {
70
                    switch ($xml->localName) {
71
                        case 'Cube':
72
                            $this->appFlags['currency_exchange_rate_date'] = strtotime($xml->getAttribute('date'));
73
                            break;
74
                        case 'Rate':
75
                            if (in_array($xml->getAttribute('currency'), $krncy)) {
0 ignored issues
show
Bug introduced by
The variable $krncy does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
76
                                $cncy = $xml->getAttribute('currency');
77
                                $cVal = $xml->readInnerXml();
78
                                if (!is_null($xml->getAttribute('multiplier'))) {
79
                                    $cVal = $cVal / $xml->getAttribute('multiplier');
80
                                }
81
                                $this->appFlags['currency_exchange_rate_value'][$cncy] = $cVal;
82
                            }
83
                            break;
84
                    }
85
                }
86
            }
87
            $xml->close();
88
        }
89
    }
90
91
    private function getOvertimes($aryStngs)
0 ignored issues
show
Coding Style introduced by
getOvertimes uses the super-global variable $_REQUEST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
92
    {
93
        $pcToBoolean = [0 => true, 1 => false];
94
        $mnth        = $this->setMonthlyAverageWorkingHours($_REQUEST['ym'], $aryStngs, $pcToBoolean[$_REQUEST['pc']]);
95
        return [
96
            'os175' => ceil($_REQUEST['os175'] * 1.75 * $_REQUEST['sn'] / $mnth),
97
            'os200' => ceil($_REQUEST['os200'] * 2 * $_REQUEST['sn'] / $mnth),
98
        ];
99
    }
100
101
    private function getValues($lngBase, $aStngs)
0 ignored issues
show
Coding Style introduced by
getValues uses the super-global variable $_REQUEST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
102
    {
103
        $inDate           = $_REQUEST['ym'];
104
        $wkDay            = $this->setWorkingDaysInMonth($inDate, $_REQUEST['pc']);
105
        $nMealDays        = ($wkDay - $_REQUEST['zfb']);
106
        $shLbl            = [
107
            'MTV'  => 'Meal Ticket Value',
108
            'HFP'  => 'Health Fund Percentage',
109
            'HFUL' => 'Health Fund Upper Limit',
110
        ];
111
        $unemploymentBase = $lngBase;
112
        if ($_REQUEST['ym'] < mktime(0, 0, 0, 1, 1, 2008)) {
113
            $unemploymentBase = $_REQUEST['sn'];
114
        }
115
        $aReturn           = [
116
            'ba'       => $this->setFoodTicketsValue($inDate, $aStngs[$shLbl['MTV']]) * $nMealDays,
117
            'cas'      => $this->setHealthFundTax($inDate, $lngBase, $aStngs[$shLbl['HFP']], $aStngs[$shLbl['HFUL']]),
118
            'sanatate' => $this->setHealthTax($inDate, $lngBase),
119
            'somaj'    => $this->setUnemploymentTax($inDate, $unemploymentBase),
120
        ];
121
        $pdVal             = [
122
            $inDate,
123
            ($lngBase + $aReturn['ba']),
124
            $_REQUEST['pi'],
125
            $aStngs['Personal Deduction'],
126
        ];
127
        $aReturn['pd']     = $this->setPersonalDeduction($pdVal[0], $pdVal[1], $pdVal[2], $pdVal[3]);
128
        $restArrayToDeduct = [
129
            $aReturn['cas'],
130
            $aReturn['sanatate'],
131
            $aReturn['somaj'],
132
            $aReturn['pd'],
133
        ];
134
        $rest              = $lngBase - array_sum($restArrayToDeduct);
135
        if ($inDate >= mktime(0, 0, 0, 7, 1, 2010)) {
136
            $rest += round($aReturn['ba'], -4);
137
        }
138
        if ($inDate >= mktime(0, 0, 0, 10, 1, 2010)) {
139
            $aReturn['gbns'] = $_REQUEST['gbns'] * pow(10, 4);
140
            $rest            += round($aReturn['gbns'], -4);
141
        }
142
        $rest               += $_REQUEST['afet'] * pow(10, 4);
143
        $aReturn['impozit'] = $this->setIncomeTax($inDate, $rest);
144
        $aReturn['zile']    = $this->setWorkingDaysInMonth($inDate, $_REQUEST['pc']);
145
        return $aReturn;
146
    }
147
148
    private function handleLocalizationSalariu()
0 ignored issues
show
Coding Style introduced by
handleLocalizationSalariu uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
handleLocalizationSalariu uses the super-global variable $_SESSION which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
149
    {
150
        if (isset($_GET['lang'])) {
151
            $_SESSION['lang'] = filter_var($_GET['lang'], FILTER_SANITIZE_STRING);
152
        } elseif (!isset($_SESSION['lang'])) {
153
            $_SESSION['lang'] = $this->appFlags['default_language'];
154
        }
155
        /* to avoid potential language injections from other applications that do not applies here */
156
        if (!in_array($_SESSION['lang'], array_keys($this->appFlags['available_languages']))) {
157
            $_SESSION['lang'] = $this->appFlags['default_language'];
158
        }
159
        $localizationFile = 'Salariu/locale/' . $_SESSION['lang'] . '/LC_MESSAGES/salariu.mo';
160
        $translations     = new \Gettext\Translations;
161
        $translations->addFromMoFile($localizationFile);
162
        $this->tApp       = new \Gettext\Translator();
163
        $this->tApp->loadTranslations($translations);
164
    }
165
166
    private function refreshExchangeRatesFile()
167
    {
168
        if ((filemtime(EXCHANGE_RATES_LOCAL) + 90 * 24 * 60 * 60) < time()) {
169
            $fCntnt = file_get_contents(EXCHANGE_RATES_SOURCE);
170
            if ($fCntnt !== false) {
171
                chmod(EXCHANGE_RATES_LOCAL, 0666);
172
                file_put_contents(EXCHANGE_RATES_LOCAL, $fCntnt);
173
            }
174
        }
175
    }
176
177
    private function setCurrencyExchangeVariables($aryRelevantCurrencies)
178
    {
179
        $this->appFlags['currency_exchanges']          = $aryRelevantCurrencies;
180
        $this->appFlags['currency_exchange_rate_date'] = strtotime('now');
181
        $krncy                                         = array_keys($this->appFlags['currency_exchanges']);
182
        foreach ($krncy as $value) {
183
            $this->appFlags['currency_exchange_rate_value'][$value] = 1;
184
        }
185
    }
186
187
    private function setFooterHtml()
188
    {
189
        $sReturn = $this->setUpperRightBoxLanguages($this->appFlags['available_languages'])
190
                . '<div class="resetOnly author">&copy; 2015 Daniel Popiniuc</div>'
191
                . '<hr/>'
192
                . '<div class="disclaimer">'
193
                . $this->tApp->gettext('i18n_Disclaimer')
194
                . '</div>';
195
        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...
196
    }
197
198
    private function setFormInput()
0 ignored issues
show
Coding Style introduced by
setFormInput uses the super-global variable $_REQUEST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
setFormInput uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
199
    {
200
        $label     = $this->tApp->gettext('i18n_Form_Label_CalculationMonth');
201
        $sReturn[] = $this->setFormRow($label, $this->setFormInputSelect(), 1);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$sReturn was never initialized. Although not strictly required by PHP, it is generally a good practice to add $sReturn = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
202
        $label     = $this->tApp->gettext('i18n_Form_Label_NegotiatedSalary');
203
        $sReturn[] = $this->setFormRow($label, $this->setStringIntoShortTag('input', [
204
                    'type'  => 'text',
205
                    'name'  => 'sn',
206
                    'value' => $_REQUEST['sn'],
207
                    'size'  => 10
208
                ]) . ' RON', 1);
209
        $label     = $this->tApp->gettext('i18n_Form_Label_CumulatedAddedValue');
210
        $sReturn[] = $this->setFormRow($label, $this->setStringIntoShortTag('input', [
211
                    'type'  => 'text',
212
                    'name'  => 'sc',
213
                    'value' => $_REQUEST['sc'],
214
                    'size'  => 2
215
                ]) . ' %', 1);
216
        $label     = $this->tApp->gettext('i18n_Form_Label_AdditionalBruttoAmount');
217
        $sReturn[] = $this->setFormRow($label, $this->setStringIntoShortTag('input', [
218
                    'type'  => 'text',
219
                    'name'  => 'pb',
220
                    'value' => $_REQUEST['pb'],
221
                    'size'  => 10
222
                ]) . ' RON', 1);
223
        $label     = $this->tApp->gettext('i18n_Form_Label_AdditionalNettoAmount');
224
        $sReturn[] = $this->setFormRow($label, $this->setStringIntoShortTag('input', [
225
                    'type'  => 'text',
226
                    'name'  => 'pn',
227
                    'value' => $_REQUEST['pn'],
228
                    'size'  => 10
229
                ]) . ' RON', 1);
230
        $pieces    = [
231
            $this->tApp->gettext('i18n_Form_Label_OvertimeHours'),
232
            $this->tApp->gettext('i18n_Form_Label_OvertimeChoice1'),
233
        ];
234
        $label     = sprintf($pieces[0], $pieces[1], '175%');
235
        $sReturn[] = $this->setFormRow($label, $this->setStringIntoShortTag('input', [
236
                    'type'  => 'text',
237
                    'name'  => 'os175',
238
                    'value' => $_REQUEST['os175'],
239
                    'size'  => 2
240
                ]), 1);
241
        $pieces    = [
242
            $this->tApp->gettext('i18n_Form_Label_OvertimeHours'),
243
            $this->tApp->gettext('i18n_Form_Label_OvertimeChoice2'),
244
        ];
245
        $label     = sprintf($pieces[0], $pieces[1], '200%');
246
        $sReturn[] = $this->setFormRow($label, $this->setStringIntoShortTag('input', [
247
                    'type'  => 'text',
248
                    'name'  => 'os200',
249
                    'value' => $_REQUEST['os200'],
250
                    'size'  => 2
251
                ]), 1);
252
        $temp2     = [];
253
        for ($counter = 0; $counter <= 4; $counter++) {
254
            $temp2[] = $counter;
255
        }
256
        $selectTemp = $this->setArrayToSelect($temp2, $_REQUEST['pi'], 'pi', ['size' => 1]);
257
        $sReturn[]  = $this->setFormRow($this->tApp->gettext('i18n_Form_Label_PersonsSupported'), $selectTemp, 1);
258
        $choices    = [
259
            $this->tApp->gettext('i18n_Form_Label_CatholicEasterFree_ChoiceNo'),
260
            $this->tApp->gettext('i18n_Form_Label_CatholicEasterFree_ChoiceYes'),
261
        ];
262
        $label      = $this->tApp->gettext('i18n_Form_Label_CatholicEasterFree');
263
        $select     = $this->setArrayToSelect($choices, $_REQUEST['pc'], 'pc', ['size' => 1]);
264
        $sReturn[]  = $this->setFormRow($label, $select, 1);
265
        $label      = $this->tApp->gettext('i18n_Form_Label_SeisureAmout');
266
        $sReturn[]  = $this->setFormRow($label, $this->setStringIntoShortTag('input', [
267
                    'type'  => 'text',
268
                    'name'  => 'szamnt',
269
                    'value' => $_REQUEST['szamnt'],
270
                    'size'  => 10
271
                ]), 1);
272
        $label      = $this->tApp->gettext('i18n_Form_Label_WorkedDaysWithoutFoodBonuses');
273
        $sReturn[]  = $this->setFormRow($label, $this->setStringIntoShortTag('input', [
274
                    'type'  => 'text',
275
                    'name'  => 'zfb',
276
                    'value' => $_REQUEST['zfb'],
277
                    'size'  => 2
278
                ]), 1);
279
        $label      = $this->tApp->gettext('i18n_Form_Label_FoodBonusesValue');
280
        $sReturn[]  = $this->setFormRow($label, $this->setStringIntoShortTag('input', [
281
                    'type'  => 'text',
282
                    'name'  => 'gbns',
283
                    'value' => $_REQUEST['gbns'],
284
                    'size'  => 2]), 1);
285
        $label      = $this->tApp->gettext('i18n_Form_Label_AdvantagesForExciseTax');
286
        $sReturn[]  = $this->setFormRow($label, $this->setStringIntoShortTag('input', [
287
                    'type'  => 'text',
288
                    'name'  => 'afet',
289
                    'value' => $_REQUEST['afet'],
290
                    'size'  => 2]), 1);
291
        $label      = $this->tApp->gettext('i18n_Form_Disclaimer');
292
        $sReturn[]  = $this->setStringIntoTag($this->setStringIntoTag($label . $this->setStringIntoShortTag('input', [
293
                            'type'  => 'hidden',
294
                            'name'  => 'action',
295
                            'value' => $_SERVER['SERVER_NAME']
296
                        ]), 'td', ['colspan' => 2, 'style' => 'color: red;']), 'tr');
297
        if (isset($_REQUEST['ym'])) {
298
            $resetBtn     = '';
299
            $submitBtnTxt = $this->tApp->gettext('i18n_Form_Button_Recalculate');
300
        } else {
301
            $resetBtn     = $this->setStringIntoShortTag('input', [
302
                'type'  => 'reset',
303
                'id'    => 'reset',
304
                'value' => $this->tApp->gettext('i18n_Form_Button_Reset'),
305
                'style' => 'color:#000;'
306
            ]);
307
            $submitBtnTxt = $this->tApp->gettext('i18n_Form_Button_Calculate');
308
        }
309
        $sReturn[] = $this->setFormRow($resetBtn, $this->setStringIntoShortTag('input', [
310
                    'type'  => 'submit',
311
                    'id'    => 'submit',
312
                    'value' => $submitBtnTxt
313
                ]), 1);
314
        $frm       = $this->setStringIntoTag($this->setStringIntoTag(implode('', $sReturn), 'table'), 'form', [
315
            'method' => 'get',
316
            'action' => $_SERVER['SCRIPT_NAME']
317
        ]);
318
        return $this->setStringIntoTag(implode('', [
319
                    $this->setStringIntoTag($this->tApp->gettext('i18n_FieldsetLabel_Inputs'), 'legend'),
320
                    $frm
321
                        ]), 'fieldset', ['style' => 'float: left;']);
322
    }
323
324
    private function setFormInputSelect()
0 ignored issues
show
Coding Style introduced by
setFormInputSelect uses the super-global variable $_REQUEST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
325
    {
326
        $temp = [];
327
        for ($counter = date('Y'); $counter >= 2001; $counter--) {
328
            for ($counter2 = 12; $counter2 >= 1; $counter2--) {
329
                $crtDate = mktime(0, 0, 0, $counter2, 1, $counter);
330
                if ($crtDate <= mktime(0, 0, 0, date('m'), 1, date('Y'))) {
331
                    $temp[$crtDate] = strftime('%Y, %m (%B)', $crtDate);
332
                }
333
            }
334
        }
335
        return $this->setArrayToSelect($temp, $_REQUEST['ym'], 'ym', ['size' => 1]);
336
    }
337
338
    private function setFormOutput($aryStngs)
0 ignored issues
show
Coding Style introduced by
setFormOutput uses the super-global variable $_REQUEST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
setFormOutput uses the super-global variable $_SESSION which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
339
    {
340
        $overtime  = $this->getOvertimes($aryStngs['Monthly Average Working Hours']);
341
        $additions = $_REQUEST['pb'] + $overtime['os175'] + $overtime['os200'];
342
        $brut      = ($_REQUEST['sn'] * (1 + $_REQUEST['sc'] / 100) + $additions) * pow(10, 4);
343
        $text      = $this->tApp->gettext('i18n_Form_Label_ExchangeRateAtDate');
344
        $xRate     = str_replace('%1', date('d.m.Y', $this->appFlags['currency_exchange_rate_date']), $text);
345
        $sReturn[] = $this->setFormRow($xRate, 1000000);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$sReturn was never initialized. Although not strictly required by PHP, it is generally a good practice to add $sReturn = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
346
        $text      = $this->tApp->gettext('i18n_Form_Label_NegotiatedSalary');
347
        $sReturn[] = $this->setFormRow($text, $_REQUEST['sn'] * 10000);
348
        $prima     = $_REQUEST['sn'] * $_REQUEST['sc'] * 100;
349
        $sReturn[] = $this->setFormRow($this->tApp->gettext('i18n_Form_Label_CumulatedAddedValue'), $prima);
350
        $text      = $this->tApp->gettext('i18n_Form_Label_AdditionalBruttoAmount');
351
        $sReturn[] = $this->setFormRow($text, $_REQUEST['pb'] * 10000);
352
        $ovTime    = [
353
            'main' => $this->tApp->gettext('i18n_Form_Label_OvertimeAmount'),
354
            1      => $this->tApp->gettext('i18n_Form_Label_OvertimeChoice1'),
355
            2      => $this->tApp->gettext('i18n_Form_Label_OvertimeChoice2'),
356
        ];
357
        $sReturn[] = $this->setFormRow(sprintf($ovTime['main'], $ovTime[1], '175%'), ($overtime['os175'] * pow(10, 4)));
358
        $sReturn[] = $this->setFormRow(sprintf($ovTime['main'], $ovTime[2], '200%'), ($overtime['os200'] * pow(10, 4)));
359
        $sReturn[] = $this->setFormRow($this->tApp->gettext('i18n_Form_Label_BruttoSalary'), $brut);
360
        $brut      += $_REQUEST['afet'] * pow(10, 4);
361
        $amount    = $this->getValues($brut, $aryStngs);
362
        $sReturn[] = $this->setFormRow($this->tApp->gettext('i18n_Form_Label_PensionFund'), $amount['cas']);
363
        $sReturn[] = $this->setFormRow($this->tApp->gettext('i18n_Form_Label_UnemploymentTax'), $amount['somaj']);
364
        $sReturn[] = $this->setFormRow($this->tApp->gettext('i18n_Form_Label_HealthTax'), $amount['sanatate']);
365
        $sReturn[] = $this->setFormRow($this->tApp->gettext('i18n_Form_Label_PersonalDeduction'), $amount['pd']);
366
        $sReturn[] = $this->setFormRow($this->tApp->gettext('i18n_Form_Label_ExciseTax'), $amount['impozit']);
367
        $retineri  = $amount['cas'] + $amount['somaj'] + $amount['sanatate'] + $amount['impozit'];
368
        $net       = $brut - $retineri + $_REQUEST['pn'] * 10000;
369
        $text      = $this->tApp->gettext('i18n_Form_Label_AdditionalNettoAmount');
370
        $sReturn[] = $this->setFormRow($text, $_REQUEST['pn'] * 10000);
371
        $sReturn[] = $this->setFormRow($this->tApp->gettext('i18n_Form_Label_NettoSalary'), $net);
372
        $text      = $this->tApp->gettext('i18n_Form_Label_SeisureAmout');
373
        $sReturn[] = $this->setFormRow($text, $_REQUEST['szamnt'] * 10000);
374
        $text      = $this->tApp->gettext('i18n_Form_Label_NettoSalaryCash');
375
        $sReturn[] = $this->setFormRow($text, ($net - $_REQUEST['szamnt'] * 10000));
376
        $sReturn[] = $this->setFormRow($this->tApp->gettext('i18n_Form_Label_WorkingDays'), $amount['zile'], 'value');
377
        $fBonus    = [
378
            'main'  => $this->tApp->gettext('i18n_Form_Label_FoodBonuses'),
379
            'no'    => $this->tApp->gettext('i18n_Form_Label_FoodBonusesChoiceNo'),
380
            'value' => $this->tApp->gettext('i18n_Form_Label_FoodBonusesChoiceValue')
381
        ];
382
        $fBonusTxt = sprintf($fBonus['main'], $fBonus['value'], $fBonus['no'], ($amount['zile'] - $_REQUEST['zfb']));
383
        $sReturn[] = $this->setFormRow($fBonusTxt, $amount['ba']);
384
        $sReturn[] = $this->setFormRow($this->tApp->gettext('i18n_Form_Label_FoodBonusesValue'), $amount['gbns']);
385
        $total     = ($net + $amount['ba'] + $amount['gbns'] - $_REQUEST['szamnt'] * 10000);
386
        $sReturn[] = $this->setFormRow($this->tApp->gettext('i18n_Form_Label_Total'), $total);
387
        setlocale(LC_TIME, explode('_', $_SESSION['lang'])[0]);
388
        $crtMonth  = strftime('%B', $_REQUEST['ym']);
389
        $legend    = sprintf($this->tApp->gettext('i18n_FieldsetLabel_Results'), $crtMonth, date('Y', $_REQUEST['ym']));
390
        return $this->setStringIntoTag(implode('', [
391
                    $this->setStringIntoTag($legend, 'legend'),
392
                    $this->setStringIntoTag(implode('', $sReturn), 'table')
393
                        ]), 'fieldset', ['style' => 'float: left;']);
394
    }
395
396
    private function setFormRow($text, $value, $type = 'amount')
397
    {
398
        $a                = '';
399
        $defaultCellStyle = ['class' => 'labelS'];
400
        switch ($text) {
401
            case $this->tApp->gettext('i18n_Form_Label_NegotiatedSalary'):
402
            case $this->tApp->gettext('i18n_Form_Label_BruttoSalary'):
403
            case $this->tApp->gettext('i18n_Form_Label_NettoSalaryCash'):
404
                $defaultCellStyle = array_merge($defaultCellStyle, [
405
                    'style' => 'color:#000000;font-weight:bold;'
406
                ]);
407
                break;
408
            case $this->tApp->gettext('i18n_Form_Label_SeisureAmout'):
409
            case $this->tApp->gettext('i18n_Form_Label_PensionFund'):
410
            case $this->tApp->gettext('i18n_Form_Label_HealthTax'):
411
            case $this->tApp->gettext('i18n_Form_Label_UnemploymentTax'):
412
            case $this->tApp->gettext('i18n_Form_Label_ExciseTax'):
413
                $defaultCellStyle = array_merge($defaultCellStyle, [
414
                    'style' => 'color:#ff9900;'
415
                ]);
416
                break;
417
            case $this->tApp->gettext('i18n_Form_Label_Total'):
418
                $defaultCellStyle = array_merge($defaultCellStyle, [
419
                    'style' => 'font-weight:bold;color:#009933;font-size:larger;'
420
                ]);
421
                break;
422
        }
423
        $defaultCellStyle['style'] = '';
424
        if ((is_numeric($value)) && ($value == 0)) {
425
            if (isset($defaultCellStyle['style'])) {
426
                $defaultCellStyle['style'] = 'color:#666;';
427
            } else {
428
                $defaultCellStyle = array_merge($defaultCellStyle, [
429
                    'style' => 'color:#666;'
430
                ]);
431
            }
432
        }
433
        switch ($type) {
434
            case 'amount':
435
                $value                      = $value / pow(10, 4);
436
                $defaultCellStyle2['style'] = $defaultCellStyle['style'] . 'text-align:right;';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$defaultCellStyle2 was never initialized. Although not strictly required by PHP, it is generally a good practice to add $defaultCellStyle2 = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
437
                $cellValue                  = [];
438
                foreach ($this->appFlags['currency_exchanges'] as $key2 => $value2) {
439
                    $fmt         = new \NumberFormatter($value2['locale'], \NumberFormatter::CURRENCY);
440
                    $fmt->setAttribute(\NumberFormatter::FRACTION_DIGITS, $value2['decimals']);
441
                    $x           = $this->appFlags['currency_exchange_rate_value'][$key2];
442
                    $finalValue  = $fmt->formatCurrency($value / $x, $key2);
443
                    $cellValue[] = $this->setStringIntoTag($finalValue, 'td', $defaultCellStyle2);
444
                }
445
                $value2show        = implode('', $cellValue);
446
                break;
447
            case 'value':
448
                $defaultCellStyle2 = array_merge($defaultCellStyle, [
449
                    'colspan' => count($this->appFlags['currency_exchanges'])
450
                ]);
451
                $value2show        = $this->setStringIntoTag($value . $a, 'td', $defaultCellStyle2);
452
                break;
453
            default:
454
                $value2show        = $this->setStringIntoTag($value, 'td');
455
                break;
456
        }
457
        if (!in_array($text, ['', '&nbsp;']) && (strpos($text, '<input') === false)) {
458
            $text .= ':';
459
        }
460
        return $this->setStringIntoTag($this->setStringIntoTag($text, 'td', $defaultCellStyle) . $value2show, 'tr');
461
    }
462
463
    private function setHeaderHtml()
0 ignored issues
show
Coding Style introduced by
setHeaderHtml uses the super-global variable $_SESSION which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
464
    {
465
        return $this->setHeaderCommon([
466
                    'lang'  => str_replace('_', '-', $_SESSION['lang']),
467
                    'title' => $this->tApp->gettext('i18n_ApplicationName'),
468
                    'css'   => [
469
                        'vendor/components/flag-icon-css/css/flag-icon.min.css',
470
                        'Salariu/css/salariu.css',
471
                    ],
472
                ])
473
                . '<h1>' . $this->tApp->gettext('i18n_ApplicationName') . '</h1>'
474
        ;
475
    }
476
}
477