| Total Complexity | 5 |
| Total Lines | 50 |
| Duplicated Lines | 0 % |
| Coverage | 0% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 11 | class Email implements RuleInterface |
||
| 12 | { |
||
| 13 | use Request; |
||
| 14 | |||
| 15 | // private $idn_to_ascii = false; |
||
| 16 | |||
| 17 | private string $message; |
||
| 18 | |||
| 19 | public function __construct(?string $message = null) |
||
| 20 | { |
||
| 21 | $this->message = $message ?? 'Не правильно введен email'; |
||
| 22 | } |
||
| 23 | |||
| 24 | |||
| 25 | |||
| 26 | /** |
||
| 27 | * @psalm-suppress PossiblyNullReference |
||
| 28 | * @param Ruleable&Element $element |
||
| 29 | * @return bool |
||
| 30 | */ |
||
| 31 | public function validate(Ruleable $element): bool |
||
| 32 | { |
||
| 33 | $method = $this->getRequest()->getMethod(); |
||
| 34 | /** @var array $requestData */ |
||
| 35 | $requestData = match (strtolower($method)) { |
||
| 36 | 'get' => $this->getRequest()->getQueryParams(), |
||
| 37 | 'post' => $this->getRequest()->getParsedBody(), |
||
| 38 | default => [] |
||
| 39 | }; |
||
| 40 | /** @var string $value */ |
||
| 41 | $value = \getValueByIndexPath($element->getName(), $requestData); |
||
|
|
|||
| 42 | if ($this->check(\trim($value)) === false) { |
||
| 43 | $element->setRuleError($this->message); |
||
| 44 | return false; |
||
| 45 | } |
||
| 46 | return true; |
||
| 47 | } |
||
| 48 | |||
| 49 | |||
| 50 | private function check(string $value): bool |
||
| 61 | } |
||
| 62 | } |
||
| 63 |