| Conditions | 17 |
| Paths | 594 |
| Total Lines | 61 |
| Code Lines | 36 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 120 | private function convertNumber($number, $miMoneda = null, string $type = 'entero') |
||
| 121 | { |
||
| 122 | |||
| 123 | $converted = ''; |
||
| 124 | $moneda = ''; |
||
| 125 | if ($miMoneda !== null) { |
||
| 126 | try { |
||
| 127 | $moneda = array_filter($this->MONEDAS, static function ($m) use ($miMoneda) { |
||
| 128 | return ($m['currency'] === $miMoneda); |
||
| 129 | }); |
||
| 130 | |||
| 131 | $moneda = array_values($moneda); |
||
| 132 | |||
| 133 | if (count($moneda) <= 0) { |
||
| 134 | throw new Exception("Tipo de moneda inválido"); |
||
| 135 | //return; |
||
| 136 | } |
||
| 137 | ($number < 2 ? $moneda = $moneda[0]['singular'] : $moneda = $moneda[0]['plural']); |
||
| 138 | } catch (Exception $e) { |
||
| 139 | echo $e->getMessage(); |
||
| 140 | //return; |
||
| 141 | } |
||
| 142 | } |
||
| 143 | |||
| 144 | if (($number < 0) || ($number > 999999999)) { |
||
| 145 | return ($type === 'decimal')?' 00/100' : ''; |
||
| 146 | } |
||
| 147 | |||
| 148 | $numberStr = (string) $number; |
||
| 149 | $numberStrFill = str_pad($numberStr, 9, '0', STR_PAD_LEFT); |
||
| 150 | $millones = substr($numberStrFill, 0, 3); |
||
| 151 | $miles = substr($numberStrFill, 3, 3); |
||
| 152 | $cientos = substr($numberStrFill, 6); |
||
| 153 | |||
| 154 | if ($millones > 0) { |
||
| 155 | if ($millones === '001') { |
||
| 156 | $converted .= 'UN MILLON '; |
||
| 157 | } elseif ($millones > 0) { |
||
| 158 | $converted .= sprintf('%sMILLONES ', $this->convertGroup($millones)); |
||
| 159 | } |
||
| 160 | } |
||
| 161 | |||
| 162 | if ($miles > 0) { |
||
| 163 | if ($miles === '001') { |
||
| 164 | $converted .= 'MIL '; |
||
| 165 | } elseif ($miles > 0) { |
||
| 166 | $converted .= sprintf('%sMIL ', $this->convertGroup($miles)); |
||
| 167 | } |
||
| 168 | } |
||
| 169 | |||
| 170 | if ($cientos > 0) { |
||
| 171 | if ($cientos === '001') { |
||
| 172 | $converted .= 'UN '; |
||
| 173 | } elseif ($cientos > 0) { |
||
| 174 | $converted .= sprintf('%s ', $this->convertGroup($cientos)); |
||
| 175 | } |
||
| 176 | } |
||
| 177 | |||
| 178 | $converted .= $moneda; |
||
| 179 | |||
| 180 | return $converted; |
||
| 181 | } |
||
| 209 | } |