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