Skip to content

Commit 6619280

Browse files
committed
LYNX-363: CR refactoring
1 parent ff46e89 commit 6619280

File tree

5 files changed

+38
-90
lines changed

5 files changed

+38
-90
lines changed

ReCaptchaVersion2Checkbox/Model/Config.php

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@
2222

2323
class Config implements ReCaptchaConfigInterface, ResetAfterRequestInterface
2424
{
25-
/**
26-
* @var $minimumScore
27-
*/
28-
private ?float $minimumScore = null;
29-
3025
/**
3126
* @var array
3227
*/
@@ -45,10 +40,10 @@ public function __construct(
4540
*
4641
* @return array
4742
*/
48-
public function getUiConfig(): array
43+
private function getUiConfig(): array
4944
{
5045
if (empty($this->uiConfig)) {
51-
$this->uiConfig = $this->uiConfigProvider->get();
46+
$this->uiConfig = $this->uiConfigProvider->get() ?? [];
5247
}
5348
return $this->uiConfig;
5449
}
@@ -60,7 +55,7 @@ public function getUiConfig(): array
6055
*/
6156
public function getWebsiteKey(): string
6257
{
63-
return $this->getUiConfig()['rendering']['sitekey'];
58+
return $this->getUiConfig()['rendering']['sitekey'] ?? '';
6459
}
6560

6661
/**
@@ -70,7 +65,7 @@ public function getWebsiteKey(): string
7065
*/
7166
public function getTheme(): string
7267
{
73-
return $this->getUiConfig()['rendering']['theme'];
68+
return $this->getUiConfig()['rendering']['theme'] ?? '';
7469
}
7570

7671
/**
@@ -80,17 +75,17 @@ public function getTheme(): string
8075
*/
8176
public function getLanguageCode(): string
8277
{
83-
return $this->getUiConfig()['rendering']['hl'];
78+
return $this->getUiConfig()['rendering']['hl'] ?? '';
8479
}
8580

8681
/**
8782
* "I am not a robot" captcha does not provide configurable minimum score setting
8883
*
89-
* @return null
84+
* @return null|float
9085
*/
91-
public function getMinimumScore()
86+
public function getMinimumScore(): ?float
9287
{
93-
return $this->minimumScore;
88+
return null;
9489
}
9590

9691
/**
@@ -109,6 +104,5 @@ public function getBadgePosition(): string
109104
public function _resetState(): void
110105
{
111106
$this->uiConfig = [];
112-
$this->minimumScore = null;
113107
}
114108
}

ReCaptchaVersion2Invisible/Model/Config.php

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ class Config implements ReCaptchaConfigInterface, ResetAfterRequestInterface
2727
*/
2828
private array $uiConfig = [];
2929

30-
/**
31-
* @var $minimumScore
32-
*/
33-
private ?float $minimumScore = null;
34-
3530
/**
3631
* @param UiConfigProvider $uiConfigProvider
3732
*/
@@ -47,17 +42,17 @@ public function __construct(
4742
*/
4843
public function getWebsiteKey(): string
4944
{
50-
return $this->getUiConfig()['rendering']['sitekey'];
45+
return $this->getUiConfig()['rendering']['sitekey'] ?? '';
5146
}
5247

5348
/**
54-
* ReCaptcha V2 Invisible does not provide configurable minimum score setting
49+
* ReCaptcha v2 Invisible does not provide configuration for minimum score
5550
*
56-
* @return null
51+
* @return null|float
5752
*/
58-
public function getMinimumScore()
53+
public function getMinimumScore(): ?float
5954
{
60-
return $this->minimumScore;
55+
return null;
6156
}
6257

6358
/**
@@ -67,7 +62,7 @@ public function getMinimumScore()
6762
*/
6863
public function getBadgePosition(): string
6964
{
70-
return $this->getUiConfig()['rendering']['badge'];
65+
return $this->getUiConfig()['rendering']['badge'] ?? '';
7166
}
7267

7368
/**
@@ -77,7 +72,7 @@ public function getBadgePosition(): string
7772
*/
7873
public function getTheme(): string
7974
{
80-
return $this->getUiConfig()['rendering']['theme'];
75+
return $this->getUiConfig()['rendering']['theme'] ?? '';
8176
}
8277

8378
/**
@@ -87,18 +82,18 @@ public function getTheme(): string
8782
*/
8883
public function getLanguageCode(): string
8984
{
90-
return $this->getUiConfig()['rendering']['hl'];
85+
return $this->getUiConfig()['rendering']['hl'] ?? '';
9186
}
9287

9388
/**
9489
* Get front-end's UI configurations
9590
*
9691
* @return array
9792
*/
98-
public function getUiConfig(): array
93+
private function getUiConfig(): array
9994
{
10095
if (empty($this->uiConfig)) {
101-
$this->uiConfig = $this->uiConfigProvider->get();
96+
$this->uiConfig = $this->uiConfigProvider->get() ?? [];
10297
}
10398
return $this->uiConfig;
10499
}
@@ -109,6 +104,5 @@ public function getUiConfig(): array
109104
public function _resetState(): void
110105
{
111106
$this->uiConfig = [];
112-
$this->minimumScore = null;
113107
}
114108
}

ReCaptchaVersion3Invisible/Model/Config.php

Lines changed: 12 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,11 @@
1515

1616
class Config implements ReCaptchaConfigInterface, ResetAfterRequestInterface
1717
{
18-
/**
19-
* @var string|null
20-
*/
21-
private ?string $websiteKey = null;
22-
2318
/**
2419
* @var float|null
2520
*/
2621
private ?float $minimumScore = null;
2722

28-
/**
29-
* @var string|null
30-
*/
31-
private ?string $badgePosition = null;
32-
33-
/**
34-
* @var string|null
35-
*/
36-
private ?string $languageCode = null;
37-
3823
/**
3924
* @var array
4025
*/
@@ -45,11 +30,6 @@ class Config implements ReCaptchaConfigInterface, ResetAfterRequestInterface
4530
*/
4631
private ?ValidationConfigInterface $validationConfig = null;
4732

48-
/**
49-
* @var array
50-
*/
51-
private array $formTypes;
52-
5333
/**
5434
* @param UiConfigProvider $uiConfigProvider
5535
* @param ValidationConfigProvider $validationConfigProvider
@@ -58,9 +38,8 @@ class Config implements ReCaptchaConfigInterface, ResetAfterRequestInterface
5838
public function __construct(
5939
private readonly UiConfigProvider $uiConfigProvider,
6040
private readonly ValidationConfigProvider $validationConfigProvider,
61-
array $formTypes = []
41+
private readonly array $formTypes
6242
) {
63-
$this->formTypes = $formTypes;
6443
}
6544

6645
/**
@@ -70,18 +49,15 @@ public function __construct(
7049
*/
7150
public function getWebsiteKey(): string
7251
{
73-
if (!$this->websiteKey) {
74-
$this->websiteKey = $this->getUiConfig()['rendering']['sitekey'];
75-
}
76-
return $this->websiteKey;
52+
return $this->getUiConfig()['rendering']['sitekey'] ?? '';
7753
}
7854

7955
/**
8056
* Get configured minimum score value
8157
*
8258
* @return float|null
8359
*/
84-
public function getMinimumScore(): float|null
60+
public function getMinimumScore(): ?float
8561
{
8662
if (!$this->minimumScore) {
8763
$validationProvider = $this->validationConfigProvider->get();
@@ -100,33 +76,27 @@ public function getMinimumScore(): float|null
10076
*/
10177
public function getBadgePosition(): string
10278
{
103-
if (!$this->badgePosition) {
104-
$this->badgePosition = $this->getUiConfig()['rendering']['badge'];
105-
}
106-
return $this->badgePosition;
79+
return $this->getUiConfig()['rendering']['badge'] ?? '';
10780
}
10881

10982
/**
110-
* Get configured captcha's theme
83+
* Get code of language to send notifications
11184
*
11285
* @return string
11386
*/
114-
public function getTheme(): string
87+
public function getLanguageCode(): string
11588
{
116-
return $this->getUiConfig()['rendering']['theme'];
89+
return $this->getUiConfig()['rendering']['hl'] ?? '';
11790
}
11891

11992
/**
120-
* Get code of language to send notifications
93+
* Get configured captcha's theme
12194
*
12295
* @return string
12396
*/
124-
public function getLanguageCode(): string
97+
public function getTheme(): string
12598
{
126-
if (!$this->languageCode) {
127-
$this->languageCode = $this->getUiConfig()['rendering']['hl'];
128-
}
129-
return $this->languageCode;
99+
return $this->getUiConfig()['rendering']['theme'] ?? '';
130100
}
131101

132102
/**
@@ -157,10 +127,10 @@ public function getValidationConfig(): ValidationConfigInterface
157127
*
158128
* @return array
159129
*/
160-
public function getUiConfig(): array
130+
private function getUiConfig(): array
161131
{
162132
if (empty($this->uiConfig)) {
163-
$this->uiConfig = $this->uiConfigProvider->get();
133+
$this->uiConfig = $this->uiConfigProvider->get() ?? [];
164134
}
165135
return $this->uiConfig;
166136
}
@@ -171,10 +141,7 @@ public function getUiConfig(): array
171141
public function _resetState(): void
172142
{
173143
$this->uiConfig = [];
174-
$this->websiteKey = null;
175144
$this->minimumScore = null;
176-
$this->languageCode = null;
177-
$this->badgePosition = null;
178145
$this->validationConfig = null;
179146
}
180147
}

ReCaptchaWebapiGraphQl/Model/Adapter/ReCaptchaConfigInterface.php

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,45 +22,38 @@
2222
*/
2323
interface ReCaptchaConfigInterface
2424
{
25-
/**
26-
* Get front-end's UI configurations
27-
*
28-
* @return array
29-
*/
30-
public function getUiConfig();
31-
3225
/**
3326
* Get website's Google API public key
3427
*
3528
* @return string
3629
*/
37-
public function getWebsiteKey();
30+
public function getWebsiteKey(): string;
3831

3932
/**
4033
* Get configured captcha's theme
4134
*
4235
* @return string
4336
*/
44-
public function getTheme();
37+
public function getTheme(): string;
4538

4639
/**
4740
* Get code of language to send notifications
4841
*
4942
* @return string
5043
*/
51-
public function getLanguageCode();
44+
public function getLanguageCode(): string;
5245

5346
/**
5447
* Returns minimum score setting
5548
*
56-
* @return mixed
49+
* @return float|null
5750
*/
58-
public function getMinimumScore();
51+
public function getMinimumScore(): ?float;
5952

6053
/**
6154
* Returns badge_position setting
6255
*
6356
* @return string
6457
*/
65-
public function getBadgePosition();
58+
public function getBadgePosition(): string;
6659
}

ReCaptchaWebapiGraphQl/etc/schema.graphqls

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ enum ReCaptchaTypeEmum {
2626
}
2727

2828
type ReCaptchaConfigOutput {
29-
is_enabled: Boolean!
30-
configurations: ReCaptchaConfiguration
29+
is_enabled: Boolean! @doc(description: "Indicates whether reCaptcha type is enabled")
30+
configurations: ReCaptchaConfiguration @doc(description: "Configuration details for reCaptcha type")
3131
}
3232

3333
type ReCaptchaConfiguration @doc(description: "Contains reCAPTCHA form configuration details.") {

0 commit comments

Comments
 (0)