Conditions | 35 |
Paths | > 20000 |
Total Lines | 110 |
Code Lines | 73 |
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 |
||
149 | public function format(): string |
||
150 | { |
||
151 | if ($this->localeFormat !== null) { |
||
152 | return $this->localeFormat; |
||
153 | } |
||
154 | $symbolWithSpacing = $this->overrideSpacing ?? ($this->currencySymbolSpacing === self::SYMBOL_WITH_SPACING); |
||
155 | $negative = $this->overrideNegative ?? $this->negative; |
||
156 | |||
157 | // format if positive |
||
158 | $format = '_('; |
||
159 | if ($this->currencySymbolPosition === self::LEADING_SYMBOL) { |
||
160 | $format .= '"' . $this->currencyCode . '"'; |
||
161 | if (preg_match('/^[A-Z]{3}$/i', $this->currencyCode) === 1) { |
||
162 | $format .= $this->spaceOrNbsp; |
||
163 | } |
||
164 | if (preg_match('/^[A-Z]{3}$/i', $this->currencyCode) === 1) { |
||
165 | $format .= $this->spaceOrNbsp; |
||
166 | } |
||
167 | if ($symbolWithSpacing) { |
||
168 | $format .= '*' . $this->spaceOrNbsp; |
||
169 | } |
||
170 | } |
||
171 | $format .= $this->thousandsSeparator ? '#,##0' : '0'; |
||
172 | if ($this->decimals > 0) { |
||
173 | $format .= '.' . str_repeat('0', $this->decimals); |
||
174 | } |
||
175 | if ($this->currencySymbolPosition === self::TRAILING_SYMBOL) { |
||
176 | if ($symbolWithSpacing) { |
||
177 | $format .= $this->spaceOrNbsp; |
||
178 | } elseif (preg_match('/^[A-Z]{3}$/i', $this->currencyCode) === 1) { |
||
179 | $format .= $this->spaceOrNbsp; |
||
180 | } |
||
181 | $format .= '[$' . $this->currencyCode . ']'; |
||
182 | } |
||
183 | $format .= '_)'; |
||
184 | |||
185 | // format if negative |
||
186 | $format .= ';_('; |
||
187 | $format .= self::NEGATIVE_COLOR[$negative] ?? ''; |
||
188 | $negativeStart = self::NEGATIVE_START[$negative] ?? ''; |
||
189 | if ($this->currencySymbolPosition === self::LEADING_SYMBOL) { |
||
190 | if ($negativeStart === '-' && !$symbolWithSpacing) { |
||
191 | $format .= $negativeStart; |
||
192 | } |
||
193 | $format .= '"' . $this->currencyCode . '"'; |
||
194 | if (preg_match('/^[A-Z]{3}$/i', $this->currencyCode) === 1) { |
||
195 | $format .= $this->spaceOrNbsp; |
||
196 | } |
||
197 | if ($symbolWithSpacing) { |
||
198 | $format .= '*' . $this->spaceOrNbsp; |
||
199 | } |
||
200 | if ($negativeStart === '\\(' || ($symbolWithSpacing && $negativeStart === '-')) { |
||
201 | $format .= $negativeStart; |
||
202 | } |
||
203 | } else { |
||
204 | $format .= self::NEGATIVE_START[$negative] ?? ''; |
||
205 | } |
||
206 | $format .= $this->thousandsSeparator ? '#,##0' : '0'; |
||
207 | if ($this->decimals > 0) { |
||
208 | $format .= '.' . str_repeat('0', $this->decimals); |
||
209 | } |
||
210 | $format .= self::NEGATIVE_END[$negative] ?? ''; |
||
211 | if ($this->currencySymbolPosition === self::TRAILING_SYMBOL) { |
||
212 | if ($symbolWithSpacing) { |
||
213 | // Do nothing - I can't figure out how to get |
||
214 | // everything to align if I put any kind of space here. |
||
215 | //$format .= "\u{2009}"; |
||
216 | } elseif (preg_match('/^[A-Z]{3}$/i', $this->currencyCode) === 1) { |
||
217 | $format .= $this->spaceOrNbsp; |
||
218 | } |
||
219 | $format .= '[$' . $this->currencyCode . ']'; |
||
220 | } |
||
221 | if ($this->currencySymbolPosition === self::TRAILING_SYMBOL) { |
||
222 | $format .= '_)'; |
||
223 | } elseif ($symbolWithSpacing && $negativeStart === '-') { |
||
224 | $format .= ' '; |
||
225 | } |
||
226 | // format if zero |
||
227 | $format .= ';_('; |
||
228 | if ($this->currencySymbolPosition === self::LEADING_SYMBOL) { |
||
229 | $format .= '"' . $this->currencyCode . '"'; |
||
230 | } |
||
231 | if ($symbolWithSpacing) { |
||
232 | if ($this->currencySymbolPosition === self::LEADING_SYMBOL) { |
||
233 | $format .= '*' . $this->spaceOrNbsp; |
||
234 | } |
||
235 | $format .= '"-"'; |
||
236 | if ($this->decimals > 0) { |
||
237 | $format .= str_repeat('?', $this->decimals); |
||
238 | } |
||
239 | } else { |
||
240 | if (preg_match('/^[A-Z]{3}$/i', $this->currencyCode) === 1) { |
||
241 | $format .= $this->spaceOrNbsp; |
||
242 | } |
||
243 | $format .= '0'; |
||
244 | if ($this->decimals > 0) { |
||
245 | $format .= '.' . str_repeat('0', $this->decimals); |
||
246 | } |
||
247 | } |
||
248 | if ($this->currencySymbolPosition === self::TRAILING_SYMBOL) { |
||
249 | if ($symbolWithSpacing) { |
||
250 | $format .= $this->spaceOrNbsp; |
||
251 | } |
||
252 | $format .= '[$' . $this->currencyCode . ']'; |
||
253 | } |
||
254 | $format .= '_)'; |
||
255 | // format if text |
||
256 | $format .= ';_(@_)'; |
||
257 | |||
258 | return $format; |
||
259 | } |
||
261 |