|
2 | 2 |
|
3 | 3 | namespace Mindee\Parsing\V2\Field; |
4 | 4 |
|
5 | | -use InvalidArgumentException; |
6 | | - |
7 | | -/** |
8 | | - * Confidence level of a field as returned by the V2 API. |
9 | | - */ |
10 | | -class FieldConfidence |
| 5 | +enum FieldConfidence: string |
11 | 6 | { |
12 | | - public const CERTAIN = 'Certain'; |
13 | | - public const HIGH = 'High'; |
14 | | - public const MEDIUM = 'Medium'; |
15 | | - public const LOW = 'Low'; |
16 | | - |
17 | | - /** |
18 | | - * @var string |
19 | | - */ |
20 | | - private string $value; |
21 | | - |
22 | | - /** |
23 | | - * @param string $value Vale provided. |
24 | | - * @throws InvalidArgumentException Throws if an invalid value is provided. |
25 | | - */ |
26 | | - public function __construct(string $value) |
27 | | - { |
28 | | - if (!self::isValid($value)) { |
29 | | - throw new InvalidArgumentException(sprintf( |
30 | | - 'Invalid confidence value "%s". Valid values are: %s', |
31 | | - $value, |
32 | | - implode(', ', self::getValidValues()) |
33 | | - )); |
34 | | - } |
35 | | - $this->value = $value; |
36 | | - } |
37 | | - |
38 | | - /** |
39 | | - * @param string $value Value to check. |
40 | | - * @return boolean True if the value is valid. |
41 | | - */ |
42 | | - public static function isValid(string $value): bool |
43 | | - { |
44 | | - return in_array($value, self::getValidValues(), true); |
45 | | - } |
46 | | - |
47 | | - /** |
48 | | - * @return array<string> |
49 | | - */ |
50 | | - public static function getValidValues(): array |
51 | | - { |
52 | | - return [ |
53 | | - self::CERTAIN, |
54 | | - self::HIGH, |
55 | | - self::MEDIUM, |
56 | | - self::LOW, |
57 | | - ]; |
58 | | - } |
59 | | - |
60 | | - /** |
61 | | - * @return string String representation. |
62 | | - */ |
63 | | - public function getValue(): string |
64 | | - { |
65 | | - return $this->value; |
66 | | - } |
67 | | - |
68 | | - /** |
69 | | - * @return string |
70 | | - */ |
71 | | - public function __toString(): string |
72 | | - { |
73 | | - return $this->value; |
74 | | - } |
| 7 | + case Certain = 'Certain'; |
| 8 | + case High = 'High'; |
| 9 | + case Medium = 'Medium'; |
| 10 | + case Low = 'Low'; |
75 | 11 | } |
0 commit comments