| Total Complexity | 6 |
| Total Lines | 60 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 17 | class Meta implements MetaInterface |
||
| 18 | { |
||
| 19 | /** |
||
| 20 | * @var Map |
||
| 21 | */ |
||
| 22 | private $constants; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @var Set |
||
| 26 | */ |
||
| 27 | private $values; |
||
| 28 | |||
| 29 | |||
| 30 | /** |
||
| 31 | * Meta constructor. |
||
| 32 | * |
||
| 33 | * @param array $constants |
||
| 34 | * |
||
| 35 | * @throws SizeMismatchException |
||
| 36 | */ |
||
| 37 | public function __construct(array $constants) |
||
| 38 | { |
||
| 39 | $this->constants = new Map($constants); |
||
| 40 | $this->values = new Set($this->constants->values()->toArray()); |
||
| 41 | |||
| 42 | if ($this->constants->keys()->size() !== $this->values->size()) { |
||
| 43 | throw new SizeMismatchException(); |
||
| 44 | } |
||
| 45 | } |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @param mixed $value |
||
| 49 | * @return bool |
||
| 50 | */ |
||
| 51 | public function isValid($value): bool |
||
| 52 | { |
||
| 53 | return $this->values->contains($value); |
||
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @param mixed $value |
||
| 58 | * @return string |
||
| 59 | * @throws MissingValueException |
||
| 60 | */ |
||
| 61 | public function getConstantName($value): string |
||
| 69 | } |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @return Map |
||
| 73 | */ |
||
| 74 | public function getConstants(): Map |
||
| 79 |