| Total Complexity | 6 |
| Total Lines | 46 |
| Duplicated Lines | 0 % |
| Coverage | 89.47% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 11 | class Email extends Rules implements RuleInterface |
||
| 12 | { |
||
| 13 | // private $idn_to_ascii = false; |
||
| 14 | |||
| 15 | 3 | public function setMessage(?string $message = null): ?string |
|
| 16 | { |
||
| 17 | 3 | if (is_null($message)) { |
|
| 18 | 3 | $message = 'Не правильно введен email'; |
|
| 19 | } |
||
| 20 | 3 | return parent::setMessage($message); |
|
| 21 | } |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @psalm-suppress PossiblyNullReference |
||
| 25 | * @param Ruleable&Element $element |
||
| 26 | * @return bool |
||
| 27 | */ |
||
| 28 | 3 | public function validate(Ruleable $element): bool |
|
| 29 | { |
||
| 30 | |||
| 31 | 3 | $method = $this->getRequest()->getRequest()->getMethod(); |
|
| 32 | 3 | $requestData = match (strtolower($method)) { |
|
| 33 | 3 | 'get' => $this->getRequest()->getQueryData()->toArray(), |
|
| 34 | 'post' => $this->getRequest()->getPostData()->toArray(), |
||
| 35 | default => [] |
||
| 36 | }; |
||
| 37 | 3 | $value = \getValueByIndexPath($element->getName(), $requestData); |
|
|
|
|||
| 38 | 3 | if (!$this->check(\trim($value))) { |
|
| 39 | 1 | $element->setRuleError($this->getMessage()); |
|
| 40 | 1 | return false; |
|
| 41 | } |
||
| 42 | 2 | return true; |
|
| 43 | } |
||
| 44 | |||
| 45 | |||
| 46 | 3 | private function check(string $value) |
|
| 57 | } |
||
| 58 | } |
||
| 59 |