Skip to content

Commit 035e8d7

Browse files
author
rajneesh1dev
committed
Updated phpdocs, property access levels,removed underscore, added backward compatible constructor params
1 parent 55cf2dc commit 035e8d7

File tree

2 files changed

+41
-41
lines changed
  • app/code/Magento/Sitemap

2 files changed

+41
-41
lines changed

app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Save.php

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,29 @@ class Save extends \Magento\Sitemap\Controller\Adminhtml\Sitemap
1717
const MAX_FILENAME_LENGTH = 32;
1818

1919
/**
20-
* @var $_stringValidator
20+
* @var \Magento\Framework\Validator\StringLength
2121
*/
22-
public $_stringValidator;
22+
private $stringValidator;
2323

2424
/**
25-
* @var $_pathValidator
25+
* @var \Magento\MediaStorage\Model\File\Validator\AvailablePath
2626
*/
27-
public $_pathValidator;
27+
private $pathValidator;
2828

2929
/**
30-
* @var $_sitemapHelper
30+
* @var \Magento\Sitemap\Helper\Data
3131
*/
32-
public $_sitemapHelper;
32+
private $sitemapHelper;
3333

3434
/**
35-
* @var $_filesystem
35+
* @var \Magento\Framework\Filesystem
3636
*/
37-
public $_filesystem;
37+
private $filesystem;
3838

3939
/**
40-
* @var $_sitemapFactory
40+
* @var \Magento\Sitemap\Model\SitemapFactory
4141
*/
42-
public $_sitemapFactory;
42+
private $sitemapFactory;
4343

4444
/**
4545
* Save constructor.
@@ -52,18 +52,18 @@ class Save extends \Magento\Sitemap\Controller\Adminhtml\Sitemap
5252
*/
5353
public function __construct(
5454
\Magento\Backend\App\Action\Context $context,
55-
\Magento\Framework\Validator\StringLength $stringValidator,
56-
\Magento\MediaStorage\Model\File\Validator\AvailablePath $pathValidator,
57-
\Magento\Sitemap\Helper\Data $sitemapHelper,
58-
\Magento\Framework\Filesystem $filesystem,
59-
\Magento\Sitemap\Model\SitemapFactory $sitemapFactory
55+
\Magento\Framework\Validator\StringLength $stringValidator = null,
56+
\Magento\MediaStorage\Model\File\Validator\AvailablePath $pathValidator = null,
57+
\Magento\Sitemap\Helper\Data $sitemapHelper = null,
58+
\Magento\Framework\Filesystem $filesystem = null,
59+
\Magento\Sitemap\Model\SitemapFactory $sitemapFactory = null
6060
) {
6161
parent::__construct($context);
62-
$this->_stringValidator = $stringValidator;
63-
$this->_pathValidator = $pathValidator;
64-
$this->_sitemapHelper = $sitemapHelper;
65-
$this->_filesystem = $filesystem;
66-
$this->_sitemapFactory = $sitemapFactory;
62+
$this->stringValidator = $stringValidator ?: $this->_objectManager->get(\Magento\Framework\Validator\StringLength::class);
63+
$this->pathValidator = $pathValidator ?: $this->_objectManager->get(\Magento\MediaStorage\Model\File\Validator\AvailablePath::class);
64+
$this->sitemapHelper = $sitemapHelper ?: $this->_objectManager->get(\Magento\Sitemap\Helper\Data::class);
65+
$this->filesystem = $filesystem ?: $this->_objectManager->get(\Magento\Framework\Filesystem::class);
66+
$this->sitemapFactory = $sitemapFactory ?: $this->_objectManager->get(\Magento\Sitemap\Model\SitemapFactory::class);
6767
}
6868

