| @@ 9-38 (lines=30) @@ | ||
| 6 | ||
| 7 | use SolBianca\Validator\Interfaces\RuleInterface; |
|
| 8 | ||
| 9 | class MaxRule implements RuleInterface |
|
| 10 | { |
|
| 11 | /** |
|
| 12 | * {@inheritdoc} |
|
| 13 | */ |
|
| 14 | public function run($value, array $input, array $args): bool |
|
| 15 | { |
|
| 16 | $number = isset($args[1]) && $args[1] === 'number'; |
|
| 17 | if ($number) { |
|
| 18 | return (float)$value <= (float)$args[0]; |
|
| 19 | } |
|
| 20 | return mb_strlen((string)$value) <= (int)$args[0]; |
|
| 21 | } |
|
| 22 | ||
| 23 | /** |
|
| 24 | * {@inheritdoc} |
|
| 25 | */ |
|
| 26 | public function errorMessage(): string |
|
| 27 | { |
|
| 28 | return 'Field `{field}` must be a maximum of `{$0}`.'; |
|
| 29 | } |
|
| 30 | ||
| 31 | /** |
|
| 32 | * {@inheritdoc} |
|
| 33 | */ |
|
| 34 | public function canSkip(): bool |
|
| 35 | { |
|
| 36 | return true; |
|
| 37 | } |
|
| 38 | } |
|
| @@ 9-38 (lines=30) @@ | ||
| 6 | ||
| 7 | use SolBianca\Validator\Interfaces\RuleInterface; |
|
| 8 | ||
| 9 | class MinRule implements RuleInterface |
|
| 10 | { |
|
| 11 | /** |
|
| 12 | * {@inheritdoc} |
|
| 13 | */ |
|
| 14 | public function run($value, array $input, array $args): bool |
|
| 15 | { |
|
| 16 | $number = isset($args[1]) && $args[1] === 'number'; |
|
| 17 | if ($number) { |
|
| 18 | return (float)$value >= (float)$args[0]; |
|
| 19 | } |
|
| 20 | return mb_strlen($value) >= (int)$args[0]; |
|
| 21 | } |
|
| 22 | ||
| 23 | /** |
|
| 24 | * {@inheritdoc} |
|
| 25 | */ |
|
| 26 | public function errorMessage(): string |
|
| 27 | { |
|
| 28 | return 'Field `{field}` must be a minimum of `{$0}`.'; |
|
| 29 | } |
|
| 30 | ||
| 31 | /** |
|
| 32 | * {@inheritdoc} |
|
| 33 | */ |
|
| 34 | public function canSkip(): bool |
|
| 35 | { |
|
| 36 | return true; |
|
| 37 | } |
|
| 38 | } |
|