PluginProbe
Metricool – Social media and site statistics / 2.1.1
Metricool – Social media and site statistics v2.1.1
2.1.1 2.1.0 2.0.2 2.0.1 2.0.0 1.27 trunk
metricool / app / Support / Validation / Rules / AcceptedRule.php

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

32 lines 692 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 AcceptedRule extends AbstractRule
8 {
9 /**
10 * Checks if the field is accepted, e.g. a checked terms checkbox.
11 * @inheritDoc
12 */
13 public function validate(string $field, $value, array $data): void
14 {
15 if (!in_array($value, [true, 1, '1', 'true', 'yes', 'on'], true)) {
16 $this->fail(sprintf(
17 /* translators: %s is the field name */
18 __('%s must be accepted.', 'metricool'),
19 $field
20 ));
21 }
22 }
23
24 /**
25 * @inheritDoc
26 */
27 public function isRequired(): bool
28 {
29 return true;
30 }
31 }
32