PluginProbe
Metricool – Social media and site statistics / trunk
Metricool – Social media and site statistics vtrunk
2.1.0 2.0.2 2.0.1 2.0.0 1.27 trunk
metricool / app / Support / Validation / Rules / MaxRule.php

MaxRule.php in Metricool – Social media and site statistics trunk, at app/Support/Validation/Rules/MaxRule.php

29 lines 794 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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