Skip to content

Commit 81879a1

Browse files
authored
Merge pull request #2753 from shopware5/chore/clean-up-captcha
chore: Cleanup captcha stuff and replace used font
2 parents 3252691 + 57e4811 commit 81879a1

File tree

19 files changed

+87
-166
lines changed

19 files changed

+87
-166
lines changed

.phpstan-baseline.neon

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -475,36 +475,6 @@ parameters:
475475
count: 1
476476
path: _sql/migrations/440-fix-sorder-email-template.php
477477

478-
-
479-
message: "#^Method Migrations_Migration443\\:\\:disableFirstRunWizard\\(\\) has no return type specified\\.$#"
480-
count: 1
481-
path: _sql/migrations/443-add-wizard-configuration-value.php
482-
483-
-
484-
message: "#^Method Migrations_Migration443\\:\\:fetchElementId\\(\\) has no return type specified\\.$#"
485-
count: 1
486-
path: _sql/migrations/443-add-wizard-configuration-value.php
487-
488-
-
489-
message: "#^Method Migrations_Migration443\\:\\:fetchFormId\\(\\) has no return type specified\\.$#"
490-
count: 1
491-
path: _sql/migrations/443-add-wizard-configuration-value.php
492-
493-
-
494-
message: "#^Method Migrations_Migration443\\:\\:fixCaptchaColor\\(\\) has no return type specified\\.$#"
495-
count: 1
496-
path: _sql/migrations/443-add-wizard-configuration-value.php
497-
498-
-
499-
message: "#^Method Migrations_Migration443\\:\\:insertFormElement\\(\\) has no return type specified\\.$#"
500-
count: 1
501-
path: _sql/migrations/443-add-wizard-configuration-value.php
502-
503-
-
504-
message: "#^Method Migrations_Migration443\\:\\:insertFormTranslation\\(\\) has no return type specified\\.$#"
505-
count: 1
506-
path: _sql/migrations/443-add-wizard-configuration-value.php
507-
508478
-
509479
message: "#^Method Migrations_Migration444\\:\\:addImprintToBottomGroup\\(\\) has no return type specified\\.$#"
510480
count: 1
@@ -1015,21 +985,6 @@ parameters:
1015985
count: 1
1016986
path: _sql/migrations/903-add-menu-import-export-advanced.php
1017987

1018-
-
1019-
message: "#^Method Migrations_Migration904\\:\\:createAdditionalCaptchaOptions\\(\\) has no return type specified\\.$#"
1020-
count: 1
1021-
path: _sql/migrations/904-add-captcha-selection.php
1022-
1023-
-
1024-
message: "#^Method Migrations_Migration904\\:\\:createAdditionalCaptchaOptionsTranslations\\(\\) has no return type specified\\.$#"
1025-
count: 1
1026-
path: _sql/migrations/904-add-captcha-selection.php
1027-
1028-
-
1029-
message: "#^Method Migrations_Migration904\\:\\:moveExistingCaptchaOptions\\(\\) has no return type specified\\.$#"
1030-
count: 1
1031-
path: _sql/migrations/904-add-captcha-selection.php
1032-
1033988
-
1034989
message: "#^Method Migrations_Migration917\\:\\:addCategorySortings\\(\\) has no return type specified\\.$#"
1035990
count: 1
@@ -21315,11 +21270,6 @@ parameters:
2131521270
count: 1
2131621271
path: engine/Shopware/Controllers/Backend/Base.php
2131721272

21318-
-
21319-
message: "#^Method Shopware_Controllers_Backend_Base\\:\\:getAvailableCaptchasAction\\(\\) has no return type specified\\.$#"
21320-
count: 1
21321-
path: engine/Shopware/Controllers/Backend/Base.php
21322-
2132321273
-
2132421274
message: "#^Method Shopware_Controllers_Backend_Base\\:\\:getAvailableHashesAction\\(\\) has no return type specified\\.$#"
2132521275
count: 1
@@ -24355,21 +24305,6 @@ parameters:
2435524305
count: 1
2435624306
path: engine/Shopware/Controllers/Widgets/Campaign.php
2435724307

