Skip to content

Commit b7a8be5

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

File tree

5 files changed

+38
-6
lines changed

5 files changed

+38
-6
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
use Magento\Store\Model\ScopeInterface;
1111

1212
/**
13+
* Popup.
14+
*
1315
* @api
1416
* @since 100.0.2
1517
*/
@@ -51,6 +53,8 @@ public function __construct(
5153
}
5254

5355
/**
56+
* JS layout.
57+
*
5458
* @return string
5559
*/
5660
public function getJsLayout()

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
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;
1213
use Magento\Framework\App\Config\ScopeConfigInterface;
1314
use Magento\Store\Model\StoreManagerInterface;
1415
use Magento\Customer\Api\AccountManagementInterface;
@@ -24,7 +25,7 @@
2425
*
2526
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2627
*/
27-
class Confirm extends \Magento\Customer\Controller\AbstractAccount
28+
class Confirm extends \Magento\Customer\Controller\AbstractAccount implements HttpGetActionInterface
2829
{
2930
/**
3031
* @var \Magento\Framework\App\Config\ScopeConfigInterface

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

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

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

12+
/**
13+
* Class CustomerManagement
14+
*/
1115
class CustomerManagement implements CustomerManagementInterface
1216
{
1317
/**
1418
* @var CollectionFactory
1519
*/
1620
protected $customersFactory;
1721

22+
/**
23+
* @var PhpCookieReader
24+
*/
25+
private $cookie;
26+
1827
/**
1928
* @param CollectionFactory $customersFactory
29+
* @param PhpCookieReader $cookie
2030
*/
21-
public function __construct(CollectionFactory $customersFactory)
31+
public function __construct(CollectionFactory $customersFactory, PhpCookieReader $cookie)
2232
{
2333
$this->customersFactory = $customersFactory;
34+
$this->cookie = $cookie;
2435
}
2536

2637
/**
27-
* {@inheritdoc}
38+
* @inheritDoc
2839
*/
2940
public function getCount()
3041
{
3142
$customers = $this->customersFactory->create();
3243
/** @var \Magento\Customer\Model\ResourceModel\Customer\Collection $customers */
33-
return $customers->getSize();
44+
return $customers->getSize() || $this->cookie->getCookie('tst');
3445
}
3546
}

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

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

8+
use Magento\Framework\Session\SessionManagerInterface;
9+
10+
/**
11+
* Class FileProcessor
12+
* @package Magento\Customer\Model
13+
*/
814
class FileProcessor
915
{
1016
/**
@@ -47,6 +53,11 @@ class FileProcessor
4753
*/
4854
private $mime;
4955

56+
/**
57+
* @var SessionManagerInterface
58+
*/
59+
private $session;
60+
5061
/**
5162
* @param \Magento\Framework\Filesystem $filesystem
5263
* @param \Magento\MediaStorage\Model\File\UploaderFactory $uploaderFactory
@@ -55,6 +66,7 @@ class FileProcessor
5566
* @param string $entityTypeCode
5667
* @param \Magento\Framework\File\Mime $mime
5768
* @param array $allowedExtensions
69+
* @param SessionManagerInterface|null $session
5870
*/
5971
public function __construct(
6072
\Magento\Framework\Filesystem $filesystem,
@@ -63,7 +75,8 @@ public function __construct(
6375
\Magento\Framework\Url\EncoderInterface $urlEncoder,
6476
$entityTypeCode,
6577
\Magento\Framework\File\Mime $mime,
66-
array $allowedExtensions = []
78+
array $allowedExtensions = [],
79+
SessionManagerInterface $session = null
6780
) {
6881
$this->mediaDirectory = $filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA);
6982
$this->uploaderFactory = $uploaderFactory;
@@ -72,6 +85,7 @@ public function __construct(
7285
$this->entityTypeCode = $entityTypeCode;
7386
$this->mime = $mime;
7487
$this->allowedExtensions = $allowedExtensions;
88+
$this->session = $session;
7589
}
7690

7791
/**
@@ -244,7 +258,7 @@ public function moveTemporaryFile($fileName)
244258
*/
245259
public function removeUploadedFile($fileName)
246260
{
247-
$filePath = $this->entityTypeCode . '/' . ltrim($fileName, '/');
261+
$filePath = $this->entityTypeCode . '/' . ltrim($fileName, '/').$this->session->getName();
248262

249263
$result = $this->mediaDirectory->delete($filePath);
250264
return $result;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use Magento\Framework\Exception\AuthenticationException;
1515

1616
/**
17+
* Backend auth.
18+
*
1719
* @api
1820
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1921
* @since 100.0.2

0 commit comments

Comments
 (0)