| Total Complexity | 11 |
| Total Lines | 52 |
| Duplicated Lines | 0 % |
| Changes | 7 | ||
| Bugs | 2 | Features | 0 |
| 1 | <?php |
||
| 8 | class Captcha implements Rule |
||
| 9 | { |
||
| 10 | protected $serviceResponse; |
||
| 11 | protected $userResponse; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * {@inheritdoc} |
||
| 15 | */ |
||
| 16 | public function passes($attribute, $response) |
||
| 17 | { |
||
| 18 | if (! config('simple-recaptcha-v3.active')) { |
||
| 19 | return true; |
||
| 20 | } |
||
| 21 | |||
| 22 | $this->userResponse = $response; |
||
| 23 | |||
| 24 | if ($this->userResponse === null) { |
||
| 25 | return false; |
||
| 26 | } |
||
| 27 | |||
| 28 | $this->serviceResponse = $this->getResponse(new CaptchaService()); |
||
| 29 | |||
| 30 | if (! empty($this->serviceResponse['error-codes'])) { |
||
| 31 | return false; |
||
| 32 | } |
||
| 33 | |||
| 34 | if (config('simple-recaptcha-v3.hostname_check') && request()->getHttpHost() !== $this->serviceResponse['hostname']) { |
||
| 35 | return false; |
||
| 36 | } |
||
| 37 | |||
| 38 | if (! $this->serviceResponse['success'] || $this->serviceResponse['score'] < config('simple-recaptcha-v3.minimum_score')) { |
||
| 39 | return false; |
||
| 40 | } |
||
| 41 | |||
| 42 | return true; |
||
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * {@inheritdoc} |
||
| 47 | */ |
||
| 48 | public function message() |
||
| 55 | } |
||
| 56 | |||
| 57 | protected function getResponse(CaptchaService $service): array |
||
| 62 |