Skip to content

Commit 57d89b7

Browse files
authored
Merge pull request #146 from magento/after-review-refactoring
Refactoring.
2 parents 73be589 + 1d508e4 commit 57d89b7

File tree

4 files changed

+21
-17
lines changed

4 files changed

+21
-17
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: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99

1010
use Magento\Framework\Validation\ValidationResult;
1111
use Magento\Framework\Validation\ValidationResultFactory;
12-
use Magento\ReCaptchaValidationApi\Api\ValidatorInterface;
1312
use Magento\ReCaptchaValidationApi\Api\Data\ValidationConfigInterface;
14-
use Magento\ReCaptchaValidationApi\Model\ErrorMessages;
15-
use ReCaptcha\ReCaptcha;
13+
use Magento\ReCaptchaValidationApi\Api\ValidatorInterface;
14+
use Magento\ReCaptchaValidationApi\Model\ErrorMessagesProvider;
15+
use ReCaptcha\ReCaptchaFactory;
1616

1717
/**
1818
* @inheritdoc
@@ -25,20 +25,28 @@ class Validator implements ValidatorInterface
2525
private $validationResultFactory;
2626

2727
/**
28-
* @var ErrorMessages
28+
* @var ErrorMessagesProvider
2929
*/
30-
private $errorMessages;
30+
private $errorMessagesProvider;
31+
32+
/**
33+
* @var ReCaptchaFactory
34+
*/
35+
private $reCaptchaFactory;
3136

3237
/**
3338
* @param ValidationResultFactory $validationResultFactory
34-
* @param ErrorMessages $errorMessages
39+
* @param ErrorMessagesProvider $errorMessagesProvider
40+
* @param ReCaptchaFactory $reCaptchaFactory
3541
*/
3642
public function __construct(
3743
ValidationResultFactory $validationResultFactory,
38-
ErrorMessages $errorMessages
44+
ErrorMessagesProvider $errorMessagesProvider,
45+
ReCaptchaFactory $reCaptchaFactory
3946
) {
4047
$this->validationResultFactory = $validationResultFactory;
41-
$this->errorMessages = $errorMessages;
48+
$this->errorMessagesProvider = $errorMessagesProvider;
49+
$this->reCaptchaFactory = $reCaptchaFactory;
4250
}
4351

4452
/**
@@ -49,11 +57,7 @@ public function isValid(
4957
ValidationConfigInterface $validationConfig
5058
): ValidationResult {
5159
$secret = $validationConfig->getPrivateKey();
52-
53-
// @codingStandardsIgnoreStart
54-
$reCaptcha = new ReCaptcha($secret);
55-
// @codingStandardsIgnoreEnd
56-
60+
$reCaptcha = $this->reCaptchaFactory->create(['secret' => $secret]);
5761
$extensionAttributes = $validationConfig->getExtensionAttributes();
5862
if ($extensionAttributes && (null !== $extensionAttributes->getScoreThreshold())) {
5963
$reCaptcha->setScoreThreshold($extensionAttributes->getScoreThreshold());
@@ -63,7 +67,7 @@ public function isValid(
6367
$validationErrors = [];
6468
if (!$result->isSuccess()) {
6569
foreach ($result->getErrorCodes() as $errorCode) {
66-
$validationErrors[] = $this->errorMessages->getErrorMessage($errorCode);
70+
$validationErrors[] = $this->errorMessagesProvider->getErrorMessage($errorCode);
6771
}
6872
}
6973

ReCaptchaValidationApi/Model/ErrorMessages.php renamed to ReCaptchaValidationApi/Model/ErrorMessagesProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*
1313
* @api Class name should be used in DI for adding new validation errors
1414
*/
15-
class ErrorMessages
15+
class ErrorMessagesProvider
1616
{
1717
/**
1818
* @var array

ReCaptchaValidationApi/etc/di.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
99
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
10-
<type name="Magento\ReCaptchaValidationApi\Model\ErrorMessages">
10+
<type name="Magento\ReCaptchaValidationApi\Model\ErrorMessagesProvider">
1111
<arguments>
1212
<argument name="errors" xsi:type="array">
1313
<item name="invalid-json" xsi:type="string" translatable="true">Invalid JSON received.</item>

0 commit comments

Comments
 (0)