hryvinskyi /
magento2-invisible-captcha
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Copyright (c) 2019. Volodymyr Hryvinskyi. All rights reserved. |
||
| 4 | * @author: <mailto:[email protected]> |
||
| 5 | * @github: <https://github.com/hryvinskyi> |
||
| 6 | */ |
||
| 7 | |||
| 8 | declare(strict_types=1); |
||
| 9 | |||
| 10 | namespace Hryvinskyi\InvisibleCaptcha\Model; |
||
| 11 | |||
| 12 | use Hryvinskyi\InvisibleCaptcha\Model\Provider\FailureInterface; |
||
| 13 | use Hryvinskyi\InvisibleCaptcha\Model\Provider\TokenResponseInterface; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * Class Captcha |
||
| 17 | */ |
||
| 18 | class Captcha implements CaptchaInterface |
||
| 19 | { |
||
| 20 | /** |
||
| 21 | * @var string|null |
||
| 22 | */ |
||
| 23 | private $action; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @var TokenResponseInterface |
||
| 27 | */ |
||
| 28 | private $tokenResponse; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var FailureInterface |
||
| 32 | */ |
||
| 33 | private $failureProvider; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @var CheckEnabledVerifyInterface|null |
||
| 37 | */ |
||
| 38 | private $checkEnabledVerify; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @var ScoreThresholdInterface|null |
||
| 42 | */ |
||
| 43 | private $scoreThreshold; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Captcha constructor. |
||
| 47 | * |
||
| 48 | * @param string $action |
||
| 49 | * @param TokenResponseInterface $tokenResponse |
||
| 50 | * @param FailureInterface $failureProvider |
||
| 51 | * @param ScoreThresholdInterface|null $scoreThreshold |
||
| 52 | * @param CheckEnabledVerifyInterface|null $checkEnabledVerify |
||
| 53 | */ |
||
| 54 | public function __construct( |
||
| 55 | string $action, |
||
| 56 | TokenResponseInterface $tokenResponse, |
||
| 57 | FailureInterface $failureProvider, |
||
| 58 | ?ScoreThresholdInterface $scoreThreshold, |
||
| 59 | ?CheckEnabledVerifyInterface $checkEnabledVerify |
||
| 60 | ) { |
||
| 61 | $this->action = $action; |
||
| 62 | $this->tokenResponse = $tokenResponse; |
||
| 63 | $this->failureProvider = $failureProvider; |
||
| 64 | $this->scoreThreshold = $scoreThreshold; |
||
| 65 | $this->checkEnabledVerify = $checkEnabledVerify; |
||
| 66 | } |
||
| 67 | |||
| 68 | /** |
||
| 69 | * @return string |
||
| 70 | */ |
||
| 71 | public function getAction(): string |
||
| 72 | { |
||
| 73 | return $this->action; |
||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 74 | } |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @return string|null |
||
| 78 | */ |
||
| 79 | public function getToken(): ?string |
||
| 80 | { |
||
| 81 | return $this->tokenResponse->getToken(); |
||
| 82 | } |
||
| 83 | |||
| 84 | /** |
||
| 85 | * @return float |
||
| 86 | */ |
||
| 87 | public function getScoreThreshold(): float |
||
| 88 | { |
||
| 89 | return $this->scoreThreshold ? $this->scoreThreshold->getValue() : 0.5; |
||
| 90 | } |
||
| 91 | |||
| 92 | /** |
||
| 93 | * @return FailureInterface |
||
| 94 | */ |
||
| 95 | public function getFailure(): FailureInterface |
||
| 96 | { |
||
| 97 | return $this->failureProvider; |
||
| 98 | } |
||
| 99 | |||
| 100 | /** |
||
| 101 | * @inheritdoc |
||
| 102 | */ |
||
| 103 | public function isEnabled(): bool |
||
| 104 | { |
||
| 105 | return !$this->checkEnabledVerify || $this->checkEnabledVerify->verify(); |
||
| 106 | } |
||
| 107 | } |
||
| 108 |