From 035e8d736961c1a074b8a732ec3bbd993670aacc Mon Sep 17 00:00:00 2001 From: rajneesh1dev Date: Tue, 22 Jan 2019 11:24:14 +0530 Subject: [PATCH] Updated phpdocs, property access levels,removed underscore, added backward compatible constructor params --- .../Controller/Adminhtml/Sitemap/Save.php | 56 +++++++++---------- .../Controller/Adminhtml/Sitemap/SaveTest.php | 26 ++++----- 2 files changed, 41 insertions(+), 41 deletions(-) diff --git a/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Save.php b/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Save.php index 23e1d2e786900..d0cb650028e99 100644 --- a/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Save.php +++ b/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Save.php @@ -17,29 +17,29 @@ class Save extends \Magento\Sitemap\Controller\Adminhtml\Sitemap const MAX_FILENAME_LENGTH = 32; /** - * @var $_stringValidator + * @var \Magento\Framework\Validator\StringLength */ - public $_stringValidator; + private $stringValidator; /** - * @var $_pathValidator + * @var \Magento\MediaStorage\Model\File\Validator\AvailablePath */ - public $_pathValidator; + private $pathValidator; /** - * @var $_sitemapHelper + * @var \Magento\Sitemap\Helper\Data */ - public $_sitemapHelper; + private $sitemapHelper; /** - * @var $_filesystem + * @var \Magento\Framework\Filesystem */ - public $_filesystem; + private $filesystem; /** - * @var $_sitemapFactory + * @var \Magento\Sitemap\Model\SitemapFactory */ - public $_sitemapFactory; + private $sitemapFactory; /** * Save constructor. @@ -52,18 +52,18 @@ class Save extends \Magento\Sitemap\Controller\Adminhtml\Sitemap */ public function __construct( \Magento\Backend\App\Action\Context $context, - \Magento\Framework\Validator\StringLength $stringValidator, - \Magento\MediaStorage\Model\File\Validator\AvailablePath $pathValidator, - \Magento\Sitemap\Helper\Data $sitemapHelper, - \Magento\Framework\Filesystem $filesystem, - \Magento\Sitemap\Model\SitemapFactory $sitemapFactory + \Magento\Framework\Validator\StringLength $stringValidator = null, + \Magento\MediaStorage\Model\File\Validator\AvailablePath $pathValidator = null, + \Magento\Sitemap\Helper\Data $sitemapHelper = null, + \Magento\Framework\Filesystem $filesystem = null, + \Magento\Sitemap\Model\SitemapFactory $sitemapFactory = null ) { parent::__construct($context); - $this->_stringValidator = $stringValidator; - $this->_pathValidator = $pathValidator; - $this->_sitemapHelper = $sitemapHelper; - $this->_filesystem = $filesystem; - $this->_sitemapFactory = $sitemapFactory; + $this->stringValidator = $stringValidator ?: $this->_objectManager->get(\Magento\Framework\Validator\StringLength::class); + $this->pathValidator = $pathValidator ?: $this->_objectManager->get(\Magento\MediaStorage\Model\File\Validator\AvailablePath::class); + $this->sitemapHelper = $sitemapHelper ?: $this->_objectManager->get(\Magento\Sitemap\Helper\Data::class); + $this->filesystem = $filesystem ?: $this->_objectManager->get(\Magento\Framework\Filesystem::class); + $this->sitemapFactory = $sitemapFactory ?: $this->_objectManager->get(\Magento\Sitemap\Model\SitemapFactory::class); } /** @@ -78,9 +78,9 @@ protected function validatePath(array $data) if (!empty($data['sitemap_filename']) && !empty($data['sitemap_path'])) { $data['sitemap_path'] = '/' . ltrim($data['sitemap_path'], '/'); $path = rtrim($data['sitemap_path'], '\\/') . '/' . $data['sitemap_filename']; - $this->_pathValidator->setPaths($this->_sitemapHelper->getValidPaths()); - if (!$this->_pathValidator->isValid($path)) { - foreach ($this->_pathValidator->getMessages() as $message) { + $this->pathValidator->setPaths($this->sitemapHelper->getValidPaths()); + if (!$this->pathValidator->isValid($path)) { + foreach ($this->pathValidator->getMessages() as $message) { $this->messageManager->addErrorMessage($message); } // save data in session @@ -90,9 +90,9 @@ protected function validatePath(array $data) } $filename = rtrim($data['sitemap_filename']); - $this->_stringValidator->setMax(self::MAX_FILENAME_LENGTH); - if (!$this->_stringValidator->isValid($filename)) { - foreach ($this->_stringValidator->getMessages() as $message) { + $this->stringValidator->setMax(self::MAX_FILENAME_LENGTH); + if (!$this->stringValidator->isValid($filename)) { + foreach ($this->stringValidator->getMessages() as $message) { $this->messageManager->addErrorMessage($message); } // save data in session @@ -113,7 +113,7 @@ protected function validatePath(array $data) protected function clearSiteMap(\Magento\Sitemap\Model\Sitemap $model) { /** @var \Magento\Framework\Filesystem $directory */ - $directory = $this->_filesystem->getDirectoryWrite(DirectoryList::ROOT); + $directory = $this->filesystem->getDirectoryWrite(DirectoryList::ROOT); if ($this->getRequest()->getParam('sitemap_id')) { $model->load($this->getRequest()->getParam('sitemap_id')); @@ -136,7 +136,7 @@ protected function saveData($data) { // init model and set data /** @var \Magento\Sitemap\Model\Sitemap $model */ - $model = $this->_sitemapFactory->create(); + $model = $this->sitemapFactory->create(); $this->clearSiteMap($model); $model->setData($data); diff --git a/app/code/Magento/Sitemap/Test/Unit/Controller/Adminhtml/Sitemap/SaveTest.php b/app/code/Magento/Sitemap/Test/Unit/Controller/Adminhtml/Sitemap/SaveTest.php index 0e5758a3d8f48..70a8ab700d301 100644 --- a/app/code/Magento/Sitemap/Test/Unit/Controller/Adminhtml/Sitemap/SaveTest.php +++ b/app/code/Magento/Sitemap/Test/Unit/Controller/Adminhtml/Sitemap/SaveTest.php @@ -14,67 +14,67 @@ class SaveTest extends \PHPUnit\Framework\TestCase /** * @var \Magento\Sitemap\Controller\Adminhtml\Sitemap\Save */ - protected $saveController; + private $saveController; /** * @var \Magento\Backend\App\Action\Context */ - protected $contextMock; + private $contextMock; /** * @var \Magento\Framework\HTTP\PhpEnvironment\Request|\PHPUnit_Framework_MockObject_MockObject */ - protected $requestMock; + private $requestMock; /** * @var \Magento\Framework\Controller\ResultFactory|\PHPUnit_Framework_MockObject_MockObject */ - protected $resultFactoryMock; + private $resultFactoryMock; /** * @var \Magento\Backend\Model\View\Result\Redirect|\PHPUnit_Framework_MockObject_MockObject */ - protected $resultRedirectMock; + private $resultRedirectMock; /** * @var \Magento\Framework\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject */ - protected $objectManagerMock; + private $objectManagerMock; /** * @var \Magento\Framework\Message\ManagerInterface|\PHPUnit_Framework_MockObject_MockObject */ - protected $messageManagerMock; + private $messageManagerMock; /** * @var \Magento\Framework\Validator\StringLength|\PHPUnit_Framework_MockObject_MockObject */ - protected $lengthValidator; + private $lengthValidator; /** * @var \Magento\MediaStorage\Model\File\Validator\AvailablePath|\PHPUnit_Framework_MockObject_MockObject */ - protected $pathValidator; + private $pathValidator; /** * @var \Magento\Sitemap\Helper\Data|\PHPUnit_Framework_MockObject_MockObject */ - protected $helper; + private $helper; /** * @var \Magento\Framework\Filesystem|\PHPUnit_Framework_MockObject_MockObject */ - protected $fileSystem; + private $fileSystem; /** * @var \Magento\Sitemap\Model\SitemapFactory|\PHPUnit_Framework_MockObject_MockObject */ - protected $siteMapFactory; + private $siteMapFactory; /** * @var \Magento\Backend\Model\Session|\PHPUnit_Framework_MockObject_MockObject */ - protected $session; + private $session; protected function setUp() {