Skip to content

Commit c10ec62

Browse files
author
Oleksandr Gorkun
committed
MAGETWO-95945: Add a code mess rule for improper session and cookies usages
1 parent 7ea1bc5 commit c10ec62

File tree

6 files changed

+13
-72
lines changed

6 files changed

+13
-72
lines changed

app/code/Magento/Customer/Block/Account/AuthenticationPopup.php

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@
66
namespace Magento\Customer\Block\Account;
77

88
use Magento\Customer\Model\Form;
9-
use Magento\Customer\Model\Session;
109
use Magento\Store\Model\ScopeInterface;
1110

1211
/**
13-
* Popup.
14-
*
1512
* @api
1613
* @since 100.0.2
1714
*/
@@ -27,34 +24,24 @@ class AuthenticationPopup extends \Magento\Framework\View\Element\Template
2724
*/
2825
private $serializer;
2926

30-
/**
31-
* @var Session|null
32-
*/
33-
private $session;
34-
3527
/**
3628
* @param \Magento\Framework\View\Element\Template\Context $context
3729
* @param array $data
3830
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
39-
* @param Session|null $session
4031
* @throws \RuntimeException
4132
*/
4233
public function __construct(
4334
\Magento\Framework\View\Element\Template\Context $context,
4435
array $data = [],
45-
\Magento\Framework\Serialize\Serializer\Json $serializer = null,
46-
Session $session = null
36+
\Magento\Framework\Serialize\Serializer\Json $serializer = null
4737
) {
4838
parent::__construct($context, $data);
4939
$this->jsLayout = isset($data['jsLayout']) && is_array($data['jsLayout']) ? $data['jsLayout'] : [];
5040
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
5141
->get(\Magento\Framework\Serialize\Serializer\Json::class);
52-
$this->session = $session;
5342
}
5443

5544
/**
56-
* JS layout.
57-
*
5845
* @return string
5946
*/
6047
public function getJsLayout()
@@ -73,8 +60,7 @@ public function getConfig()
7360
'autocomplete' => $this->escapeHtml($this->isAutocompleteEnabled()),
7461
'customerRegisterUrl' => $this->escapeUrl($this->getCustomerRegisterUrlUrl()),
7562
'customerForgotPasswordUrl' => $this->escapeUrl($this->getCustomerForgotPasswordUrl()),
76-
'baseUrl' => $this->escapeUrl($this->getBaseUrl()),
77-
'tst' => $this->session->getData('somedata')
63+
'baseUrl' => $this->escapeUrl($this->getBaseUrl())
7864
];
7965
}
8066

