| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Metricool\Support\Validation\Rules; |
| 6 |
|
| 7 |
class InRule extends AbstractRule |
| 8 |
{ |
| 9 |
/** |
| 10 |
* Checks if the field value is one of the given parameters, |
| 11 |
* e.g. "in:countries,referers". |
| 12 |
* @inheritDoc |
| 13 |
*/ |
| 14 |
public function validate(string $field, $value, array $data): void |
| 15 |
{ |
| 16 |
if (!in_array((string) $value, $this->parameters, true)) { |
| 17 |
$this->fail(sprintf( |
| 18 |
/* translators: %s is the field name */ |
| 19 |
__('%s is invalid.', 'metricool'), |
| 20 |
$field |
| 21 |
)); |
| 22 |
} |
| 23 |
} |
| 24 |
} |
| 25 |
|