Skip to content

Commit 2693c09

Browse files
authored
Merge pull request #166 from magento/after-review-refactoring
security-package/pull/146: Refactoring after Code Review
2 parents 57d89b7 + afc51de commit 2693c09

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

ReCaptchaCustomer/Model/AjaxLogin/CaptchaResponseResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function __construct(SerializerInterface $serializer)
3232
}
3333

3434
/**
35-
* @inheritdoc
35+
* {@inheritdoc}
3636
*
3737
* @param RequestInterface|PlainTextRequestInterface $request
3838
* @return string

ReCaptchaValidation/Model/Validator.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\ReCaptchaValidationApi\Api\Data\ValidationConfigInterface;
1313
use Magento\ReCaptchaValidationApi\Api\ValidatorInterface;
1414
use Magento\ReCaptchaValidationApi\Model\ErrorMessagesProvider;
15+
use ReCaptcha\ReCaptcha;
1516
use ReCaptcha\ReCaptchaFactory;
1617

1718
/**
@@ -56,21 +57,22 @@ public function isValid(
5657
string $reCaptchaResponse,
5758
ValidationConfigInterface $validationConfig
5859
): ValidationResult {
59-
$secret = $validationConfig->getPrivateKey();
60-
$reCaptcha = $this->reCaptchaFactory->create(['secret' => $secret]);
60+
/** @var ReCaptcha $reCaptcha */
61+
$reCaptcha = $this->reCaptchaFactory->create(['secret' => $validationConfig->getPrivateKey()]);
62+
6163
$extensionAttributes = $validationConfig->getExtensionAttributes();
6264
if ($extensionAttributes && (null !== $extensionAttributes->getScoreThreshold())) {
6365
$reCaptcha->setScoreThreshold($extensionAttributes->getScoreThreshold());
6466
}
67+
6568
$result = $reCaptcha->verify($reCaptchaResponse, $validationConfig->getRemoteIp());
6669

6770
$validationErrors = [];
68-
if (!$result->isSuccess()) {
71+
if (false === $result->isSuccess()) {
6972
foreach ($result->getErrorCodes() as $errorCode) {
7073
$validationErrors[] = $this->errorMessagesProvider->getErrorMessage($errorCode);
7174
}
7275
}
73-
7476
return $this->validationResultFactory->create(['errors' => $validationErrors]);
7577
}
7678
}

0 commit comments

Comments
 (0)