Complex classes like Salariu often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Salariu, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 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() |
||
| 43 | { |
||
| 44 | $configPath = 'Salariu' . DIRECTORY_SEPARATOR . 'config'; |
||
| 45 | $interfaceElements = $this->readTypeFromJsonFileUniversal($configPath, 'interfaceElements'); |
||
| 46 | $this->appFlags = [ |
||
| 47 | 'FI' => $interfaceElements['Form Input'], |
||
| 48 | 'TCAS' => $interfaceElements['Table Cell Applied Style'], |
||
| 49 | 'TCSD' => $interfaceElements['Table Cell Style Definitions'], |
||
| 50 | ]; |
||
| 51 | $this->initializeSprGlbAndSession(); |
||
| 52 | $this->handleLocalizationSalariu($interfaceElements['Application']); |
||
| 53 | echo $this->setHeaderHtml(); |
||
| 54 | echo $this->setFormInput(); |
||
| 55 | $this->refreshExchangeRatesFile($interfaceElements['Application']); |
||
| 56 | $this->setCurrencyExchangeVariables($interfaceElements['Relevant Currencies']); |
||
| 57 | $this->getExchangeRates($interfaceElements['Application'], $interfaceElements['Relevant Currencies']); |
||
| 58 | $aryStngs = $this->readTypeFromJsonFileUniversal($configPath, 'valuesToCompute'); |
||
| 59 | echo $this->setFormOutput($aryStngs); |
||
| 60 | echo $this->setFooterHtml($interfaceElements['Application']); |
||
| 61 | } |
||
| 62 | |||
| 63 | private function buildArrayOfFieldsStyled() |
||
| 64 | { |
||
| 65 | $sReturn = []; |
||
| 66 | foreach ($this->appFlags['TCAS'] as $key => $value) { |
||
| 67 | $sReturn[$this->tApp->gettext($key)] = $value; |
||
| 68 | } |
||
| 69 | return $sReturn; |
||
| 70 | } |
||
| 71 | |||
| 72 | private function buildStyleForCellFormat($styleId) |
||
| 73 | { |
||
| 74 | $sReturn = []; |
||
| 75 | foreach ($this->appFlags['TCSD'][$styleId] as $key => $value) { |
||
| 76 | $sReturn[] = $key . ':' . $value; |
||
| 77 | } |
||
| 78 | return implode(';', $sReturn) . ';'; |
||
| 79 | } |
||
| 80 | |||
| 81 | private function getExchangeRates($appSettings, $aryRelevantCurrencies) |
||
| 82 | { |
||
| 83 | $xml = new \XMLReader(); |
||
| 84 | if ($xml->open($appSettings['Exchange Rate Local'], 'UTF-8')) { |
||
| 85 | while ($xml->read()) { |
||
| 86 | if ($xml->nodeType == \XMLReader::ELEMENT) { |
||
| 87 | switch ($xml->localName) { |
||
| 88 | case 'Cube': |
||
| 89 | $this->appFlags['currency_exchange_rate_date'] = strtotime($xml->getAttribute('date')); |
||
| 90 | break; |
||
| 91 | case 'Rate': |
||
| 92 | if (array_key_exists($xml->getAttribute('currency'), $aryRelevantCurrencies)) { |
||
| 93 | $cVal = $xml->readInnerXml(); |
||
| 94 | if (!is_null($xml->getAttribute('multiplier'))) { |
||
| 95 | $cVal = $cVal / $xml->getAttribute('multiplier'); |
||
| 96 | } |
||
| 97 | $this->appFlags['currency_exchange_rate_value'][$xml->getAttribute('currency')] = $cVal; |
||
| 98 | } |
||
| 99 | break; |
||
| 100 | } |
||
| 101 | } |
||
| 102 | } |
||
| 103 | $xml->close(); |
||
| 104 | } |
||
| 105 | } |
||
| 106 | |||
| 107 | private function getOvertimes($aryStngs) |
||
| 108 | { |
||
| 109 | $pcToBoolean = [0 => true, 1 => false]; |
||
| 110 | $pcBoolean = $pcToBoolean[$this->tCmnSuperGlobals->get('pc')]; |
||
| 111 | $ymVal = $this->tCmnSuperGlobals->get('ym'); |
||
| 112 | $snVal = $this->tCmnSuperGlobals->get('sn'); |
||
| 113 | $mnth = $this->setMonthlyAverageWorkingHours($ymVal, $aryStngs, $pcBoolean); |
||
| 114 | return [ |
||
| 115 | 'os175' => ceil($this->tCmnSuperGlobals->get('os175') * 1.75 * $snVal / $mnth), |
||
| 116 | 'os200' => ceil($this->tCmnSuperGlobals->get('os200') * 2 * $snVal / $mnth), |
||
| 117 | ]; |
||
| 118 | } |
||
| 119 | |||
| 120 | private function getValues($lngBase, $aStngs) |
||
|
|
|||
| 121 | { |
||
| 122 | $inDate = $this->tCmnSuperGlobals->get('ym'); |
||
| 123 | $inDT = new \DateTime(date('Y/m/d', $inDate)); |
||
| 124 | $wkDay = $this->setWorkingDaysInMonth($inDT, $_REQUEST['pc']); |
||
| 125 | $nMealDays = ($wkDay - $_REQUEST['zfb']); |
||
| 126 | $shLbl = [ |
||
| 127 | 'HFP' => 'Health Fund Percentage', |
||
| 128 | 'HFUL' => 'Health Fund Upper Limit', |
||
| 129 | 'HTP' => 'Health Tax Percentage', |
||
| 130 | 'IT' => 'Income Tax', |
||
| 131 | 'MTV' => 'Meal Ticket Value', |
||
| 132 | ]; |
||
| 133 | $unemploymentBase = $lngBase; |
||
| 134 | if ($this->tCmnSuperGlobals->get('ym') < mktime(0, 0, 0, 1, 1, 2008)) { |
||
| 135 | $unemploymentBase = $_REQUEST['sn']; |
||
| 136 | } |
||
| 137 | $aReturn = [ |
||
| 138 | 'ba' => $this->setFoodTicketsValue($inDate, $aStngs[$shLbl['MTV']]) * $nMealDays, |
||
| 139 | 'cas' => $this->setHealthFundTax($inDate, $lngBase, $aStngs[$shLbl['HFP']], $aStngs[$shLbl['HFUL']]), |
||
| 140 | 'sanatate' => $this->setHealthTax($inDate, $lngBase, $aStngs[$shLbl['HTP']]), |
||
| 141 | 'somaj' => $this->setUnemploymentTax($inDate, $unemploymentBase), |
||
| 142 | ]; |
||
| 143 | $pdVal = [ |
||
| 144 | $inDate, |
||
| 145 | ($lngBase + $aReturn['ba']), |
||
| 146 | $_REQUEST['pi'], |
||
| 147 | $aStngs['Personal Deduction'], |
||
| 148 | ]; |
||
| 149 | $aReturn['pd'] = $this->setPersonalDeduction($pdVal[0], $pdVal[1], $pdVal[2], $pdVal[3]); |
||
| 150 | $restArrayToDeduct = [ |
||
| 151 | $aReturn['cas'], |
||
| 152 | $aReturn['sanatate'], |
||
| 153 | $aReturn['somaj'], |
||
| 154 | $aReturn['pd'], |
||
| 155 | ]; |
||
| 156 | $rest = $lngBase - array_sum($restArrayToDeduct); |
||
| 157 | if ($inDate >= mktime(0, 0, 0, 7, 1, 2010)) { |
||
| 158 | $rest += round($aReturn['ba'], -4); |
||
| 159 | if ($inDate >= mktime(0, 0, 0, 10, 1, 2010)) { |
||
| 160 | $aReturn['gbns'] = $_REQUEST['gbns'] * pow(10, 4); |
||
| 161 | $rest += round($aReturn['gbns'], -4); |
||
| 162 | } |
||
| 163 | } |
||
| 164 | $rest += $_REQUEST['afet'] * pow(10, 4); |
||
| 165 | $aReturn['impozit'] = $this->setIncomeTax($inDate, $rest, $aStngs[$shLbl['IT']]); |
||
| 166 | $aReturn['zile'] = $wkDay; |
||
| 167 | return $aReturn; |
||
| 168 | } |
||
| 169 | |||
| 170 | private function handleLocalizationSalariu($appSettings) |
||
| 171 | { |
||
| 172 | if (is_null($this->tCmnSuperGlobals->get('lang')) && is_null($this->tCmnSession->get('lang'))) { |
||
| 173 | $this->tCmnSession->set('lang', $appSettings['Default Language']); |
||
| 174 | } elseif (!is_null($this->tCmnSuperGlobals->get('lang'))) { |
||
| 175 | $this->tCmnSession->set('lang', filter_var($this->tCmnSuperGlobals->get('lang'), FILTER_SANITIZE_STRING)); |
||
| 176 | } |
||
| 177 | /* to avoid potential language injections from other applications that do not applies here */ |
||
| 178 | if (!array_key_exists($this->tCmnSession->get('lang'), $appSettings['Available Languages'])) { |
||
| 179 | $this->tCmnSession->set('lang', $appSettings['Default Language']); |
||
| 180 | } |
||
| 181 | $localizationFile = 'Salariu/locale/' . $this->tCmnSession->get('lang') . '/LC_MESSAGES/salariu.mo'; |
||
| 182 | $translations = new \Gettext\Translations; |
||
| 183 | $translations->addFromMoFile($localizationFile); |
||
| 184 | $this->tApp = new \Gettext\Translator(); |
||
| 185 | $this->tApp->loadTranslations($translations); |
||
| 186 | } |
||
| 187 | |||
| 188 | private function refreshExchangeRatesFile($appSettings) |
||
| 189 | { |
||
| 190 | if ((filemtime($appSettings['Exchange Rate Local']) + 90 * 24 * 60 * 60) < time()) { |
||
| 191 | $fCntnt = file_get_contents($appSettings['Exchange Rate Source']); |
||
| 192 | if ($fCntnt !== false) { |
||
| 193 | file_put_contents($appSettings['Exchange Rate Local'], $fCntnt); |
||
| 194 | chmod($appSettings['Exchange Rate Local'], 0666); |
||
| 195 | } |
||
| 196 | } |
||
| 197 | } |
||
| 198 | |||
| 199 | private function setCurrencyExchangeVariables($aryRelevantCurrencies) |
||
| 200 | { |
||
| 201 | $this->appFlags['currency_exchanges'] = $aryRelevantCurrencies; |
||
| 202 | $this->appFlags['currency_exchange_rate_date'] = strtotime('now'); |
||
| 203 | $krncy = array_keys($this->appFlags['currency_exchanges']); |
||
| 204 | foreach ($krncy as $value) { |
||
| 205 | $this->appFlags['currency_exchange_rate_value'][$value] = 1; |
||
| 206 | } |
||
| 207 | } |
||
| 208 | |||
| 209 | private function setFooterHtml($appSettings) |
||
| 210 | { |
||
| 211 | $sReturn = $this->setUpperRightBoxLanguages($appSettings['Available Languages']) |
||
| 212 | . '<div class="resetOnly author">© ' . date('Y') . ' ' |
||
| 213 | . $appSettings['Copyright Holder'] . '</div>' |
||
| 214 | . '<hr/>' |
||
| 215 | . '<div class="disclaimer">' |
||
| 216 | . $this->tApp->gettext('i18n_Disclaimer') |
||
| 217 | . '</div>'; |
||
| 218 | return $this->setFooterCommon($sReturn); |
||
| 219 | } |
||
| 220 | |||
| 221 | private function setFormInput() |
||
| 222 | { |
||
| 223 | $sReturn = []; |
||
| 224 | $sReturn[] = $this->setFormRow($this->setLabel('ym'), $this->setFormInputSelectYM(), 1); |
||
| 225 | $sReturn[] = $this->setFormRow($this->setLabel('sn'), $this->setFormInputText('sn', 10, 'RON'), 1); |
||
| 226 | $sReturn[] = $this->setFormRow($this->setLabel('sc'), $this->setFormInputText('sc', 2, '%'), 1); |
||
| 227 | $sReturn[] = $this->setFormRow($this->setLabel('pb'), $this->setFormInputText('pb', 10, 'RON'), 1); |
||
| 228 | $sReturn[] = $this->setFormRow($this->setLabel('pn'), $this->setFormInputText('pn', 10, 'RON'), 1); |
||
| 229 | $sReturn[] = $this->setFormRow($this->setLabel('os175'), $this->setFormInputText('os175', 2, ''), 1); |
||
| 230 | $sReturn[] = $this->setFormRow($this->setLabel('os200'), $this->setFormInputText('os200', 2, ''), 1); |
||
| 231 | $sReturn[] = $this->setFormRow($this->setLabel('pi'), $this->setFormInputSelectPI(), 1); |
||
| 232 | $sReturn[] = $this->setFormRow($this->setLabel('pc'), $this->setFormInputSelectPC(), 1); |
||
| 233 | $sReturn[] = $this->setFormRow($this->setLabel('szamnt'), $this->setFormInputText('szamnt', 2, ''), 1); |
||
| 234 | $sReturn[] = $this->setFormRow($this->setLabel('zfb'), $this->setFormInputText('zfb', 2, ''), 1); |
||
| 235 | $sReturn[] = $this->setFormRow($this->setLabel('gbns'), $this->setFormInputText('gbns', 2, ''), 1); |
||
| 236 | $sReturn[] = $this->setFormRow($this->setLabel('afet'), $this->setFormInputText('afet', 2, ''), 1); |
||
| 237 | $label = $this->tApp->gettext('i18n_Form_Disclaimer'); |
||
| 238 | $hiddenField = $this->setStringIntoShortTag('input', [ |
||
| 239 | 'type' => 'hidden', |
||
| 240 | 'name' => 'action', |
||
| 241 | 'value' => $_SERVER['SERVER_NAME'] |
||
| 242 | ]); |
||
| 243 | $sReturn[] = $this->setStringIntoTag($this->setStringIntoTag($label . $hiddenField, 'td', [ |
||
| 244 | 'colspan' => 2, |
||
| 245 | 'style' => 'color: red;' |
||
| 246 | ]), 'tr'); |
||
| 247 | $submitBtnTxt = $this->tApp->gettext('i18n_Form_Button_Recalculate'); |
||
| 248 | $sReturn[] = $this->setFormRow('', $this->setStringIntoShortTag('input', [ |
||
| 249 | 'type' => 'submit', |
||
| 250 | 'id' => 'submit', |
||
| 251 | 'value' => $submitBtnTxt |
||
| 252 | ]), 1); |
||
| 253 | $frm = $this->setStringIntoTag($this->setStringIntoTag(implode('', $sReturn), 'table'), 'form', [ |
||
| 254 | 'method' => 'get', |
||
| 255 | 'action' => $_SERVER['SCRIPT_NAME'] |
||
| 256 | ]); |
||
| 257 | return $this->setStringIntoTag(implode('', [ |
||
| 258 | $this->setStringIntoTag($this->tApp->gettext('i18n_FieldsetLabel_Inputs'), 'legend'), |
||
| 259 | $frm |
||
| 260 | ]), 'fieldset', ['style' => 'float: left;']); |
||
| 261 | } |
||
| 262 | |||
| 263 | private function setFormInputSelectPC() |
||
| 264 | { |
||
| 265 | $choices = [ |
||
| 266 | $this->tApp->gettext('i18n_Form_Label_CatholicEasterFree_ChoiceNo'), |
||
| 267 | $this->tApp->gettext('i18n_Form_Label_CatholicEasterFree_ChoiceYes'), |
||
| 268 | ]; |
||
| 269 | return $this->setArrayToSelect($choices, $this->tCmnSuperGlobals->get('pc'), 'pc', ['size' => 1]); |
||
| 270 | } |
||
| 271 | |||
| 272 | private function setFormInputSelectPI() |
||
| 273 | { |
||
| 274 | $temp2 = []; |
||
| 275 | for ($counter = 0; $counter <= 4; $counter++) { |
||
| 276 | $temp2[$counter] = $counter . ($counter == 4 ? '+' : ''); |
||
| 277 | } |
||
| 278 | return $this->setArrayToSelect($temp2, $this->tCmnSuperGlobals->get('pi'), 'pi', ['size' => 1]); |
||
| 279 | } |
||
| 280 | |||
| 281 | private function setFormInputSelectYM() |
||
| 282 | { |
||
| 283 | $temp = []; |
||
| 284 | for ($counter = date('Y'); $counter >= 2001; $counter--) { |
||
| 285 | for ($counter2 = 12; $counter2 >= 1; $counter2--) { |
||
| 286 | $crtDate = mktime(0, 0, 0, $counter2, 1, $counter); |
||
| 287 | if ($crtDate <= mktime(0, 0, 0, date('m'), 1, date('Y'))) { |
||
| 288 | $temp[$crtDate] = strftime('%Y, %m (%B)', $crtDate); |
||
| 289 | } |
||
| 290 | } |
||
| 291 | } |
||
| 292 | return $this->setArrayToSelect($temp, $this->tCmnSuperGlobals->get('ym'), 'ym', ['size' => 1]); |
||
| 293 | } |
||
| 294 | |||
| 295 | private function setFormInputText($inName, $inSize, $inAfterLabel) |
||
| 296 | { |
||
| 297 | $inputParameters = [ |
||
| 298 | 'type' => 'text', |
||
| 299 | 'name' => $inName, |
||
| 300 | 'value' => $this->tCmnSuperGlobals->get($inName), |
||
| 301 | 'size' => $inSize, |
||
| 302 | 'maxlength' => $inSize, |
||
| 303 | ]; |
||
| 304 | return $this->setStringIntoShortTag('input', $inputParameters) . ' ' . $inAfterLabel; |
||
| 305 | } |
||
| 306 | |||
| 307 | private function setFormOutput($aryStngs) |
||
| 308 | { |
||
| 309 | $sReturn = []; |
||
| 310 | $overtime = $this->getOvertimes($aryStngs['Monthly Average Working Hours']); |
||
| 311 | $additions = $_REQUEST['pb'] + $overtime['os175'] + $overtime['os200']; |
||
| 312 | $brut = ($_REQUEST['sn'] * (1 + $_REQUEST['sc'] / 100) + $additions) * pow(10, 4); |
||
| 313 | $text = $this->tApp->gettext('i18n_Form_Label_ExchangeRateAtDate'); |
||
| 314 | $xRate = str_replace('%1', date('d.m.Y', $this->appFlags['currency_exchange_rate_date']), $text); |
||
| 315 | $sReturn[] = $this->setFormRow($xRate, 1000000); |
||
| 316 | $text = $this->tApp->gettext('i18n_Form_Label_NegotiatedSalary'); |
||
| 317 | $sReturn[] = $this->setFormRow($text, $_REQUEST['sn'] * 10000); |
||
| 318 | $prima = $_REQUEST['sn'] * $_REQUEST['sc'] * 100; |
||
| 319 | $sReturn[] = $this->setFormRow($this->tApp->gettext('i18n_Form_Label_CumulatedAddedValue'), $prima); |
||
| 320 | $text = $this->tApp->gettext('i18n_Form_Label_AdditionalBruttoAmount'); |
||
| 321 | $sReturn[] = $this->setFormRow($text, $_REQUEST['pb'] * 10000); |
||
| 322 | $ovTime = [ |
||
| 323 | 'main' => $this->tApp->gettext('i18n_Form_Label_OvertimeAmount'), |
||
| 324 | 1 => $this->tApp->gettext('i18n_Form_Label_OvertimeChoice1'), |
||
| 325 | 2 => $this->tApp->gettext('i18n_Form_Label_OvertimeChoice2'), |
||
| 326 | ]; |
||
| 327 | $sReturn[] = $this->setFormRow(sprintf($ovTime['main'], $ovTime[1], '175%'), ($overtime['os175'] * pow(10, 4))); |
||
| 328 | $sReturn[] = $this->setFormRow(sprintf($ovTime['main'], $ovTime[2], '200%'), ($overtime['os200'] * pow(10, 4))); |
||
| 329 | $sReturn[] = $this->setFormRow($this->tApp->gettext('i18n_Form_Label_BruttoSalary'), $brut); |
||
| 330 | $brut += $_REQUEST['afet'] * pow(10, 4); |
||
| 331 | $amount = $this->getValues($brut, $aryStngs); |
||
| 332 | $sReturn[] = $this->setFormRow($this->tApp->gettext('i18n_Form_Label_PensionFund'), $amount['cas']); |
||
| 333 | $sReturn[] = $this->setFormRow($this->tApp->gettext('i18n_Form_Label_UnemploymentTax'), $amount['somaj']); |
||
| 334 | $sReturn[] = $this->setFormRow($this->tApp->gettext('i18n_Form_Label_HealthTax'), $amount['sanatate']); |
||
| 335 | $sReturn[] = $this->setFormRow($this->tApp->gettext('i18n_Form_Label_PersonalDeduction'), $amount['pd']); |
||
| 336 | $sReturn[] = $this->setFormRow($this->tApp->gettext('i18n_Form_Label_ExciseTax'), $amount['impozit']); |
||
| 337 | $retineri = $amount['cas'] + $amount['somaj'] + $amount['sanatate'] + $amount['impozit']; |
||
| 338 | $net = $brut - $retineri + $_REQUEST['pn'] * 10000; |
||
| 339 | $text = $this->tApp->gettext('i18n_Form_Label_AdditionalNettoAmount'); |
||
| 340 | $sReturn[] = $this->setFormRow($text, $_REQUEST['pn'] * 10000); |
||
| 341 | $sReturn[] = $this->setFormRow($this->tApp->gettext('i18n_Form_Label_NettoSalary'), $net); |
||
| 342 | $text = $this->tApp->gettext('i18n_Form_Label_SeisureAmout'); |
||
| 343 | $sReturn[] = $this->setFormRow($text, $_REQUEST['szamnt'] * 10000); |
||
| 344 | $text = $this->tApp->gettext('i18n_Form_Label_NettoSalaryCash'); |
||
| 345 | $sReturn[] = $this->setFormRow($text, ($net - $_REQUEST['szamnt'] * 10000)); |
||
| 346 | $sReturn[] = $this->setFormRow($this->tApp->gettext('i18n_Form_Label_WorkingDays'), $amount['zile'], 'value'); |
||
| 347 | $fBonus = [ |
||
| 348 | 'main' => $this->tApp->gettext('i18n_Form_Label_FoodBonuses'), |
||
| 349 | 'no' => $this->tApp->gettext('i18n_Form_Label_FoodBonusesChoiceNo'), |
||
| 350 | 'value' => $this->tApp->gettext('i18n_Form_Label_FoodBonusesChoiceValue') |
||
| 351 | ]; |
||
| 352 | $fBonusTxt = sprintf($fBonus['main'], $fBonus['value'], $fBonus['no'], ($amount['zile'] - $_REQUEST['zfb'])); |
||
| 353 | $sReturn[] = $this->setFormRow($fBonusTxt, $amount['ba']); |
||
| 354 | $sReturn[] = $this->setFormRow($this->tApp->gettext('i18n_Form_Label_FoodBonusesValue'), $amount['gbns']); |
||
| 355 | $total = ($net + $amount['ba'] + $amount['gbns'] - $_REQUEST['szamnt'] * 10000); |
||
| 356 | $sReturn[] = $this->setFormRow($this->tApp->gettext('i18n_Form_Label_Total'), $total); |
||
| 357 | setlocale(LC_TIME, explode('_', $this->tCmnSession->get('lang'))[0]); |
||
| 358 | $crtMonth = strftime('%B', $this->tCmnSuperGlobals->get('ym')); |
||
| 359 | $legend = sprintf($this->tApp->gettext('i18n_FieldsetLabel_Results') |
||
| 360 | . '', $crtMonth, date('Y', $this->tCmnSuperGlobals->get('ym'))); |
||
| 361 | return $this->setStringIntoTag(implode('', [ |
||
| 362 | $this->setStringIntoTag($legend, 'legend'), |
||
| 363 | $this->setStringIntoTag(implode('', $sReturn), 'table') |
||
| 364 | ]), 'fieldset', ['style' => 'float: left;']); |
||
| 365 | } |
||
| 366 | |||
| 367 | private function setFormRow($text, $value, $type = 'amount') |
||
| 368 | { |
||
| 369 | $a = ''; |
||
| 370 | $defaultCellStyle = $this->setFormatRow($text, $value); |
||
| 371 | $defaultCellStyle2 = []; |
||
| 372 | switch ($type) { |
||
| 373 | case 'amount': |
||
| 374 | $value = $value / pow(10, 4); |
||
| 375 | $defaultCellStyle2['style'] = $defaultCellStyle['style'] . 'text-align:right;'; |
||
| 376 | $cellValue = []; |
||
| 377 | foreach ($this->appFlags['currency_exchanges'] as $key2 => $value2) { |
||
| 378 | $fmt = new \NumberFormatter($value2['locale'], \NumberFormatter::CURRENCY); |
||
| 379 | $fmt->setAttribute(\NumberFormatter::FRACTION_DIGITS, $value2['decimals']); |
||
| 380 | $x = $this->appFlags['currency_exchange_rate_value'][$key2]; |
||
| 381 | $finalValue = $fmt->formatCurrency($value / $x, $key2); |
||
| 382 | $cellValue[] = $this->setStringIntoTag($finalValue, 'td', $defaultCellStyle2); |
||
| 383 | } |
||
| 384 | $value2show = implode('', $cellValue); |
||
| 385 | break; |
||
| 386 | case 'value': |
||
| 387 | $defaultCellStyle2 = array_merge($defaultCellStyle, [ |
||
| 388 | 'colspan' => count($this->appFlags['currency_exchanges']) |
||
| 389 | ]); |
||
| 390 | $value2show = $this->setStringIntoTag($value . $a, 'td', $defaultCellStyle2); |
||
| 391 | break; |
||
| 392 | default: |
||
| 393 | $value2show = $this->setStringIntoTag($value, 'td'); |
||
| 394 | break; |
||
| 395 | } |
||
| 396 | if (!in_array($text, ['', ' ']) && (strpos($text, '<input') === false)) { |
||
| 397 | $text .= ':'; |
||
| 398 | } |
||
| 399 | return $this->setStringIntoTag($this->setStringIntoTag($text, 'td', $defaultCellStyle) . $value2show, 'tr'); |
||
| 400 | } |
||
| 401 | |||
| 402 | private function setFormatRow($text, $value) |
||
| 403 | { |
||
| 404 | $defaultCellStyle = [ |
||
| 405 | 'class' => 'labelS', |
||
| 406 | ]; |
||
| 407 | $fieldsStyled = $this->buildArrayOfFieldsStyled(); |
||
| 408 | if (array_key_exists($text, $fieldsStyled)) { |
||
| 409 | $defaultCellStyle['style'] = $this->buildStyleForCellFormat($fieldsStyled[$text]); |
||
| 410 | } |
||
| 411 | if ((is_numeric($value)) && ($value == 0)) { |
||
| 412 | $defaultCellStyle['style'] = 'color:#666;'; |
||
| 413 | } |
||
| 414 | return $defaultCellStyle; |
||
| 415 | } |
||
| 416 | |||
| 417 | private function setHeaderHtml() |
||
| 430 | |||
| 431 | private function setLabel($labelId) |
||
| 448 | } |
||
| 449 |
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: