| Conditions | 4 |
| Paths | 4 |
| Total Lines | 22 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 9 |
| CRAP Score | 4.25 |
| Changes | 0 | ||
| 1 | <?php |
||
| 26 | 4 | public static function create(string $source, string $postfix = '.html'): string |
|
| 27 | { |
||
| 28 | 4 | $slug = \transliterator_transliterate(static::OPTIONS, $source); |
|
| 29 | |||
| 30 | 4 | if (false === $slug) { |
|
| 31 | throw new \InvalidArgumentException(sprintf('Incorrect source string "%s".', $source)); |
||
| 32 | } |
||
| 33 | |||
| 34 | 4 | $slug = \strtr($slug, static::MAP); |
|
| 35 | 4 | $slug = \preg_replace('#^\-|[^a-z0-9\-]|\-$#', '', $slug); |
|
| 36 | |||
| 37 | 4 | if (false === \is_string($slug)) { |
|
|
|
|||
| 38 | throw new \RuntimeException(sprintf('Can not remove special chars from "%s".', $source)); |
||
| 39 | } |
||
| 40 | |||
| 41 | 4 | $slug = \preg_replace('#(\-+)#', '-', $slug); |
|
| 42 | |||
| 43 | 4 | if (false === \is_string($slug)) { |
|
| 44 | throw new \RuntimeException(sprintf('Can not remove "-" duplicates "%s".', $source)); |
||
| 45 | } |
||
| 46 | |||
| 47 | 4 | return $slug . $postfix; |
|
| 48 | } |
||
| 50 |