Lines
100.00%
5 / 5
Methods
100.00%
3 / 3
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| matches | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| exactEntries | 100.00% | 3 / 3 | 100.00% | 1 / 1 | 1 | ||
| 12 | final readonly class KeyPatterns | |
| 13 | { | |
| 14 | private SelectorCollection $selectors; | |
| 15 | ||
| 16 | /** | |
| 17 | * @param list<string> $patterns | |
| 18 | * @throws SelectorException | |
| 19 | */ | |
| 20 | public function __construct(array $patterns = []) | |
| 21 | { | |
| 22 | $this->selectors = SelectorCollection::fromSpecs(...$patterns); | |
| 23 | } | |
| 24 | ||
| 25 | public function matches(string $key): bool | |
| 26 | { | |
| 27 | return $this->selectors->anyMatches($key); | |
| 28 | } | |
| 29 | ||
| 30 | /** @return list<string> */ | |
| 31 | public function exactEntries(): array | |
| 32 | { | |
| 33 | return $this->selectors | |
| 34 | ->filter(static fn(Selector $selector): bool => $selector->getKind() === SelectorKind::Exact) | |
| 35 | ->mapToList(static fn(Selector $selector): string => $selector->getPattern()); | |
| 36 | } | |
| 37 | } |