Conditions | 18 |
Paths | 270 |
Total Lines | 43 |
Code Lines | 27 |
Lines | 6 |
Ratio | 13.95 % |
Changes | 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 |
||
134 | private function normalize($str, $opts) |
||
135 | { |
||
136 | if ($opts['nfc'] || $opts['nfkc']) { |
||
137 | if (class_exists('Normalizer', false)) { |
||
138 | View Code Duplication | if ($opts['nfc'] && ! Normalizer::isNormalized($str, Normalizer::FORM_C)) { |
|
139 | $str = Normalizer::normalize($str, Normalizer::FORM_C); |
||
140 | } |
||
141 | View Code Duplication | if ($opts['nfkc'] && ! Normalizer::isNormalized($str, Normalizer::FORM_KC)) { |
|
142 | $str = Normalizer::normalize($str, Normalizer::FORM_KC); |
||
143 | } |
||
144 | } else { |
||
145 | if (! class_exists('I18N_UnicodeNormalizer', false)) { |
||
146 | include_once 'I18N/UnicodeNormalizer.php'; |
||
147 | } |
||
148 | if (class_exists('I18N_UnicodeNormalizer', false)) { |
||
149 | $normalizer = new I18N_UnicodeNormalizer(); |
||
150 | if ($opts['nfc']) { |
||
151 | $str = $normalizer->normalize($str, 'NFC'); |
||
152 | } |
||
153 | if ($opts['nfkc']) { |
||
154 | $str = $normalizer->normalize($str, 'NFKC'); |
||
155 | } |
||
156 | } |
||
157 | } |
||
158 | } |
||
159 | if ($opts['umlauts']) { |
||
160 | if (strpos($str = htmlentities($str, ENT_QUOTES, 'UTF-8'), '&') !== false) { |
||
161 | $str = html_entity_decode(preg_replace('~&([a-z]{1,2})(?:acute|cedil|circ|grave|lig|orn|ring|slash|tilde|uml);~i', '$1', $str), ENT_QUOTES, 'utf-8'); |
||
162 | } |
||
163 | } |
||
164 | if ($opts['convmap'] && is_array($opts['convmap'])) { |
||
165 | $str = strtr($str, $opts['convmap']); |
||
166 | } |
||
167 | if ($opts['lowercase']) { |
||
168 | if (function_exists('mb_strtolower')) { |
||
169 | $str = mb_strtolower($str, 'UTF-8'); |
||
170 | } else { |
||
171 | $str = strtolower($str); |
||
172 | } |
||
173 | } |
||
174 | |||
175 | return $str; |
||
176 | } |
||
177 | } |
||
178 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.