Total Complexity | 8 |
Total Lines | 40 |
Duplicated Lines | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php declare(strict_types=1); |
||
13 | final class KeysMatch implements Satisfiable |
||
14 | { |
||
15 | private $canMatchWith; |
||
16 | |||
17 | private function __construct(array ...$canMatchWith) |
||
18 | { |
||
19 | $this->canMatchWith = $canMatchWith; |
||
20 | } |
||
21 | |||
22 | /** |
||
23 | * Produces a constraint that is satisfied with data that contains all the |
||
24 | * key/value pairs in one of the given key/value pair sets. |
||
25 | * |
||
26 | * @param array ...$canMatchWith The key/value pair sets. |
||
27 | * @return Satisfiable The constraint. |
||
28 | */ |
||
29 | public static function withEitherOf(array ...$canMatchWith): Satisfiable |
||
30 | { |
||
31 | return new self(...$canMatchWith); |
||
32 | } |
||
33 | |||
34 | /** @inheritdoc */ |
||
35 | public function isSatisfiedBy($knownData): bool |
||
36 | { |
||
37 | foreach ($this->canMatchWith as $set) { |
||
38 | if ($this->matches($knownData, $set)) { |
||
39 | return true; |
||
40 | } |
||
41 | } |
||
42 | return false; |
||
43 | } |
||
44 | |||
45 | private function matches(array $knownData, array $set): bool |
||
53 | } |
||
54 | } |
||
55 |