| Conditions | 8 |
| Paths | 12 |
| Total Lines | 26 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 22 | public static function getHumanReadableIdentifier(string $text): string |
||
| 23 | { |
||
| 24 | $lowercase = strtolower($text); |
||
| 25 | |||
| 26 | $result = ''; |
||
| 27 | for ($i = 0; $i < strlen($text); ++$i) { |
||
| 28 | $character = $lowercase[$i]; |
||
| 29 | //0-9, a-z |
||
| 30 | if (($character >= 48 && $character <= 57) || |
||
| 31 | ($character >= 97 && $character <= 122)) { |
||
| 32 | $result .= $character; |
||
| 33 | } else { |
||
| 34 | $result .= '-'; |
||
| 35 | } |
||
| 36 | } |
||
| 37 | |||
| 38 | if (strlen($result) > 100) { |
||
| 39 | $result = substr($result, 0, 100); // make max length |
||
| 40 | $result = substr($result, 0, strrpos($result, '-')); // cut off last word |
||
| 41 | } |
||
| 42 | |||
| 43 | if (strlen($result) < 10) { |
||
| 44 | $result .= RandomHelper::generateHumanReadableRandom(10, '-'); |
||
| 45 | } |
||
| 46 | |||
| 47 | return $result; |
||
| 48 | } |
||
| 50 |