6969
/**
@@ -78,9 +78,9 @@ protected function validatePath(array $data)
7878
if (!empty($data['sitemap_filename']) && !empty($data['sitemap_path'])) {
7979
$data['sitemap_path'] = '/' . ltrim($data['sitemap_path'], '/');
8080
$path = rtrim($data['sitemap_path'], '\\/') . '/' . $data['sitemap_filename'];
81-
$this->_pathValidator->setPaths($this->_sitemapHelper->getValidPaths());
82-
if (!$this->_pathValidator->isValid($path)) {
83-
foreach ($this->_pathValidator->getMessages() as $message) {
81+
$this->pathValidator->setPaths($this->sitemapHelper->getValidPaths());
82+
if (!$this->pathValidator->isValid($path)) {
83+
foreach ($this->pathValidator->getMessages() as $message) {
8484
$this->messageManager->addErrorMessage($message);
8585
}
8686
// save data in session
@@ -90,9 +90,9 @@ protected function validatePath(array $data)
9090
}
9191

9292
$filename = rtrim($data['sitemap_filename']);
93-
$this->_stringValidator->setMax(self::MAX_FILENAME_LENGTH);
94-
if (!$this->_stringValidator->isValid($filename)) {
95-
foreach ($this->_stringValidator->getMessages() as $message) {
93+
$this->stringValidator->setMax(self::MAX_FILENAME_LENGTH);
94+
if (!$this->stringValidator->isValid($filename)) {
95+
foreach ($this->stringValidator->getMessages() as $message) {
9696
$this->messageManager->addErrorMessage($message);
9797
}
9898
// save data in session
@@ -113,7 +113,7 @@ protected function validatePath(array $data)
113113
protected function clearSiteMap(\Magento\Sitemap\Model\Sitemap $model)
114114
{
115115
/** @var \Magento\Framework\Filesystem $directory */
116-
$directory = $this->_filesystem->getDirectoryWrite(DirectoryList::ROOT);
116+
$directory = $this->filesystem->getDirectoryWrite(DirectoryList::ROOT);
117117

118118
if ($this->getRequest()->getParam('sitemap_id')) {
119119
$model->load($this->getRequest()->getParam('sitemap_id'));
@@ -136,7 +136,7 @@ protected function saveData($data)
136136
{
137137
// init model and set data
138138
/** @var \Magento\Sitemap\Model\Sitemap $model */
139-
$model = $this->_sitemapFactory->create();
139+
$model = $this->sitemapFactory->create();
140140
$this->clearSiteMap($model);
141141
$model->setData($data);
142142

app/code/Magento/Sitemap/Test/Unit/Controller/Adminhtml/Sitemap/SaveTest.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,67 +14,67 @@ class SaveTest extends \PHPUnit\Framework\TestCase
1414
/**
1515
* @var \Magento\Sitemap\Controller\Adminhtml\Sitemap\Save
1616
*/
17-
protected $saveController;
17+
private $saveController;
1818

1919
/**
2020
* @var \Magento\Backend\App\Action\Context
2121
*/
22-
protected $contextMock;
22+
private $contextMock;
2323

2424
/**
2525
* @var \Magento\Framework\HTTP\PhpEnvironment\Request|\PHPUnit_Framework_MockObject_MockObject
2626
*/
27-
protected $requestMock;
27+
private $requestMock;
2828

2929
/**
3030
* @var \Magento\Framework\Controller\ResultFactory|\PHPUnit_Framework_MockObject_MockObject
3131
*/
32-
protected $resultFactoryMock;
32+
private $resultFactoryMock;
3333

3434
/**
3535
* @var \Magento\Backend\Model\View\Result\Redirect|\PHPUnit_Framework_MockObject_MockObject
3636
*/
37-
protected $resultRedirectMock;
37+
private $resultRedirectMock;
3838

3939
/**
4040
* @var \Magento\Framework\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject
4141
*/
42-
protected $objectManagerMock;
42+
private $objectManagerMock;
4343

4444
/**
4545
* @var \Magento\Framework\Message\ManagerInterface|\PHPUnit_Framework_MockObject_MockObject
4646
*/
47-
protected $messageManagerMock;
47+
private $messageManagerMock;
4848

4949
/**
5050
* @var \Magento\Framework\Validator\StringLength|\PHPUnit_Framework_MockObject_MockObject
5151
*/
52-
protected $lengthValidator;
52+
private $lengthValidator;
5353

5454
/**
5555
* @var \Magento\MediaStorage\Model\File\Validator\AvailablePath|\PHPUnit_Framework_MockObject_MockObject
5656
*/
57-
protected $pathValidator;
57+
private $pathValidator;
5858

5959
/**
6060
* @var \Magento\Sitemap\Helper\Data|\PHPUnit_Framework_MockObject_MockObject
6161
*/
62-
protected $helper;
62+
private $helper;
6363

6464
/**
6565
* @var \Magento\Framework\Filesystem|\PHPUnit_Framework_MockObject_MockObject
6666
*/
67-
protected $fileSystem;
67+
private $fileSystem;
6868

6969
/**
7070
* @var \Magento\Sitemap\Model\SitemapFactory|\PHPUnit_Framework_MockObject_MockObject
7171
*/
72-
protected $siteMapFactory;
72+
private $siteMapFactory;
7373

7474
/**
7575
* @var \Magento\Backend\Model\Session|\PHPUnit_Framework_MockObject_MockObject
7676
*/
77-
protected $session;
77+
private $session;
7878

7979
protected function setUp()
8080
{

0 commit comments

Comments
 (0)