| Conditions | 4 |
| Paths | 6 |
| Total Lines | 64 |
| Code Lines | 43 |
| 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 |
||
| 42 | public static function getTitle($title = '', $withExt = true) |
||
| 43 | { |
||
| 44 | |||
| 45 | /** |
||
| 46 | * if XOOPS ML is present, let's sanitize the title with the current language |
||
| 47 | */ |
||
| 48 | $myts = \MyTextSanitizer::getInstance(); |
||
| 49 | if (method_exists($myts, 'formatForML')) { |
||
| 50 | $title = $myts->formatForML($title); |
||
| 51 | } |
||
| 52 | |||
| 53 | // Transformation de la chaine en minuscule |
||
| 54 | // Codage de la chaine afin d'éviter les erreurs 500 en cas de caractères imprévus |
||
| 55 | $title = rawurlencode(mb_strtolower($title)); |
||
| 56 | |||
| 57 | // Transformation des ponctuations |
||
| 58 | $pattern = [ |
||
| 59 | '/%09/', // Tab |
||
| 60 | '/%20/', // Space |
||
| 61 | '/%21/', // ! |
||
| 62 | '/%22/', // " |
||
| 63 | '/%23/', // # |
||
| 64 | '/%25/', // % |
||
| 65 | '/%26/', // & |
||
| 66 | '/%27/', // ' |
||
| 67 | '/%28/', // ( |
||
| 68 | '/%29/', // ) |
||
| 69 | '/%2C/', // , |
||
| 70 | '/%2F/', // / |
||
| 71 | '/%3A/', // : |
||
| 72 | '/%3B/', // ; |
||
| 73 | '/%3C/', // < |
||
| 74 | '/%3D/', // = |
||
| 75 | '/%3E/', // > |
||
| 76 | '/%3F/', // ? |
||
| 77 | '/%40/', // @ |
||
| 78 | '/%5B/', // [ |
||
| 79 | '/%5C/', // \ |
||
| 80 | '/%5D/', // ] |
||
| 81 | '/%5E/', // ^ |
||
| 82 | '/%7B/', // { |
||
| 83 | '/%7C/', // | |
||
| 84 | '/%7D/', // } |
||
| 85 | '/%7E/', // ~ |
||
| 86 | "/\./", // . |
||
| 87 | ]; |
||
| 88 | $repPattern = ['-', '-', '', '', '', '-100', '', '-', '', '', '', '-', '', '', '', '-', '', '', '-at-', '', '-', '', '-', '', '-', '', '-', '']; |
||
| 89 | $title = preg_replace($pattern, $repPattern, $title); |
||
| 90 | |||
| 91 | // Transformation des caractères accentués |
||
| 92 | // è é ê ë ç à â ä î ï ù ü û ô ö |
||
| 93 | $pattern = ['/%B0/', '/%E8/', '/%E9/', '/%EA/', '/%EB/', '/%E7/', '/%E0/', '/%E2/', '/%E4/', '/%EE/', '/%EF/', '/%F9/', '/%FC/', '/%FB/', '/%F4/', '/%F6/']; |
||
| 94 | $repPattern = ['-', 'e', 'e', 'e', 'e', 'c', 'a', 'a', 'a', 'i', 'i', 'u', 'u', 'u', 'o', 'o']; |
||
| 95 | $title = preg_replace($pattern, $repPattern, $title); |
||
| 96 | |||
| 97 | if (count($title) > 0) { |
||
|
|
|||
| 98 | if ($withExt) { |
||
| 99 | $title .= '.html'; |
||
| 100 | } |
||
| 101 | |||
| 102 | return $title; |
||
| 103 | } |
||
| 104 | |||
| 105 | return ''; |
||
| 106 | } |
||
| 147 |