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 |
||
125 | public function format(): string |
||
126 | { |
||
127 | if ($this->localeFormat !== null) { |
||
128 | return $this->localeFormat; |
||
129 | } |
||
130 | $symbolWithSpacing = $this->overrideSpacing ?? ($this->currencySymbolSpacing === self::SYMBOL_WITH_SPACING); |
||
131 | $negative = $this->overrideNegative ?? $this->negative; |
||
132 | |||
133 | // format if positive |
||
134 | $format = '_('; |
||
135 | if ($this->currencySymbolPosition === self::LEADING_SYMBOL) { |
||
136 | $format .= '"' . $this->currencyCode . '"'; |
||
137 | if (preg_match('/^[A-Z]{3}$/i', $this->currencyCode) === 1) { |
||
138 | $format .= $this->spaceOrNbsp; |
||
139 | } |
||
140 | if (preg_match('/^[A-Z]{3}$/i', $this->currencyCode) === 1) { |
||
141 | $format .= $this->spaceOrNbsp; |
||
142 | } |
||
143 | if ($symbolWithSpacing) { |
||
144 | $format .= '*' . $this->spaceOrNbsp; |
||
145 | } |
||
146 | } |
||
147 | $format .= $this->thousandsSeparator ? '#,##0' : '0'; |
||
148 | if ($this->decimals > 0) { |
||
149 | $format .= '.' . str_repeat('0', $this->decimals); |
||
150 | } |
||
151 | if ($this->currencySymbolPosition === self::TRAILING_SYMBOL) { |
||
152 | if ($symbolWithSpacing) { |
||
153 | $format .= $this->spaceOrNbsp; |
||
154 | } elseif (preg_match('/^[A-Z]{3}$/i', $this->currencyCode) === 1) { |
||
155 | $format .= $this->spaceOrNbsp; |
||
156 | } |
||
157 | $format .= '[$' . $this->currencyCode . ']'; |
||
158 | } |
||
159 | $format .= '_)'; |
||
160 | |||
161 | // format if negative |
||
162 | $format .= ';_('; |
||
163 | $format .= $negative->color(); |
||
164 | $negativeStart = $negative->start(); |
||
165 | if ($this->currencySymbolPosition === self::LEADING_SYMBOL) { |
||
166 | if ($negativeStart === '-' && !$symbolWithSpacing) { |
||
167 | $format .= $negativeStart; |
||
168 | } |
||
169 | $format .= '"' . $this->currencyCode . '"'; |
||
170 | if (preg_match('/^[A-Z]{3}$/i', $this->currencyCode) === 1) { |
||
171 | $format .= $this->spaceOrNbsp; |
||
172 | } |
||
173 | if ($symbolWithSpacing) { |
||
174 | $format .= '*' . $this->spaceOrNbsp; |
||
175 | } |
||
176 | if ($negativeStart === '\\(' || ($symbolWithSpacing && $negativeStart === '-')) { |
||
177 | $format .= $negativeStart; |
||
178 | } |
||
179 | } else { |
||
180 | $format .= $negative->start(); |
||
181 | } |
||
182 | $format .= $this->thousandsSeparator ? '#,##0' : '0'; |
||
183 | if ($this->decimals > 0) { |
||
184 | $format .= '.' . str_repeat('0', $this->decimals); |
||
185 | } |
||
186 | $format .= $negative->end(); |
||
187 | if ($this->currencySymbolPosition === self::TRAILING_SYMBOL) { |
||
188 | if ($symbolWithSpacing) { |
||
189 | // Do nothing - I can't figure out how to get |
||
190 | // everything to align if I put any kind of space here. |
||
191 | //$format .= "\u{2009}"; |
||
192 | } elseif (preg_match('/^[A-Z]{3}$/i', $this->currencyCode) === 1) { |
||
193 | $format .= $this->spaceOrNbsp; |
||
194 | } |
||
195 | $format .= '[$' . $this->currencyCode . ']'; |
||
196 | } |
||
197 | if ($this->currencySymbolPosition === self::TRAILING_SYMBOL) { |
||
198 | $format .= '_)'; |
||
199 | } elseif ($symbolWithSpacing && $negativeStart === '-') { |
||
200 | $format .= ' '; |
||
201 | } |
||
202 | // format if zero |
||
203 | $format .= ';_('; |
||
204 | if ($this->currencySymbolPosition === self::LEADING_SYMBOL) { |
||
205 | $format .= '"' . $this->currencyCode . '"'; |
||
206 | } |
||
207 | if ($symbolWithSpacing) { |
||
208 | if ($this->currencySymbolPosition === self::LEADING_SYMBOL) { |
||
209 | $format .= '*' . $this->spaceOrNbsp; |
||
210 | } |
||
211 | $format .= '"-"'; |
||
212 | if ($this->decimals > 0) { |
||
213 | $format .= str_repeat('?', $this->decimals); |
||
214 | } |
||
215 | } else { |
||
216 | if (preg_match('/^[A-Z]{3}$/i', $this->currencyCode) === 1) { |
||
217 | $format .= $this->spaceOrNbsp; |
||
218 | } |
||
219 | $format .= '0'; |
||
220 | if ($this->decimals > 0) { |
||
221 | $format .= '.' . str_repeat('0', $this->decimals); |
||
222 | } |
||
223 | } |
||
224 | if ($this->currencySymbolPosition === self::TRAILING_SYMBOL) { |
||
225 | if ($symbolWithSpacing) { |
||
226 | $format .= $this->spaceOrNbsp; |
||
227 | } |
||
228 | $format .= '[$' . $this->currencyCode . ']'; |
||
229 | } |
||
230 | $format .= '_)'; |
||
231 | // format if text |
||
232 | $format .= ';_(@_)'; |
||
233 | |||
234 | return $format; |
||
235 | } |
||
237 |