| Conditions | 5 |
| Paths | 2 |
| Total Lines | 34 |
| Code Lines | 18 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 40 | public function fetchSuffixes(bool $force = false): void |
||
| 41 | { |
||
| 42 | if (null === $this->cache || true === $force) { |
||
| 43 | $content = $this->client->get($this->listUrl)->getBody(); |
||
| 44 | // Create an iterator for the document |
||
| 45 | $iterator = (function (string $content) { |
||
| 46 | $tok = strtok($content, "\r\n"); |
||
| 47 | while (false !== $tok) { |
||
| 48 | $line = $tok; |
||
| 49 | $tok = strtok("\r\n"); |
||
| 50 | |||
| 51 | // Remove "*." prefixes |
||
| 52 | if (0 === strpos($line, '*.')) { |
||
| 53 | $line = substr($line, 2, mb_strlen($line) - 2); |
||
| 54 | } |
||
| 55 | |||
| 56 | yield $line; |
||
| 57 | } |
||
| 58 | })($content); |
||
| 59 | |||
| 60 | // Ignore commented lines |
||
| 61 | $valid = function (string $string) { |
||
| 62 | return 0 !== strpos($string, '//'); |
||
| 63 | }; |
||
| 64 | $suffixes = iterator_to_array(new CallbackFilterIterator($iterator, $valid)); |
||
| 65 | |||
| 66 | // Sort by suffix length |
||
| 67 | usort($suffixes, function ($a, $b) { |
||
| 68 | return mb_strlen($b) <=> mb_strlen($a); |
||
| 69 | }); |
||
| 70 | |||
| 71 | $this->cache = $suffixes; |
||
| 72 | } |
||
| 73 | } |
||
| 74 | |||
| 84 |