| Conditions | 9 |
| Paths | 5 |
| Total Lines | 38 |
| Code Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 20 |
| CRAP Score | 9 |
| Changes | 0 | ||
| 1 | <?php |
||
| 26 | 5 | public function resolve(string $ident, iterable $options = null): Svg |
|
| 27 | { |
||
| 28 | 5 | $tokens = preg_split('@\s+@', mb_strtolower($ident)); |
|
| 29 | 5 | $tokens[] = FontAwesome::DEFAULT_PREFIX; // Add default prefix as fallback |
|
| 30 | |||
| 31 | 5 | $errors = []; |
|
| 32 | |||
| 33 | 5 | foreach ($tokens as $prefix) { |
|
| 34 | 5 | $style = FontAwesome::PREFIXES[$prefix] ?? null; |
|
| 35 | 5 | if (null === $style) { |
|
| 36 | 4 | continue; // Ignore tokens that are *not* a known prefix |
|
| 37 | } |
||
| 38 | |||
| 39 | 5 | foreach ($tokens as $name) { |
|
| 40 | 5 | if (isset(FontAwesome::PREFIXES[$name])) { |
|
| 41 | 4 | continue; // Ignore tokens that are a known prefix |
|
| 42 | } |
||
| 43 | |||
| 44 | 5 | $name = (0 === mb_strpos($name, 'fa-')) ? mb_substr($name, 3) : $name; |
|
| 45 | 5 | if (empty($name)) { |
|
| 46 | continue; // @codeCoverageIgnore |
||
| 47 | } |
||
| 48 | |||
| 49 | 5 | $path = sprintf('%s/%s', $style, $name); |
|
| 50 | 5 | if (array_key_exists($path, $errors)) { |
|
| 51 | 1 | continue; |
|
| 52 | } |
||
| 53 | |||
| 54 | try { |
||
| 55 | 5 | return new Icon($this->findPath($path), $options); |
|
| 56 | 3 | } catch (LoaderException $err) { |
|
| 57 | 3 | $errors[sprintf('%s/%s', $style, $name)] = $err; |
|
| 58 | } |
||
| 59 | } |
||
| 60 | } |
||
| 61 | |||
| 62 | // Could not resolve |
||
| 63 | 3 | throw new LoaderException($ident, new \ReflectionClass(__CLASS__), null, 0, $errors); |
|
| 64 | } |
||
| 66 |