24358-
-
24359-
message: "#^Method Shopware_Controllers_Widgets_Captcha\\:\\:getCaptchaByNameAction\\(\\) has no return type specified\\.$#"
24360-
count: 1
24361-
path: engine/Shopware/Controllers/Widgets/Captcha.php
24362-
24363-
-
24364-
message: "#^Method Shopware_Controllers_Widgets_Captcha\\:\\:indexAction\\(\\) has no return type specified\\.$#"
24365-
count: 1
24366-
path: engine/Shopware/Controllers/Widgets/Captcha.php
24367-
24368-
-
24369-
message: "#^Method Shopware_Controllers_Widgets_Captcha\\:\\:refreshCaptchaAction\\(\\) has no return type specified\\.$#"
24370-
count: 1
24371-
path: engine/Shopware/Controllers/Widgets/Captcha.php
24372-
2437324308
-
2437424309
message: "#^Access to an undefined property Enlight_Components_Session_Namespace\\:\\:\\$sOneTimeAccount\\.$#"
2437524310
count: 1
@@ -24640,11 +24575,6 @@ parameters:
2464024575
count: 1
2464124576
path: engine/Shopware/Core/sAdmin.php
2464224577

24643-
-
24644-
message: "#^Method sAdmin\\:\\:sNewsletterSubscription\\(\\) return type has no value type specified in iterable type array\\.$#"
24645-
count: 1
24646-
path: engine/Shopware/Core/sAdmin.php
24647-
2464824578
-
2464924579
message: "#^Method sAdmin\\:\\:sRiskARTICLESFROM\\(\\) has parameter \\$order with no value type specified in iterable type array\\.$#"
2465024580
count: 1
@@ -25055,11 +24985,6 @@ parameters:
2505524985
count: 2
2505624986
path: engine/Shopware/Core/sAdmin.php
2505724987

25058-
-
25059-
message: "#^Parameter \\#2 \\$request of method Shopware\\\\Components\\\\Captcha\\\\CaptchaValidator\\:\\:validateByName\\(\\) expects Enlight_Controller_Request_Request, Enlight_Controller_Request_Request\\|null given\\.$#"
25060-
count: 1
25061-
path: engine/Shopware/Core/sAdmin.php
25062-
2506324988
-
2506424989
message: "#^Parameter \\#2 \\$resource of method Shopware\\\\Components\\\\DependencyInjection\\\\Container\\:\\:set\\(\\) expects object\\|null, string given\\.$#"
2506524990
count: 1
@@ -36410,11 +36335,6 @@ parameters:
3641036335
count: 1
3641136336
path: tests/Functional/Components/CacheSubscriberTest.php
3641236337

36413-
-
36414-
message: "#^Method Shopware\\\\Tests\\\\Functional\\\\Components\\\\Captcha\\\\CaptchaRepositoryTest\\:\\:testThrowCaptchaNotFoundException\\(\\) has no return type specified\\.$#"
36415-
count: 1
36416-
path: tests/Functional/Components/Captcha/CaptchaRepositoryTest.php
36417-
3641836338
-
3641936339
message: "#^Method Shopware\\\\Tests\\\\Functional\\\\Components\\\\Cart\\\\BasketQueryHelperTest\\:\\:testGetInsertDiscountAttributeQuery\\(\\) has no return type specified\\.$#"
3642036340
count: 1

_sql/migrations/443-add-wizard-configuration-value.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
3+
declare(strict_types=1);
24
/**
35
* Shopware 5
46
* Copyright (c) shopware AG
@@ -21,7 +23,9 @@
2123
* our trademarks remain entirely with the shopware AG.
2224
*/
2325

24-
class Migrations_Migration443 extends Shopware\Components\Migrations\AbstractMigration
26+
use Shopware\Components\Migrations\AbstractMigration;
27+
28+
class Migrations_Migration443 extends AbstractMigration
2529
{
2630
public function up($modus)
2731
{
@@ -36,7 +40,7 @@ public function up($modus)
3640
}
3741
}
3842

39-
private function disableFirstRunWizard()
43+
private function disableFirstRunWizard(): void
4044
{
4145
$sql = <<<'EOD'
4246
INSERT IGNORE INTO `s_core_config_values` (`element_id`, `shop_id`, `value`) VALUES
@@ -45,23 +49,23 @@ private function disableFirstRunWizard()
4549
$this->addSql($sql);
4650
}
4751

48-
private function fetchFormId()
52+
private function fetchFormId(): void
4953
{
5054
$sql = <<<'EOD'
5155
SET @formId = (SELECT id FROM s_core_config_forms WHERE `name`='Auth');
5256
EOD;
5357
$this->addSql($sql);
5458
}
5559

