Skip to content

Commit 51a00b9

Browse files
ihorvansachnaydav
authored andcommitted
[Login As Customer] Addded declare strict_types=1
1 parent 57eb24b commit 51a00b9

File tree

21 files changed

+64
-40
lines changed

21 files changed

+64
-40
lines changed

app/code/Magento/LoginAsCustomer/Block/Adminhtml/Customer/Edit/Login.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\LoginAsCustomer\Block\Adminhtml\Customer\Edit;
89

@@ -37,7 +38,7 @@ public function __construct(
3738
/**
3839
* @return array
3940
*/
40-
public function getButtonData()
41+
public function getButtonData(): array
4142
{
4243
$customerId = $this->getCustomerId();
4344
$data = [];
@@ -57,7 +58,7 @@ public function getButtonData()
5758
/**
5859
* @return string
5960
*/
60-
public function getInvalidateTokenUrl()
61+
public function getInvalidateTokenUrl(): string
6162
{
6263
return $this->getUrl('loginascustomer/login/login', ['customer_id' => $this->getCustomerId()]);
6364
}

app/code/Magento/LoginAsCustomer/Block/Adminhtml/Login.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\LoginAsCustomer\Block\Adminhtml;
89

app/code/Magento/LoginAsCustomer/Block/Adminhtml/Store/SaveButton.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\LoginAsCustomer\Block\Adminhtml\Store;
89

@@ -16,7 +17,7 @@ class SaveButton implements ButtonProviderInterface
1617
/**
1718
* @return array
1819
*/
19-
public function getButtonData()
20+
public function getButtonData(): array
2021
{
2122
return [
2223
'label' => __('Login As Customer'),

app/code/Magento/LoginAsCustomer/Controller/Adminhtml/Login/Grid.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\LoginAsCustomer\Controller\Adminhtml\Login;
89

app/code/Magento/LoginAsCustomer/Controller/Adminhtml/Login/Index.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\LoginAsCustomer\Controller\Adminhtml\Login;
89

app/code/Magento/LoginAsCustomer/Controller/Adminhtml/Login/Login.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\LoginAsCustomer\Controller\Adminhtml\Login;
89

app/code/Magento/LoginAsCustomer/Controller/Adminhtml/Login/Manual.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\LoginAsCustomer\Controller\Adminhtml\Login;
89

app/code/Magento/LoginAsCustomer/Controller/Login/Index.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\LoginAsCustomer\Controller\Login;
79

10+
use Magento\Framework\Exception\LocalizedException;
11+
812
/**
913
* LoginAsCustomer login action
1014
*/
@@ -34,18 +38,18 @@ public function __construct(
3438
*/
3539
public function execute()
3640
{
37-
$login = $this->_initLogin();
38-
if (!$login) {
39-
$this->_redirect('/');
40-
return;
41-
}
42-
4341
try {
42+
$login = $this->_initLogin();
43+
4444
/* Log in */
4545
$login->authenticateCustomer();
4646
$this->messageManager->addSuccessMessage(
4747
__('You are logged in as customer: %1', $login->getCustomer()->getName())
4848
);
49+
} catch (LocalizedException $e) {
50+
$this->messageManager->addErrorMessage($e->getMessage());
51+
$this->_redirect('/');
52+
return;
4953
} catch (\Exception $e) {
5054
$this->messageManager->addErrorMessage($e->getMessage());
5155
}
@@ -55,23 +59,21 @@ public function execute()
5559

5660
/**
5761
* Init login info
58-
* @return false || \Magento\LoginAsCustomer\Model\Login
62+
* @return \Magento\LoginAsCustomer\Model\Login
5963
*/
60-
private function _initLogin()
64+
private function _initLogin(): \Magento\LoginAsCustomer\Model\Login
6165
{
6266
$secret = $this->getRequest()->getParam('secret');
6367
if (!$secret) {
64-
$this->messageManager->addErrorMessage(__('Cannot login to account. No secret key provided.'));
65-
return false;
68+
throw LocalizedException(__('Cannot login to account. No secret key provided.'));
6669
}
6770

6871
$login = $this->loginModel->loadNotUsed($secret);
6972

7073
if ($login->getId()) {
7174
return $login;
7275
} else {
73-
$this->messageManager->addErrorMessage(__('Cannot login to account. Secret key is not valid.'));
74-
return false;
76+
throw LocalizedException(__('Cannot login to account. Secret key is not valid'));
7577
}
7678
}
7779
}

app/code/Magento/LoginAsCustomer/Controller/Login/Proceed.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67
namespace Magento\LoginAsCustomer\Controller\Login;
78

89
/**

app/code/Magento/LoginAsCustomer/Model/Config.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\LoginAsCustomer\Model;
89

@@ -61,31 +62,31 @@ public function getConfig($path, $storeId = null)
6162
}
6263

6364
/**
64-
* @return mixed
65+
* @return bool
6566
*/
66-
public function isEnabled()
67+
public function isEnabled():bool
6768
{
68-
return $this->getConfig(
69+
return (bool)$this->getConfig(
6970
self::XML_PATH_EXTENSION_ENABLED
7071
);
7172
}
7273

7374
/**
74-
* @return mixed
75+
* @return bool
7576
*/
76-
public function isKeyMissing()
77+
public function isKeyMissing(): bool
7778
{
7879
return !$this->getConfig(
7980
self::XML_PATH_KEY
8081
) && $this->metadata->getEdition() != 'C' . strrev('ytinummo');
8182
}
8283

8384
/**
84-
* @return mixed
85+
* @return bool
8586
*/
86-
public function getStoreViewLogin()
87+
public function getStoreViewLogin(): bool
8788
{
88-
return $this->getConfig(
89+
return (bool)$this->getConfig(
8990
self::STORE_VIEW_TO_LOGIN_IN
9091
);
9192
}

0 commit comments

Comments
 (0)