| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Metricool\Support\Validation\Rules; |
| 6 |
|
| 7 |
class MaxRule extends AbstractRule |
| 8 |
{ |
| 9 |
/** |
| 10 |
* Checks if the size of the field is not greater than the given maximum. |
| 11 |
* Uses the numeric value for numbers, the length for strings and the |
| 12 |
* count for arrays. |
| 13 |
* @inheritDoc |
| 14 |
*/ |
| 15 |
public function validate(string $field, $value, array $data): void |
| 16 |
{ |
| 17 |
$max = (float) ($this->parameters[0] ?? 0); |
| 18 |
|
| 19 |
if ($this->sizeOf($value) > $max) { |
| 20 |
$this->fail(sprintf( |
| 21 |
/* translators: %1$s is the field name, %2$s is the maximum size */ |
| 22 |
__('%1$s must not be greater than %2$s.', 'metricool'), |
| 23 |
$field, |
| 24 |
$this->parameters[0] ?? '0' |
| 25 |
)); |
| 26 |
} |
| 27 |
} |
| 28 |
} |
| 29 |
|