app/code/Magento/Customer/Controller/Account/Confirm.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use Magento\Customer\Model\Url;
1010
use Magento\Framework\App\Action\Context;
1111
use Magento\Customer\Model\Session;
12-
use Magento\Framework\App\Action\HttpGetActionInterface;
1312
use Magento\Framework\App\Config\ScopeConfigInterface;
1413
use Magento\Store\Model\StoreManagerInterface;
1514
use Magento\Customer\Api\AccountManagementInterface;
@@ -25,7 +24,7 @@
2524
*
2625
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2726
*/
28-
class Confirm extends \Magento\Customer\Controller\AbstractAccount implements HttpGetActionInterface
27+
class Confirm extends \Magento\Customer\Controller\AbstractAccount
2928
{
3029
/**
3130
* @var \Magento\Framework\App\Config\ScopeConfigInterface
@@ -168,7 +167,7 @@ public function execute()
168167
$resultRedirect->setUrl($this->getSuccessRedirect());
169168
return $resultRedirect;
170169
} catch (StateException $e) {
171-
$this->messageManager->addException($e, __('This confirmation key is invalid or has expired.TEST'));
170+
$this->messageManager->addException($e, __('This confirmation key is invalid or has expired.'));
172171
} catch (\Exception $e) {
173172
$this->messageManager->addException($e, __('There was an error confirming the account'));
174173
}

app/code/Magento/Customer/Model/CustomerManagement.php

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,29 @@
77

88
use Magento\Customer\Api\CustomerManagementInterface;
99
use Magento\Customer\Model\ResourceModel\Customer\CollectionFactory;
10-
use Magento\Framework\Stdlib\Cookie\PhpCookieReader;
1110

12-
/**
13-
* Class CustomerManagement
14-
*/
1511
class CustomerManagement implements CustomerManagementInterface
1612
{
1713
/**
1814
* @var CollectionFactory
1915
*/
2016
protected $customersFactory;
2117

22-
/**
23-
* @var PhpCookieReader
24-
*/
25-
private $cookie;
26-
2718
/**
2819
* @param CollectionFactory $customersFactory
29-
* @param PhpCookieReader $cookie
3020
*/
31-
public function __construct(CollectionFactory $customersFactory, PhpCookieReader $cookie)
21+
public function __construct(CollectionFactory $customersFactory)
3222
{
3323
$this->customersFactory = $customersFactory;
34-
$this->cookie = $cookie;
3524
}
3625

3726
/**
38-
* @inheritDoc
27+
* {@inheritdoc}
3928
*/
4029
public function getCount()
4130
{
4231
$customers = $this->customersFactory->create();
4332
/** @var \Magento\Customer\Model\ResourceModel\Customer\Collection $customers */
44-
return $customers->getSize() || $this->cookie->getCookie('tst');
33+
return $customers->getSize();
4534
}
4635
}

app/code/Magento/Customer/Model/FileProcessor.php

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@
55
*/
66
namespace Magento\Customer\Model;
77

8-
use Magento\Framework\Session\SessionManagerInterface;
9-
10-
/**
11-
* Class FileProcessor
12-
*/
138
class FileProcessor
149
{
1510
/**
@@ -52,11 +47,6 @@ class FileProcessor
5247
*/
5348
private $mime;
5449

55-
/**
56-
* @var SessionManagerInterface
57-
*/
58-
private $session;
59-
6050
/**
6151
* @param \Magento\Framework\Filesystem $filesystem
6252
* @param \Magento\MediaStorage\Model\File\UploaderFactory $uploaderFactory
@@ -65,7 +55,6 @@ class FileProcessor
6555
* @param string $entityTypeCode
6656
* @param \Magento\Framework\File\Mime $mime
6757
* @param array $allowedExtensions
68-
* @param SessionManagerInterface|null $session
6958
*/
7059
public function __construct(
7160
\Magento\Framework\Filesystem $filesystem,
@@ -74,8 +63,7 @@ public function __construct(
7463
\Magento\Framework\Url\EncoderInterface $urlEncoder,
7564
$entityTypeCode,
7665
\Magento\Framework\File\Mime $mime,
77-
array $allowedExtensions = [],
78-
SessionManagerInterface $session = null
66+
array $allowedExtensions = []
7967
) {
8068
$this->mediaDirectory = $filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA);
8169
$this->uploaderFactory = $uploaderFactory;
@@ -84,7 +72,6 @@ public function __construct(
8472
$this->entityTypeCode = $entityTypeCode;
8573
$this->mime = $mime;
8674
$this->allowedExtensions = $allowedExtensions;
87-
$this->session = $session;
8875
}
8976

9077
/**
@@ -257,7 +244,7 @@ public function moveTemporaryFile($fileName)
257244
*/
258245
public function removeUploadedFile($fileName)
259246
{
260-
$filePath = $this->entityTypeCode . '/' . ltrim($fileName, '/').$this->session->getName();
247+
$filePath = $this->entityTypeCode . '/' . ltrim($fileName, '/');
261248

262249
$result = $this->mediaDirectory->delete($filePath);
263250
return $result;

app/code/Magento/Customer/Ui/Component/DataProvider/Document.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use Magento\Framework\Exception\NoSuchEntityException;
1313
use Magento\Customer\Api\GroupRepositoryInterface;
1414
use Magento\Framework\App\ObjectManager;
15-
use Magento\Framework\Stdlib\Cookie\CookieReaderInterface;
1615
use Magento\Store\Model\ScopeInterface;
1716
use Magento\Store\Model\StoreManagerInterface;
1817

@@ -71,11 +70,6 @@ class Document extends \Magento\Framework\View\Element\UiComponent\DataProvider\
7170
*/
7271
private $scopeConfig;
7372

74-
/**
75-
* @var CookieReaderInterface
76-
*/
77-
private $cookie;
78-
7973
/**
8074
* Document constructor.
8175
*
@@ -84,22 +78,19 @@ class Document extends \Magento\Framework\View\Element\UiComponent\DataProvider\
8478
* @param CustomerMetadataInterface $customerMetadata
8579
* @param StoreManagerInterface $storeManager
8680
* @param ScopeConfigInterface $scopeConfig
87-
* @param CookieReaderInterface|null $cookie
8881
*/
8982
public function __construct(
9083
AttributeValueFactory $attributeValueFactory,
9184
GroupRepositoryInterface $groupRepository,
9285
CustomerMetadataInterface $customerMetadata,
9386
StoreManagerInterface $storeManager,
94-
ScopeConfigInterface $scopeConfig = null,
95-
CookieReaderInterface $cookie = null
87+
ScopeConfigInterface $scopeConfig = null
9688
) {
9789
parent::__construct($attributeValueFactory);
9890
$this->customerMetadata = $customerMetadata;
9991
$this->groupRepository = $groupRepository;
10092
$this->storeManager = $storeManager;
10193
$this->scopeConfig = $scopeConfig ?: ObjectManager::getInstance()->create(ScopeConfigInterface::class);
102-
$this->cookie = $cookie;
10394
}
10495

10596
/**
@@ -138,7 +129,7 @@ private function setGenderValue()
138129
$value = $this->getData(self::$genderAttributeCode);
139130

140131
if (!$value) {
141-
$this->setCustomAttribute(self::$genderAttributeCode, $this->cookie->getCookie('NA'));
132+
$this->setCustomAttribute(self::$genderAttributeCode, 'N/A');
142133
return;
143134
}
144135

app/code/Magento/Rss/App/Action/Plugin/BackendAuthentication.php

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,11 @@
88
namespace Magento\Rss\App\Action\Plugin;
99

1010
use Magento\Backend\App\AbstractAction;
11-
use Magento\Backend\Model\Session;
1211
use Magento\Framework\App\RequestInterface;
1312
use Magento\Framework\App\ResponseInterface;
1413
use Magento\Framework\Exception\AuthenticationException;
1514

1615
/**
17-
* Backend auth.
18-
*
1916
* @api
2017
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2118
* @since 100.0.2
@@ -42,11 +39,6 @@ class BackendAuthentication extends \Magento\Backend\App\Action\Plugin\Authentic
4239
*/
4340
protected $aclResources;
4441

45-
/**
46-
* @var Session
47-
*/
48-
private $session;
49-
5042
/**
5143
* @param \Magento\Backend\Model\Auth $auth
5244
* @param \Magento\Backend\Model\UrlInterface $url
@@ -61,7 +53,6 @@ class BackendAuthentication extends \Magento\Backend\App\Action\Plugin\Authentic
6153
* @param \Psr\Log\LoggerInterface $logger
6254
* @param \Magento\Framework\AuthorizationInterface $authorization
6355
* @param array $aclResources
64-
* @param Session $session
6556
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
6657
*/
6758
public function __construct(
@@ -77,14 +68,12 @@ public function __construct(
7768
\Magento\Framework\HTTP\Authentication $httpAuthentication,
7869
\Psr\Log\LoggerInterface $logger,
7970
\Magento\Framework\AuthorizationInterface $authorization,
80-
array $aclResources,
81-
Session $session
71+
array $aclResources
8272
) {
8373
$this->httpAuthentication = $httpAuthentication;
8474
$this->logger = $logger;
8575
$this->authorization = $authorization;
8676
$this->aclResources = $aclResources;
87-
$this->session = $session;
8877
parent::__construct(
8978
$auth,
9079
$url,
@@ -117,7 +106,7 @@ public function aroundDispatch(AbstractAction $subject, \Closure $proceed, Reque
117106
: $this->aclResources[$request->getControllerName()]
118107
: null;
119108

120-
$type = $request->getParam('type'.$this->session->getName());
109+
$type = $request->getParam('type');
121110
$resourceType = isset($this->aclResources[$type]) ? $this->aclResources[$type] : null;
122111

123112
if (!$resource || !$resourceType) {

0 commit comments

Comments
 (0)