Lines 100.00% 5 / 5
Functions and Methods 100.00% 5 / 5
Classes and Traits 100.00% 1 / 1
Name Lines Functions and Methods CRAP Classes and Traits
OptionNameMatch 100.00% 5 / 5 100.00% 5 / 5 5 100.00% 1 / 1
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 matched 100.00% 1 / 1 100.00% 1 / 1 1
 ambiguous 100.00% 1 / 1 100.00% 1 / 1 1
 unmatched 100.00% 1 / 1 100.00% 1 / 1 1
 isAmbiguous 100.00% 1 / 1 100.00% 1 / 1 1
1<?php
2
3declare(strict_types=1);
4
5namespace Stewart\Support\Text;
6
7/** @internal */
8final readonly class OptionNameMatch
9{
10    /** @param list<string> $candidates */
11    private function __construct(
12        public ?string $parameter,
13        public array $candidates,
14        public ?string $suggestion,
15    ) {}
16
17    public static function matched(string $parameter): self
18    {
19        return new self($parameter, [$parameter], null);
20    }
21
22    /** @param list<string> $candidates */
23    public static function ambiguous(array $candidates): self
24    {
25        return new self(null, $candidates, null);
26    }
27
28    public static function unmatched(?string $suggestion): self
29    {
30        return new self(null, [], $suggestion);
31    }
32
33    public function isAmbiguous(): bool
34    {
35        return \count($this->candidates) > 1;
36    }
37}