56-
private function fetchElementId()
60+
private function fetchElementId(): void
5761
{
5862
$sql = <<<'EOD'
5963
SET @elementId = (SELECT id FROM s_core_config_elements WHERE name LIKE "firstRunWizardEnabled" LIMIT 1);
6064
EOD;
6165
$this->addSql($sql);
6266
}
6367

64-
private function insertFormElement()
68+
private function insertFormElement(): void
6569
{
6670
$sql = <<<'EOD'
6771
INSERT IGNORE INTO `s_core_config_elements` (`id`, `form_id`, `name`, `value`, `label`, `description`, `type`, `required`, `position`, `scope`) VALUES
@@ -70,7 +74,7 @@ private function insertFormElement()
7074
$this->addSql($sql);
7175
}
7276

73-
private function insertFormTranslation()
77+
private function insertFormTranslation(): void
7478
{
7579
$sql = <<<'EOD'
7680
INSERT IGNORE INTO `s_core_config_element_translations` (`element_id`, `locale_id`, `label`, `description`)
@@ -79,7 +83,7 @@ private function insertFormTranslation()
7983
$this->addSql($sql);
8084
}
8185

82-
private function fixCaptchaColor()
86+
private function fixCaptchaColor(): void
8387
{
8488
$sql = <<<'EOD'
8589
UPDATE s_core_config_element_translations

_sql/migrations/904-add-captcha-selection.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
3+
declare(strict_types=1);
24
/**
35
* Shopware 5
46
* Copyright (c) shopware AG
@@ -21,7 +23,9 @@
2123
* our trademarks remain entirely with the shopware AG.
2224
*/
2325

24-
class Migrations_Migration904 extends Shopware\Components\Migrations\AbstractMigration
26+
use Shopware\Components\Migrations\AbstractMigration;
27+
28+
class Migrations_Migration904 extends AbstractMigration
2529
{
2630
public function up($modus)
2731
{
@@ -30,7 +34,7 @@ public function up($modus)
3034
$this->createAdditionalCaptchaOptionsTranslations();
3135
}
3236

33-
private function moveExistingCaptchaOptions()
37+
private function moveExistingCaptchaOptions(): void
3438
{
3539
$this->addSql("SET @help_parent = (SELECT id FROM s_core_config_forms WHERE name='Frontend' LIMIT 1)");
3640

@@ -44,7 +48,7 @@ private function moveExistingCaptchaOptions()
4448
$this->addSql("UPDATE s_core_config_elements SET form_id=@parent WHERE name='captchaColor'");
4549
}
4650

47-
private function createAdditionalCaptchaOptionsTranslations()
51+
private function createAdditionalCaptchaOptionsTranslations(): void
4852
{
4953
$this->addSql("SET @captchaMethod = (SELECT id FROM s_core_config_elements WHERE name = 'captchaMethod' LIMIT 1)");
5054
$this->addSql("SET @noCaptchaAfterLogin = (SELECT id FROM s_core_config_elements WHERE name = 'noCaptchaAfterLogin' LIMIT 1)");
@@ -59,9 +63,9 @@ private function createAdditionalCaptchaOptionsTranslations()
5963
}
6064

6165
/**
62-
* @param string $modus
66+
* @param self::MODUS_* $modus
6367
*/
64-
private function createAdditionalCaptchaOptions($modus)
68+
private function createAdditionalCaptchaOptions(string $modus): void
6569
{
6670
$captchaMethod = 'default';
6771
if ($modus === self::MODUS_UPDATE) {

engine/Shopware/Components/Captcha/AbstractCaptcha.php

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,8 @@
3333
abstract class AbstractCaptcha implements CaptchaInterface
3434
{
3535
private const PATH_CAPTCHA_IMAGE = 'frontend/_public/src/img/bg--captcha.jpg';
36-
private const PATH_CAPTCHA_IMAGE_FALLBACK = 'frontend/_resources/images/captcha/background.jpg';
3736

3837
private const PATH_CAPTCHA_FONT = 'frontend/_public/src/fonts/captcha.ttf';
39-
private const PATH_CAPTCHA_FONT_FALLBACK = 'frontend/_resources/images/captcha/font.ttf';
4038

4139
protected Shopware_Components_Config $config;
4240

@@ -62,14 +60,6 @@ protected function getImageResource($string)
6260
$captcha = $this->getCaptchaFile(self::PATH_CAPTCHA_IMAGE);
6361
$font = $this->getCaptchaFile(self::PATH_CAPTCHA_FONT);
6462

65-
if (empty($captcha)) {
66-
$captcha = $this->getCaptchaFile(self::PATH_CAPTCHA_IMAGE_FALLBACK);
67-
}
68-
69-
if (empty($font)) {
70-
$font = $this->getCaptchaFile(self::PATH_CAPTCHA_FONT_FALLBACK);
71-
}
72-
7363
if (!empty($captcha)) {
7464
$im = imagecreatefromjpeg($captcha);
7565
} else {
@@ -107,10 +97,8 @@ protected function getImageResource($string)
10797
imagettftext($im, $rand1, $rand2, (($i + 1) * 15) + 2, $rand3 + 2, $black, $font, $string[$i]);
10898
}
10999
for ($i = 0; $i < 8; ++$i) {
110-
imageline($im, Random::getInteger(30, 70), Random::getInteger(0, 50), Random::getInteger(100, 150),
111-
Random::getInteger(20, 100), $black);
112-
imageline($im, Random::getInteger(30, 70), Random::getInteger(0, 50), Random::getInteger(100, 150),
113-
Random::getInteger(20, 100), $black);
100+
imageline($im, Random::getInteger(30, 70), Random::getInteger(0, 50), Random::getInteger(100, 150), Random::getInteger(20, 100), $black);
101+
imageline($im, Random::getInteger(30, 70), Random::getInteger(0, 50), Random::getInteger(100, 150), Random::getInteger(20, 100), $black);
114102
}
115103
} else {
116104
$white = (int) imagecolorallocate($im, 255, 255, 255);

engine/Shopware/Components/Captcha/CaptchaInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
3+
declare(strict_types=1);
24
/**
35
* Shopware 5
46
* Copyright (c) shopware AG

engine/Shopware/Components/Captcha/CaptchaRepository.php

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
3+
declare(strict_types=1);
24
/**
35
* Shopware 5
46
* Copyright (c) shopware AG
@@ -31,20 +33,14 @@
3133

3234
class CaptchaRepository
3335
{
34-
/**
35-
* @var Shopware_Components_Config
36-
*/
37-
private $config;
36+
private Shopware_Components_Config $config;
3837

3938
/**
40-
* @var CaptchaInterface[]
39+
* @var list<CaptchaInterface>
4140
*/
42-
private $captchas;
41+
private array $captchas;
4342

44-
/**
45-
* @var ContainerInterface
46-
*/
47-
private $container;
43+
private ContainerInterface $container;
4844

4945
public function __construct(
5046
IteratorAggregate $captchas,
@@ -79,7 +75,7 @@ public function getConfiguredCaptcha()
7975
}
8076

8177
/**
82-
* @return CaptchaInterface[]
78+
* @return list<CaptchaInterface>
8379
*/
8480
public function getList()
8581
{
@@ -98,31 +94,25 @@ public function getList()
9894
public function getCaptchaByName($captchaName)
9995
{
10096
foreach ($this->captchas as $captcha) {
101-
if ($captcha->getName() == $captchaName) {
97+
if ($captcha->getName() === $captchaName) {
10298
return $captcha;
10399
}
104100
}
105101

106102
throw new CaptchaNotFoundException(sprintf("The captcha with id '%s' is configured, but could not be found", $captchaName));
107103
}
108104

109-
/**
110-
* @return bool
111-
*/
112-
private function isCaptchaDisabled()
105+
private function isCaptchaDisabled(): bool
113106
{
114-
$userIsLoggedIn = !empty($this->container->get('session')->get('sUserId'));
107+
$isCustomerLoggedIn = !empty($this->container->get('session')->get('sUserId'));
115108

116-
if ($this->config->get('noCaptchaAfterLogin') && $userIsLoggedIn) {
109+
if ($this->config->get('noCaptchaAfterLogin') && $isCustomerLoggedIn) {
117110
return true;
118111
}
119112

120113
// legacy way to disable the captcha
121114
$captchaColor = $this->config->get('CaptchaColor');
122-
if (empty($captchaColor)) {
123-
return true;
124-
}
125115

126-
return false;
116+
return empty($captchaColor);
127117
}
128118
}

0 commit comments

Comments
 (0)