Skip to content

Commit 9b9ede3

Browse files
committed
OXDEV-10012 Fix static analysis issues
1 parent b081150 commit 9b9ede3

7 files changed

Lines changed: 13 additions & 21 deletions

File tree

src/Authentication/TwoFactorAuth/Controller/TwoFactorAuthController.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
namespace OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Controller;
1111

1212
use OxidEsales\Eshop\Application\Controller\FrontendController;
13-
use OxidEsales\Eshop\Core\Language;
1413
use OxidEsales\Eshop\Core\UtilsView;
1514
use OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Exception\OTPValidationException;
1615
use OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Service\AuthorizeServiceInterface;
@@ -31,7 +30,6 @@ public function __construct(
3130
private readonly AuthorizeServiceInterface $authService,
3231
private readonly UserServiceInterface $userService,
3332
private readonly AuthCodeRequestInterface $authCodeRequest,
34-
private readonly Language $language,
3533
private readonly UtilsView $utilsView,
3634
) {
3735
parent::__construct();
@@ -45,10 +43,8 @@ public function handleOTP(): ?string
4543
);
4644

4745
$this->userService->finalizeLogin();
48-
4946
} catch (OTPValidationException $e) {
50-
$translatedMessage = $this->language->translateString($e->getMessage());
51-
$this->utilsView->addErrorToDisplay($translatedMessage);
47+
$this->utilsView->addErrorToDisplay($e);
5248
}
5349

5450
return null;

src/Authentication/TwoFactorAuth/Controller/services.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ services:
44
public: false
55
bind:
66
OxidEsales\Eshop\Core\UtilsView: '@=service("OxidEsales\\SecurityModule\\Core\\Registry").getUtilsView()'
7-
OxidEsales\Eshop\Core\Language: '@=service("OxidEsales\\SecurityModule\\Core\\Registry").getLang()'
87

98
OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Controller\TwoFactorAuthController:
109
public: true

src/Authentication/TwoFactorAuth/Exception/OTPValidationException.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
namespace OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Exception;
1111

12-
class OTPValidationException extends \Exception
12+
use OxidEsales\Eshop\Core\Exception\StandardException;
13+
14+
class OTPValidationException extends StandardException
1315
{
1416
}

src/Authentication/TwoFactorAuth/Service/UserService.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public function finalizeLogin(): void
4242
$redirectUrl = $this->getRedirectUrl();
4343

4444
$this->session->set('OTP_PASS', $userId);
45+
/** @phpstan-ignore argument.type (password is null because user already authenticated via OTP) */
4546
$user->login($user->getFieldData('oxusername'), null, false);
4647
$this->clearOTPSessionVariables();
4748
Registry::getUtils()->redirect($redirectUrl, false);

src/Authentication/TwoFactorAuth/Subscriber/StoreCurrentUrlSubscriber.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ public static function getSubscribedEvents(): array
3131
];
3232
}
3333

34+
/**
35+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
36+
*/
3437
public function onViewRendered(ViewRenderedEvent $event): void
3538
{
3639
if ($this->isAdmin()) {

src/Shared/Model/User.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ public function login($userName, $password, $setSessionCookie = false): bool
8080
return parent::login($userName, $password, $setSessionCookie);
8181
}
8282

83+
/** @phpstan-ignore missingType.return (inherited from parent without return type) */
8384
protected function onLogin($userName, $password)
8485
{
8586
parent::onLogin($userName, $password);

tests/Unit/Authentication/TwoFactorAuth/Controller/TwoFactorAuthControllerTest.php

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
namespace OxidEsales\SecurityModule\Tests\Unit\Authentication\TwoFactorAuth\Controller;
1111

12-
use OxidEsales\Eshop\Core\Language;
1312
use OxidEsales\Eshop\Core\UtilsView;
1413
use OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Controller\TwoFactorAuthController;
1514
use OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Exception\InvalidCodeException;
@@ -71,32 +70,25 @@ public function testHandleOTPDoesNotFinalizeLoginOnValidationFailure(): void
7170
$this->assertNull($result);
7271
}
7372

74-
public function testHandleOTPDisplaysTranslatedErrorOnValidationFailure(): void
73+
public function testHandleOTPDisplaysErrorOnValidationFailure(): void
7574
{
76-
$translatedMessage = 'The code is invalid';
75+
$exception = new InvalidCodeException();
7776

7877
$authCodeRequestStub = $this->createStub(AuthCodeRequestInterface::class);
7978
$authCodeRequestStub->method('getCode')->willReturn('invalid');
8079

8180
$authServiceStub = $this->createStub(AuthorizeServiceInterface::class);
8281
$authServiceStub->method('validate')
83-
->willThrowException(new InvalidCodeException());
84-
85-
$languageMock = $this->createMock(Language::class);
86-
$languageMock->expects($this->once())
87-
->method('translateString')
88-
->with('ERROR_INVALID_CODE')
89-
->willReturn($translatedMessage);
82+
->willThrowException($exception);
9083

9184
$utilsViewMock = $this->createMock(UtilsView::class);
9285
$utilsViewMock->expects($this->once())
9386
->method('addErrorToDisplay')
94-
->with($translatedMessage);
87+
->with($exception);
9588

9689
$controller = $this->getSut(
9790
authService: $authServiceStub,
9891
authCodeRequest: $authCodeRequestStub,
99-
language: $languageMock,
10092
utilsView: $utilsViewMock,
10193
);
10294

@@ -140,14 +132,12 @@ private function getSut(
140132
AuthorizeServiceInterface $authService = null,
141133
UserServiceInterface $userService = null,
142134
AuthCodeRequestInterface $authCodeRequest = null,
143-
Language $language = null,
144135
UtilsView $utilsView = null,
145136
): TwoFactorAuthController {
146137
return new TwoFactorAuthController(
147138
authService: $authService ?? $this->createStub(AuthorizeServiceInterface::class),
148139
userService: $userService ?? $this->createStub(UserServiceInterface::class),
149140
authCodeRequest: $authCodeRequest ?? $this->createStub(AuthCodeRequestInterface::class),
150-
language: $language ?? $this->createStub(Language::class),
151141
utilsView: $utilsView ?? $this->createStub(UtilsView::class),
152142
);
153143
}

0 commit comments

Comments
 (0)