| Conditions | 4 |
| Paths | 6 |
| Total Lines | 149 |
| Code Lines | 125 |
| Lines | 0 |
| Ratio | 0 % |
| 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 declare(strict_types=1); |
||
| 143 | function adslight_seo_title($title = '', $withExt = false) |
||
| 144 | { |
||
| 145 | /** |
||
| 146 | * if XOOPS ML is present, let's sanitize the title with the current language |
||
| 147 | */ |
||
| 148 | $myts = \MyTextSanitizer::getInstance(); |
||
| 149 | if (method_exists($myts, 'formatForML')) { |
||
| 150 | $title = $myts->formatForML($title); |
||
| 151 | } |
||
| 152 | |||
| 153 | // Transformation de la chaine en minuscule |
||
| 154 | // String encoding to avoid 500 errors in case of unforeseen characters |
||
| 155 | $title = rawurlencode(mb_strtolower($title)); |
||
| 156 | |||
| 157 | // Transformation des ponctuations |
||
| 158 | // Tab Space ! " # % & ' ( ) , / : ; < = > ? @ [ \ ] ^ { | } ~ . + |
||
| 159 | $pattern = [ |
||
| 160 | '/%09/', // Tab |
||
| 161 | '/%20/', // Space |
||
| 162 | '/%21/', // ! |
||
| 163 | '/%22/', // " |
||
| 164 | '/%23/', // # |
||
| 165 | '/%25/', // % |
||
| 166 | '/%26/', // & |
||
| 167 | '/%27/', // ' |
||
| 168 | '/%28/', // ( |
||
| 169 | '/%29/', // ) |
||
| 170 | '/%2C/', // , |
||
| 171 | '/%2F/', // / |
||
| 172 | '/%3A/', // : |
||
| 173 | '/%3B/', // ; |
||
| 174 | '/%3C/', // < |
||
| 175 | '/%3D/', // = |
||
| 176 | '/%3E/', // > |
||
| 177 | '/%3F/', // ? |
||
| 178 | '/%40/', // @ |
||
| 179 | '/%5B/', // [ |
||
| 180 | '/%5C/', // \ |
||
| 181 | '/%5D/', // ] |
||
| 182 | '/%5E/', // ^ |
||
| 183 | '/%7B/', // { |
||
| 184 | '/%7C/', // | |
||
| 185 | '/%7D/', // } |
||
| 186 | '/%7E/', // ~ |
||
| 187 | '/\./', // . |
||
| 188 | '/%2A/', |
||
| 189 | '/%2B/', |
||
| 190 | '/quot/', |
||
| 191 | ]; |
||
| 192 | $rep_pat = [ |
||
| 193 | '-', |
||
| 194 | '-', |
||
| 195 | '', |
||
| 196 | '', |
||
| 197 | '', |
||
| 198 | '-100', |
||
| 199 | '', |
||
| 200 | '-', |
||
| 201 | '', |
||
| 202 | '', |
||
| 203 | '', |
||
| 204 | '-', |
||
| 205 | '', |
||
| 206 | '', |
||
| 207 | '', |
||
| 208 | '-', |
||
| 209 | '', |
||
| 210 | '', |
||
| 211 | '-at-', |
||
| 212 | '', |
||
| 213 | '-', |
||
| 214 | '', |
||
| 215 | '-', |
||
| 216 | '', |
||
| 217 | '-', |
||
| 218 | '', |
||
| 219 | '-', |
||
| 220 | '', |
||
| 221 | '', |
||
| 222 | '+', |
||
| 223 | '', |
||
| 224 | ]; |
||
| 225 | $title = preg_replace($pattern, $rep_pat, $title); |
||
| 226 | |||
| 227 | // Transformation of characters with accents |
||
| 228 | // ° è é ê ë ç à â ä î ï ù ü û ô ö |
||
| 229 | $pattern = [ |
||
| 230 | '/%B0/', // ° |
||
| 231 | '/%E8/', // è |
||
| 232 | '/%E9/', // é |
||
| 233 | '/%EA/', // ê |
||
| 234 | '/%EB/', // ë |
||
| 235 | '/%E7/', // ç |
||
| 236 | '/%E0/', // à |
||
| 237 | '/%E2/', // â |
||
| 238 | '/%E4/', // ä |
||
| 239 | '/%EE/', // î |
||
| 240 | '/%EF/', // ï |
||
| 241 | '/%F9/', // ù |
||
| 242 | '/%FC/', // ü |
||
| 243 | '/%FB/', // û |
||
| 244 | '/%F4/', // ô |
||
| 245 | '/%F6/', // ö |
||
| 246 | '/%E3%A8/', |
||
| 247 | '/%E3%A9/', |
||
| 248 | '/%E3%A0/', |
||
| 249 | '/%E3%AA/', |
||
| 250 | '/%E3%A2/', |
||
| 251 | '/a%80%9C/', |
||
| 252 | '/a%80%9D/', |
||
| 253 | '/%E3%A7/', |
||
| 254 | ]; |
||
| 255 | $rep_pat = [ |
||
| 256 | '-', |
||
| 257 | 'e', |
||
| 258 | 'e', |
||
| 259 | 'e', |
||
| 260 | 'e', |
||
| 261 | 'c', |
||
| 262 | 'a', |
||
| 263 | 'a', |
||
| 264 | 'a', |
||
| 265 | 'i', |
||
| 266 | 'i', |
||
| 267 | 'u', |
||
| 268 | 'u', |
||
| 269 | 'u', |
||
| 270 | 'o', |
||
| 271 | 'o', |
||
| 272 | 'e', |
||
| 273 | 'e', |
||
| 274 | 'a', |
||
| 275 | 'e', |
||
| 276 | 'a', |
||
| 277 | '-', |
||
| 278 | '-', |
||
| 279 | 'c', |
||
| 280 | ]; |
||
| 281 | $title = preg_replace($pattern, $rep_pat, $title); |
||
| 282 | |||
| 283 | if (count($title) > 0) { |
||
| 284 | if ($withExt) { |
||
| 285 | $title .= '.html'; |
||
| 286 | } |
||
| 287 | |||
| 288 | return $title; |
||
| 289 | } |
||
| 290 | |||
| 291 | return ''; |
||
| 292 | } |
||
| 346 |