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 / RequiredRule.php

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

34 lines 685 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 use Metricool\Support\Validation\Validator;
8
9 class RequiredRule extends AbstractRule
10 {
11 /**
12 * Checks if the field is present and not empty.
13 * @inheritDoc
14 */
15 public function validate(string $field, $value, array $data): void
16 {
17 if (Validator::isEmptyValue($value)) {
18 $this->fail(sprintf(
19 /* translators: %s is the field name */
20 __('%s is required.', 'metricool'),
21 $field
22 ));
23 }
24 }
25
26 /**
27 * @inheritDoc
28 */
29 public function isRequired(): bool
30 {
31 return true;
32 }
33 }
34