| Total Complexity | 5 |
| Total Lines | 49 |
| Duplicated Lines | 0 % |
| Coverage | 88.24% |
| 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 | 3 | public function __construct(?string $message = null) |
|
| 20 | { |
||
| 21 | 3 | $this->message = $message ?? 'Не правильно введен email'; |
|
| 22 | } |
||
| 23 | |||
| 24 | |||
| 25 | |||
| 26 | /** |
||
| 27 | * @psalm-suppress PossiblyNullReference |
||
| 28 | * @param Ruleable&Element $element |
||
| 29 | * @return bool |
||
| 30 | */ |
||
| 31 | 3 | public function validate(Ruleable $element): bool |
|
| 32 | { |
||
| 33 | 3 | $method = $this->getRequest()->getRequest()->getMethod(); |
|
| 34 | 3 | $requestData = match (strtolower($method)) { |
|
| 35 | 3 | 'get' => $this->getRequest()->getQueryData()->toArray(), |
|
| 36 | 'post' => $this->getRequest()->getPostData()->toArray(), |
||
| 37 | default => [] |
||
| 38 | }; |
||
| 39 | /** @var string $value */ |
||
| 40 | 3 | $value = \getValueByIndexPath($element->getName(), $requestData); |
|
|
|
|||
| 41 | 3 | if ($this->check(\trim($value)) === false) { |
|
| 42 | 1 | $element->setRuleError($this->message); |
|
| 43 | 1 | return false; |
|
| 44 | } |
||
| 45 | 2 | return true; |
|
| 46 | } |
||
| 47 | |||
| 48 | |||
| 49 | 3 | private function check(string $value): bool |
|
| 60 | } |
||
| 61 | } |
||
| 62 |