| Total Complexity | 7 |
| Total Lines | 47 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 6 | class ContainsAtLeastOneConstraint extends Constraint |
||
| 7 | { |
||
| 8 | /** |
||
| 9 | * @var array |
||
| 10 | */ |
||
| 11 | private $members; |
||
| 12 | |||
| 13 | 62 | public function __construct(array $members) |
|
| 14 | { |
||
| 15 | 62 | $this->members = $members; |
|
| 16 | 62 | } |
|
| 17 | |||
| 18 | /** |
||
| 19 | * Returns a string representation of the constraint. |
||
| 20 | */ |
||
| 21 | 7 | public function toString() : string |
|
| 22 | { |
||
| 23 | 7 | return \sprintf( |
|
| 24 | 7 | 'contains at least one element of "%s"', |
|
| 25 | 7 | \implode(', ', $this->members) |
|
| 26 | ); |
||
| 27 | } |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Evaluates the constraint for parameter $other. Returns true if the |
||
| 31 | * constraint is met, false otherwise. |
||
| 32 | * |
||
| 33 | * @param mixed $other value or object to evaluate |
||
| 34 | */ |
||
| 35 | 62 | protected function matches($other) : bool |
|
| 36 | { |
||
| 37 | 62 | if (!is_array($other)) { |
|
| 38 | 1 | return false; |
|
| 39 | } |
||
| 40 | |||
| 41 | 61 | foreach ($this->members as $member) { |
|
| 42 | 61 | if (array_key_exists($member, $other)) { |
|
| 43 | 45 | return true; |
|
| 44 | } |
||
| 45 | } |
||
| 46 | |||
| 47 | 19 | return false; |
|
| 48 | } |
||
| 49 | |||
| 50 | 25 | public function check($other) : bool |
|
| 53 | } |
||
| 54 | } |
||
| 55 |