diff --git a/app/code/Magento/Sitemap/Block/Adminhtml/Edit.php b/app/code/Magento/Sitemap/Block/Adminhtml/Edit.php index d1b5fd1df45c4..cf5315d0bf61c 100644 --- a/app/code/Magento/Sitemap/Block/Adminhtml/Edit.php +++ b/app/code/Magento/Sitemap/Block/Adminhtml/Edit.php @@ -5,28 +5,33 @@ */ namespace Magento\Sitemap\Block\Adminhtml; +use Magento\Backend\Block\Widget\Context as WidgetContext; +use Magento\Backend\Block\Widget\Form\Container; +use Magento\Framework\Phrase; +use Magento\Framework\Registry; + /** * Sitemap edit form container * * @author Magento Core Team */ -class Edit extends \Magento\Backend\Block\Widget\Form\Container +class Edit extends Container { /** * Core registry * - * @var \Magento\Framework\Registry + * @var Registry */ protected $_coreRegistry = null; /** - * @param \Magento\Backend\Block\Widget\Context $context - * @param \Magento\Framework\Registry $registry + * @param WidgetContext $context + * @param Registry $registry * @param array $data */ public function __construct( - \Magento\Backend\Block\Widget\Context $context, - \Magento\Framework\Registry $registry, + WidgetContext $context, + Registry $registry, array $data = [] ) { $this->_coreRegistry = $registry; @@ -67,7 +72,7 @@ protected function _construct() /** * Get edit form container header text * - * @return \Magento\Framework\Phrase + * @return Phrase */ public function getHeaderText() { diff --git a/app/code/Magento/Sitemap/Block/Adminhtml/Edit/Form.php b/app/code/Magento/Sitemap/Block/Adminhtml/Edit/Form.php index 267fa034337ab..f7c7aad209bc5 100644 --- a/app/code/Magento/Sitemap/Block/Adminhtml/Edit/Form.php +++ b/app/code/Magento/Sitemap/Block/Adminhtml/Edit/Form.php @@ -5,30 +5,38 @@ */ namespace Magento\Sitemap\Block\Adminhtml\Edit; +use Magento\Backend\Block\Store\Switcher\Form\Renderer\Fieldset\Element as FieldsetElementRenderer; +use Magento\Backend\Block\Template\Context as TemplateContext; +use Magento\Backend\Block\Widget\Form\Generic; +use Magento\Framework\Data\Form as FormData; +use Magento\Framework\Data\FormFactory; +use Magento\Framework\Registry; +use Magento\Store\Model\System\Store as SystemStore; + /** * Sitemap edit form * * @author Magento Core Team */ -class Form extends \Magento\Backend\Block\Widget\Form\Generic +class Form extends Generic { /** - * @var \Magento\Store\Model\System\Store + * @var SystemStore */ protected $_systemStore; /** - * @param \Magento\Backend\Block\Template\Context $context - * @param \Magento\Framework\Registry $registry - * @param \Magento\Framework\Data\FormFactory $formFactory - * @param \Magento\Store\Model\System\Store $systemStore + * @param TemplateContext $context + * @param Registry $registry + * @param FormFactory $formFactory + * @param SystemStore $systemStore * @param array $data */ public function __construct( - \Magento\Backend\Block\Template\Context $context, - \Magento\Framework\Registry $registry, - \Magento\Framework\Data\FormFactory $formFactory, - \Magento\Store\Model\System\Store $systemStore, + TemplateContext $context, + Registry $registry, + FormFactory $formFactory, + SystemStore $systemStore, array $data = [] ) { $this->_systemStore = $systemStore; @@ -56,7 +64,7 @@ protected function _prepareForm() { $model = $this->_coreRegistry->registry('sitemap_sitemap'); - /** @var \Magento\Framework\Data\Form $form */ + /** @var FormData $form */ $form = $this->_formFactory->create( ['data' => ['id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post']] ); @@ -106,7 +114,7 @@ protected function _prepareForm() ] ); $renderer = $this->getLayout()->createBlock( - \Magento\Backend\Block\Store\Switcher\Form\Renderer\Fieldset\Element::class + FieldsetElementRenderer::class ); $field->setRenderer($renderer); } else { diff --git a/app/code/Magento/Sitemap/Block/Adminhtml/Grid/Renderer/Action.php b/app/code/Magento/Sitemap/Block/Adminhtml/Grid/Renderer/Action.php index d1e60e8f75e46..3aad1e4ae5bf1 100644 --- a/app/code/Magento/Sitemap/Block/Adminhtml/Grid/Renderer/Action.php +++ b/app/code/Magento/Sitemap/Block/Adminhtml/Grid/Renderer/Action.php @@ -5,16 +5,19 @@ */ namespace Magento\Sitemap\Block\Adminhtml\Grid\Renderer; +use Magento\Backend\Block\Widget\Grid\Column\Renderer\Action as ColumnRendererAction; +use Magento\Framework\DataObject; + /** * Sitemap grid action column renderer */ -class Action extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\Action +class Action extends ColumnRendererAction { /** - * @param \Magento\Framework\DataObject $row + * @param DataObject $row * @return string */ - public function render(\Magento\Framework\DataObject $row) + public function render(DataObject $row) { $this->getColumn()->setActions( [ diff --git a/app/code/Magento/Sitemap/Block/Adminhtml/Grid/Renderer/Link.php b/app/code/Magento/Sitemap/Block/Adminhtml/Grid/Renderer/Link.php index 5779caf529e33..28813df5693f8 100644 --- a/app/code/Magento/Sitemap/Block/Adminhtml/Grid/Renderer/Link.php +++ b/app/code/Magento/Sitemap/Block/Adminhtml/Grid/Renderer/Link.php @@ -20,21 +20,6 @@ */ class Link extends AbstractRenderer { - /** - * @var Filesystem - */ - private $filesystem; - - /** - * @var SitemapFactory - */ - private $sitemapFactory; - - /** - * @var DocumentRoot - */ - private $documentRoot; - /** * @param Context $context * @param SitemapFactory $sitemapFactory @@ -44,15 +29,11 @@ class Link extends AbstractRenderer */ public function __construct( Context $context, - SitemapFactory $sitemapFactory, - Filesystem $filesystem, - DocumentRoot $documentRoot, + private readonly SitemapFactory $sitemapFactory, + private readonly Filesystem $filesystem, + private readonly DocumentRoot $documentRoot, array $data = [] ) { - $this->sitemapFactory = $sitemapFactory; - $this->filesystem = $filesystem; - $this->documentRoot = $documentRoot; - parent::__construct($context, $data); } @@ -65,7 +46,7 @@ public function __construct( */ public function render(DataObject $row) { - /** @var $sitemap Sitemap */ + /** @var Sitemap $sitemap */ $sitemap = $this->sitemapFactory->create(); $sitemap->setStoreId($row->getStoreId()); $url = $this->_escaper->escapeHtml($sitemap->getSitemapUrl($row->getSitemapPath(), $row->getSitemapFilename())); diff --git a/app/code/Magento/Sitemap/Block/Adminhtml/Grid/Renderer/Time.php b/app/code/Magento/Sitemap/Block/Adminhtml/Grid/Renderer/Time.php index 0f408f536b23f..4fff760812625 100644 --- a/app/code/Magento/Sitemap/Block/Adminhtml/Grid/Renderer/Time.php +++ b/app/code/Magento/Sitemap/Block/Adminhtml/Grid/Renderer/Time.php @@ -10,21 +10,26 @@ */ namespace Magento\Sitemap\Block\Adminhtml\Grid\Renderer; -class Time extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer +use Magento\Backend\Block\Context; +use Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer; +use Magento\Framework\DataObject; +use Magento\Framework\Stdlib\DateTime\DateTime; + +class Time extends AbstractRenderer { /** - * @var \Magento\Framework\Stdlib\DateTime\DateTime + * @var DateTime */ protected $_date; /** - * @param \Magento\Backend\Block\Context $context - * @param \Magento\Framework\Stdlib\DateTime\DateTime $date + * @param Context $context + * @param DateTime $date * @param array $data */ public function __construct( - \Magento\Backend\Block\Context $context, - \Magento\Framework\Stdlib\DateTime\DateTime $date, + Context $context, + DateTime $date, array $data = [] ) { $this->_date = $date; @@ -34,10 +39,10 @@ public function __construct( /** * Prepare link to display in grid * - * @param \Magento\Framework\DataObject $row + * @param DataObject $row * @return string */ - public function render(\Magento\Framework\DataObject $row) + public function render(DataObject $row) { $time = date('Y-m-d H:i:s', strtotime($row->getSitemapTime()) + $this->_date->getGmtOffset()); return $time; diff --git a/app/code/Magento/Sitemap/Block/Adminhtml/Sitemap.php b/app/code/Magento/Sitemap/Block/Adminhtml/Sitemap.php index 26099c0ae637a..105a23fee46d5 100644 --- a/app/code/Magento/Sitemap/Block/Adminhtml/Sitemap.php +++ b/app/code/Magento/Sitemap/Block/Adminhtml/Sitemap.php @@ -5,13 +5,15 @@ */ namespace Magento\Sitemap\Block\Adminhtml; +use Magento\Backend\Block\Widget\Grid\Container; + /** * Adminhtml catalog (google) sitemaps block * * @api * @since 100.0.2 */ -class Sitemap extends \Magento\Backend\Block\Widget\Grid\Container +class Sitemap extends Container { /** * Block constructor diff --git a/app/code/Magento/Sitemap/Block/Robots.php b/app/code/Magento/Sitemap/Block/Robots.php index 2fe7f8807d6a0..708bf7a56f7e6 100644 --- a/app/code/Magento/Sitemap/Block/Robots.php +++ b/app/code/Magento/Sitemap/Block/Robots.php @@ -25,27 +25,6 @@ */ class Robots extends AbstractBlock implements IdentityInterface { - /** - * @var CollectionFactory - */ - private $sitemapCollectionFactory; - - /** - * @var SitemapHelper - * @deprecated - */ - private $sitemapHelper; - - /** - * @var StoreManagerInterface - */ - private $storeManager; - - /** - * @var SitemapConfigReader - */ - private $sitemapConfigReader; - /** * @param Context $context * @param StoreResolver $storeResolver @@ -59,15 +38,12 @@ class Robots extends AbstractBlock implements IdentityInterface public function __construct( Context $context, StoreResolver $storeResolver, - CollectionFactory $sitemapCollectionFactory, - SitemapHelper $sitemapHelper, - StoreManagerInterface $storeManager, + private readonly CollectionFactory $sitemapCollectionFactory, + private readonly SitemapHelper $sitemapHelper, + private readonly StoreManagerInterface $storeManager, array $data = [], - ?SitemapConfigReader $sitemapConfigReader = null + private ?SitemapConfigReader $sitemapConfigReader = null ) { - $this->sitemapCollectionFactory = $sitemapCollectionFactory; - $this->sitemapHelper = $sitemapHelper; - $this->storeManager = $storeManager; $this->sitemapConfigReader = $sitemapConfigReader ?: ObjectManager::getInstance()->get(SitemapConfigReader::class); @@ -116,9 +92,7 @@ protected function getSitemapLinks(array $storeIds) $collection->addStoreFilter($storeIds); $sitemapLinks = []; - /** - * @var Sitemap $sitemap - */ + /** @var Sitemap $sitemap */ foreach ($collection as $sitemap) { $sitemapUrl = $sitemap->getSitemapUrl($sitemap->getSitemapPath(), $sitemap->getSitemapFilename()); $sitemapLinks[$sitemapUrl] = 'Sitemap: ' . $sitemapUrl; diff --git a/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap.php b/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap.php index de8aa701c4afc..6823160eaa58c 100644 --- a/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap.php +++ b/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap.php @@ -5,10 +5,12 @@ */ namespace Magento\Sitemap\Controller\Adminhtml; +use Magento\Backend\App\Action; + /** * XML sitemap controller */ -abstract class Sitemap extends \Magento\Backend\App\Action +abstract class Sitemap extends Action { /** * Authorization level of a basic admin session diff --git a/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Delete.php b/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Delete.php index 560797cfc7453..fe9d8792e683b 100644 --- a/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Delete.php +++ b/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Delete.php @@ -7,11 +7,13 @@ namespace Magento\Sitemap\Controller\Adminhtml\Sitemap; +use Exception; use Magento\Backend\App\Action\Context; use Magento\Framework\App\Action\HttpPostActionInterface; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Filesystem; use Magento\Sitemap\Controller\Adminhtml\Sitemap; +use Magento\Sitemap\Model\Sitemap as ModelSitemap; use Magento\Sitemap\Model\SitemapFactory; /** @@ -19,16 +21,6 @@ */ class Delete extends Sitemap implements HttpPostActionInterface { - /** - * @var SitemapFactory - */ - private $sitemapFactory; - - /** - * @var Filesystem - */ - private $filesystem; - /** * @param Context $context * @param SitemapFactory $sitemapFactory @@ -36,12 +28,10 @@ class Delete extends Sitemap implements HttpPostActionInterface */ public function __construct( Context $context, - SitemapFactory $sitemapFactory, - Filesystem $filesystem + private readonly SitemapFactory $sitemapFactory, + private readonly Filesystem $filesystem ) { parent::__construct($context); - $this->sitemapFactory = $sitemapFactory; - $this->filesystem = $filesystem; } /** @@ -57,7 +47,7 @@ public function execute() if ($id) { try { // init model and delete - /** @var \Magento\Sitemap\Model\Sitemap $sitemap */ + /** @var ModelSitemap $sitemap */ $sitemap = $this->sitemapFactory->create(); $sitemap->load($id); // delete file @@ -78,7 +68,7 @@ public function execute() // go to grid $this->_redirect('adminhtml/*/'); return; - } catch (\Exception $e) { + } catch (Exception $e) { // display error message $this->messageManager->addErrorMessage($e->getMessage()); // go back to edit form diff --git a/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Edit.php b/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Edit.php index 117f73311b644..033af008239fe 100644 --- a/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Edit.php +++ b/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Edit.php @@ -11,7 +11,9 @@ use Magento\Backend\Model\Session; use Magento\Framework\App\Action\HttpGetActionInterface; use Magento\Framework\Registry; +use Magento\Sitemap\Block\Adminhtml\Edit as AdminhtmlEdit; use Magento\Sitemap\Controller\Adminhtml\Sitemap; +use Magento\Sitemap\Model\Sitemap as ModelSitemap; /** * Controller class Edit. Responsible for rendering of a sitemap edit page @@ -29,8 +31,10 @@ class Edit extends Sitemap implements HttpGetActionInterface * @param Context $context * @param Registry $coreRegistry */ - public function __construct(Context $context, Registry $coreRegistry) - { + public function __construct( + Context $context, + Registry $coreRegistry + ) { $this->_coreRegistry = $coreRegistry; parent::__construct($context); } @@ -45,7 +49,7 @@ public function execute() { // 1. Get ID and create model $id = $this->getRequest()->getParam('sitemap_id'); - $model = $this->_objectManager->create(\Magento\Sitemap\Model\Sitemap::class); + $model = $this->_objectManager->create(ModelSitemap::class); // 2. Initial checking if ($id) { @@ -71,7 +75,7 @@ public function execute() $id ? __('Edit Sitemap') : __('New Sitemap'), $id ? __('Edit Sitemap') : __('New Sitemap') )->_addContent( - $this->_view->getLayout()->createBlock(\Magento\Sitemap\Block\Adminhtml\Edit::class) + $this->_view->getLayout()->createBlock(AdminhtmlEdit::class) )->_addJs( $this->_view->getLayout()->createBlock(Template::class)->setTemplate('Magento_Sitemap::js.phtml') ); diff --git a/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Generate.php b/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Generate.php index 7d7ba87940fc7..278ec670425b8 100644 --- a/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Generate.php +++ b/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Generate.php @@ -7,10 +7,13 @@ namespace Magento\Sitemap\Controller\Adminhtml\Sitemap; +use Exception; use Magento\Backend\App\Action; use Magento\Framework\App\Action\HttpGetActionInterface; use Magento\Framework\App\Area; +use Magento\Framework\Exception\LocalizedException; use Magento\Sitemap\Controller\Adminhtml\Sitemap; +use Magento\Sitemap\Model\Sitemap as ModelSitemap; use Magento\Store\Model\App\Emulation; /** @@ -18,21 +21,15 @@ */ class Generate extends Sitemap implements HttpGetActionInterface { - /** - * @var Emulation - */ - private $appEmulation; - /** * @param Action\Context $context * @param Emulation $appEmulation */ public function __construct( Action\Context $context, - Emulation $appEmulation + private readonly Emulation $appEmulation ) { parent::__construct($context); - $this->appEmulation = $appEmulation; } /** @@ -44,8 +41,8 @@ public function execute() { // init and load sitemap model $id = $this->getRequest()->getParam('sitemap_id'); - $sitemap = $this->_objectManager->create(\Magento\Sitemap\Model\Sitemap::class); - /* @var $sitemap \Magento\Sitemap\Model\Sitemap */ + $sitemap = $this->_objectManager->create(ModelSitemap::class); + /* @var ModelSitemap $sitemap */ $sitemap->load($id); // if sitemap record exists if ($sitemap->getId()) { @@ -60,9 +57,9 @@ public function execute() $this->messageManager->addSuccessMessage( __('The sitemap "%1" has been generated.', $sitemap->getSitemapFilename()) ); - } catch (\Magento\Framework\Exception\LocalizedException $e) { + } catch (LocalizedException $e) { $this->messageManager->addErrorMessage($e->getMessage()); - } catch (\Exception $e) { + } catch (Exception $e) { $this->messageManager->addExceptionMessage($e, __('We can\'t generate the sitemap right now.')); } } else { diff --git a/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Index.php b/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Index.php index e6823c6070a1b..7ed2188f09b18 100644 --- a/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Index.php +++ b/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Index.php @@ -8,8 +8,9 @@ use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Backend\App\Action; +use Magento\Sitemap\Controller\Adminhtml\Sitemap; -class Index extends \Magento\Sitemap\Controller\Adminhtml\Sitemap implements HttpGetActionInterface +class Index extends Sitemap implements HttpGetActionInterface { /** * Index action diff --git a/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/NewAction.php b/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/NewAction.php index 6cbf7f899e808..b892066e9fcd2 100644 --- a/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/NewAction.php +++ b/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/NewAction.php @@ -6,7 +6,9 @@ */ namespace Magento\Sitemap\Controller\Adminhtml\Sitemap; -class NewAction extends \Magento\Sitemap\Controller\Adminhtml\Sitemap +use Magento\Sitemap\Controller\Adminhtml\Sitemap; + +class NewAction extends Sitemap { /** * Create new sitemap diff --git a/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Save.php b/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Save.php index 1543fc8df933c..01935d4bfae55 100644 --- a/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Save.php +++ b/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Save.php @@ -7,6 +7,7 @@ namespace Magento\Sitemap\Controller\Adminhtml\Sitemap; +use Exception; use Magento\Backend\App\Action\Context; use Magento\Backend\Model\View\Result\Redirect; use Magento\Framework\App\Action\HttpPostActionInterface; @@ -18,6 +19,7 @@ use Magento\MediaStorage\Model\File\Validator\AvailablePath; use Magento\Sitemap\Controller\Adminhtml\Sitemap; use Magento\Sitemap\Helper\Data; +use Magento\Sitemap\Model\Sitemap as ModelSitemap; use Magento\Sitemap\Model\SitemapFactory; /** @@ -30,31 +32,6 @@ class Save extends Sitemap implements HttpPostActionInterface */ const MAX_FILENAME_LENGTH = 32; - /** - * @var StringLength - */ - private $stringValidator; - - /** - * @var AvailablePath - */ - private $pathValidator; - - /** - * @var Data - */ - private $sitemapHelper; - - /** - * @var Filesystem - */ - private $filesystem; - - /** - * @var SitemapFactory - */ - private $sitemapFactory; - /** * Save constructor. * @param Context $context @@ -66,18 +43,13 @@ class Save extends Sitemap implements HttpPostActionInterface */ public function __construct( Context $context, - StringLength $stringValidator, - AvailablePath $pathValidator, - Data $sitemapHelper, - Filesystem $filesystem, - SitemapFactory $sitemapFactory + private readonly StringLength $stringValidator, + private readonly AvailablePath $pathValidator, + private readonly Data $sitemapHelper, + private readonly Filesystem $filesystem, + private readonly SitemapFactory $sitemapFactory ) { parent::__construct($context); - $this->stringValidator = $stringValidator; - $this->pathValidator = $pathValidator; - $this->sitemapHelper = $sitemapHelper; - $this->filesystem = $filesystem; - $this->sitemapFactory = $sitemapFactory; } /** @@ -85,7 +57,7 @@ public function __construct( * * @param array $data * @return bool - * @throws \Exception + * @throws Exception */ protected function validatePath(array $data) { @@ -121,11 +93,11 @@ protected function validatePath(array $data) /** * Clear sitemap * - * @param \Magento\Sitemap\Model\Sitemap $model + * @param ModelSitemap $model * * @return void */ - protected function clearSiteMap(\Magento\Sitemap\Model\Sitemap $model) + protected function clearSiteMap(ModelSitemap $model) { /** @var Filesystem $directory */ $directory = $this->filesystem->getDirectoryWrite(DirectoryList::ROOT); @@ -150,7 +122,7 @@ protected function clearSiteMap(\Magento\Sitemap\Model\Sitemap $model) protected function saveData($data) { // init model and set data - /** @var \Magento\Sitemap\Model\Sitemap $model */ + /** @var ModelSitemap $model */ $model = $this->sitemapFactory->create(); $this->clearSiteMap($model); $model->setData($data); @@ -164,7 +136,7 @@ protected function saveData($data) // clear previously saved data from session $this->_session->setFormData(false); return $model->getId(); - } catch (\Exception $e) { + } catch (Exception $e) { // display error message $this->messageManager->addErrorMessage($e->getMessage()); // save data in session diff --git a/app/code/Magento/Sitemap/Helper/Data.php b/app/code/Magento/Sitemap/Helper/Data.php index 118aeff28a14f..fd8f4bbc25a4f 100644 --- a/app/code/Magento/Sitemap/Helper/Data.php +++ b/app/code/Magento/Sitemap/Helper/Data.php @@ -5,6 +5,7 @@ */ namespace Magento\Sitemap\Helper; +use Magento\Framework\App\Helper\AbstractHelper; use Magento\Sitemap\Model\ItemProvider\CategoryConfigReader; use Magento\Sitemap\Model\ItemProvider\CmsPageConfigReader; use Magento\Sitemap\Model\ItemProvider\ProductConfigReader; @@ -14,7 +15,7 @@ /** * @deprecated 100.3.0 */ -class Data extends \Magento\Framework\App\Helper\AbstractHelper +class Data extends AbstractHelper { /** * Config path to sitemap valid paths diff --git a/app/code/Magento/Sitemap/Model/Config/Backend/Priority.php b/app/code/Magento/Sitemap/Model/Config/Backend/Priority.php index 36f6d69c8219b..27d6bd365e210 100644 --- a/app/code/Magento/Sitemap/Model/Config/Backend/Priority.php +++ b/app/code/Magento/Sitemap/Model/Config/Backend/Priority.php @@ -5,19 +5,22 @@ */ namespace Magento\Sitemap\Model\Config\Backend; -class Priority extends \Magento\Framework\App\Config\Value +use Exception; +use Magento\Framework\App\Config\Value as ConfigValue; + +class Priority extends ConfigValue { /** * @return $this - * @throws \Exception + * @throws Exception */ public function beforeSave() { $value = $this->getValue(); if ($value < 0 || $value > 1) { - throw new \Exception(__('The priority must be between 0 and 1.')); + throw new Exception(__('The priority must be between 0 and 1.')); } elseif ($value == 0 && !($value === '0' || $value === '0.0')) { - throw new \Exception(__('The priority must be between 0 and 1.')); + throw new Exception(__('The priority must be between 0 and 1.')); } return $this; } diff --git a/app/code/Magento/Sitemap/Model/Config/Backend/Robots.php b/app/code/Magento/Sitemap/Model/Config/Backend/Robots.php index 9b9aa6fb05e5b..85dcbb4679ca4 100644 --- a/app/code/Magento/Sitemap/Model/Config/Backend/Robots.php +++ b/app/code/Magento/Sitemap/Model/Config/Backend/Robots.php @@ -32,11 +32,6 @@ class Robots extends Value implements IdentityInterface */ protected $_cacheTag = true; - /** - * @var StoreManagerInterface - */ - private $storeManager; - /** * @param Context $context * @param Registry $registry @@ -52,12 +47,11 @@ public function __construct( Registry $registry, ScopeConfigInterface $config, TypeListInterface $cacheTypeList, - StoreManagerInterface $storeManager, + private readonly StoreManagerInterface $storeManager, AbstractResource $resource = null, AbstractDb $resourceCollection = null, array $data = [] ) { - $this->storeManager = $storeManager; parent::__construct( $context, diff --git a/app/code/Magento/Sitemap/Model/Config/Source/Frequency.php b/app/code/Magento/Sitemap/Model/Config/Source/Frequency.php index 87ce87189229c..f2e7c5334e4e9 100644 --- a/app/code/Magento/Sitemap/Model/Config/Source/Frequency.php +++ b/app/code/Magento/Sitemap/Model/Config/Source/Frequency.php @@ -5,7 +5,9 @@ */ namespace Magento\Sitemap\Model\Config\Source; -class Frequency implements \Magento\Framework\Option\ArrayInterface +use Magento\Framework\Option\ArrayInterface; + +class Frequency implements ArrayInterface { /** * {@inheritdoc} diff --git a/app/code/Magento/Sitemap/Model/EmailNotification.php b/app/code/Magento/Sitemap/Model/EmailNotification.php index 27c042870a1d6..dda65636fcfd3 100644 --- a/app/code/Magento/Sitemap/Model/EmailNotification.php +++ b/app/code/Magento/Sitemap/Model/EmailNotification.php @@ -7,12 +7,14 @@ namespace Magento\Sitemap\Model; +use Exception; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\Translate\Inline\StateInterface; use Magento\Framework\Mail\Template\TransportBuilder; use Magento\Store\Model\ScopeInterface; use Magento\Backend\App\Area\FrontNameResolver; use Magento\Sitemap\Model\Observer as Observer; +use Magento\Store\Model\Store as ModelStore; use Psr\Log\LoggerInterface; /** @@ -20,45 +22,19 @@ */ class EmailNotification { - /** - * @var \Magento\Framework\Translate\Inline\StateInterface - */ - private $inlineTranslation; - - /** - * Core store config - * - * @var \Magento\Framework\App\Config\ScopeConfigInterface - */ - private $scopeConfig; - - /** - * @var \Magento\Framework\Mail\Template\TransportBuilder - */ - private $transportBuilder; - - /** - * @var \Psr\Log\LoggerInterface $logger - */ - private $logger; - /** * EmailNotification constructor. * @param StateInterface $inlineTranslation * @param TransportBuilder $transportBuilder - * @param ScopeConfigInterface $scopeConfig + * @param ScopeConfigInterface $scopeConfig Core store config * @param LoggerInterface $logger */ public function __construct( - StateInterface $inlineTranslation, - TransportBuilder $transportBuilder, - ScopeConfigInterface $scopeConfig, - LoggerInterface $logger + private readonly StateInterface $inlineTranslation, + private readonly TransportBuilder $transportBuilder, + private readonly ScopeConfigInterface $scopeConfig, + private readonly LoggerInterface $logger ) { - $this->inlineTranslation = $inlineTranslation; - $this->scopeConfig = $scopeConfig; - $this->transportBuilder = $transportBuilder; - $this->logger = $logger; } /** @@ -78,7 +54,7 @@ public function sendErrors($errors) )->setTemplateOptions( [ 'area' => FrontNameResolver::AREA_CODE, - 'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID, + 'store' => ModelStore::DEFAULT_STORE_ID, ] )->setTemplateVars( ['warnings' => join("\n", $errors)] @@ -96,7 +72,7 @@ public function sendErrors($errors) $transport = $this->transportBuilder->getTransport(); $transport->sendMessage(); - } catch (\Exception $e) { + } catch (Exception $e) { $this->logger->error('Sitemap sendErrors: '.$e->getMessage()); } finally { $this->inlineTranslation->resume(); diff --git a/app/code/Magento/Sitemap/Model/ItemProvider/Category.php b/app/code/Magento/Sitemap/Model/ItemProvider/Category.php index 2c41915c72e98..1564ff2e6c4d5 100644 --- a/app/code/Magento/Sitemap/Model/ItemProvider/Category.php +++ b/app/code/Magento/Sitemap/Model/ItemProvider/Category.php @@ -11,42 +11,18 @@ class Category implements ItemProviderInterface { - /** - * Category factory - * - * @var CategoryFactory - */ - private $categoryFactory; - - /** - * Sitemap item factory - * - * @var SitemapItemInterfaceFactory - */ - private $itemFactory; - - /** - * Config reader - * - * @var ConfigReaderInterface - */ - private $configReader; - /** * CategorySitemapItemResolver constructor. * - * @param ConfigReaderInterface $configReader - * @param CategoryFactory $categoryFactory - * @param SitemapItemInterfaceFactory $itemFactory + * @param ConfigReaderInterface $configReader Config reader + * @param CategoryFactory $categoryFactory Category factory + * @param SitemapItemInterfaceFactory $itemFactory Sitemap item factory */ public function __construct( - ConfigReaderInterface $configReader, - CategoryFactory $categoryFactory, - SitemapItemInterfaceFactory $itemFactory + private readonly ConfigReaderInterface $configReader, + private readonly CategoryFactory $categoryFactory, + private readonly SitemapItemInterfaceFactory $itemFactory ) { - $this->categoryFactory = $categoryFactory; - $this->itemFactory = $itemFactory; - $this->configReader = $configReader; } /** diff --git a/app/code/Magento/Sitemap/Model/ItemProvider/CategoryConfigReader.php b/app/code/Magento/Sitemap/Model/ItemProvider/CategoryConfigReader.php index 2dee63eff2600..24f45d812476a 100644 --- a/app/code/Magento/Sitemap/Model/ItemProvider/CategoryConfigReader.php +++ b/app/code/Magento/Sitemap/Model/ItemProvider/CategoryConfigReader.php @@ -18,21 +18,14 @@ class CategoryConfigReader implements ConfigReaderInterface const XML_PATH_PRIORITY = 'sitemap/category/priority'; /**#@-*/ - /** - * Scope config - * - * @var ScopeConfigInterface - */ - private $scopeConfig; - /** * CategoryItemResolverConfigReader constructor. * - * @param ScopeConfigInterface $scopeConfig + * @param ScopeConfigInterface $scopeConfig Scope config */ - public function __construct(ScopeConfigInterface $scopeConfig) - { - $this->scopeConfig = $scopeConfig; + public function __construct( + private readonly ScopeConfigInterface $scopeConfig + ) { } /** diff --git a/app/code/Magento/Sitemap/Model/ItemProvider/CmsPage.php b/app/code/Magento/Sitemap/Model/ItemProvider/CmsPage.php index bc9e6eef7aa36..ab83c01e1e804 100644 --- a/app/code/Magento/Sitemap/Model/ItemProvider/CmsPage.php +++ b/app/code/Magento/Sitemap/Model/ItemProvider/CmsPage.php @@ -11,42 +11,18 @@ class CmsPage implements ItemProviderInterface { - /** - * Cms page factory - * - * @var PageFactory - */ - private $cmsPageFactory; - - /** - * Sitemap item factory - * - * @var SitemapItemInterfaceFactory - */ - private $itemFactory; - - /** - * Config reader - * - * @var ConfigReaderInterface - */ - private $configReader; - /** * CmsPage constructor. * - * @param ConfigReaderInterface $configReader - * @param PageFactory $cmsPageFactory + * @param ConfigReaderInterface $configReader Config reader + * @param PageFactory $cmsPageFactory Cms page factory * @param SitemapItemInterfaceFactory $itemFactory */ public function __construct( - ConfigReaderInterface $configReader, - PageFactory $cmsPageFactory, - SitemapItemInterfaceFactory $itemFactory + private readonly ConfigReaderInterface $configReader, + private readonly PageFactory $cmsPageFactory, + private readonly SitemapItemInterfaceFactory $itemFactory ) { - $this->cmsPageFactory = $cmsPageFactory; - $this->itemFactory = $itemFactory; - $this->configReader = $configReader; } /** diff --git a/app/code/Magento/Sitemap/Model/ItemProvider/CmsPageConfigReader.php b/app/code/Magento/Sitemap/Model/ItemProvider/CmsPageConfigReader.php index e173dc79e343d..8c3392f626d99 100644 --- a/app/code/Magento/Sitemap/Model/ItemProvider/CmsPageConfigReader.php +++ b/app/code/Magento/Sitemap/Model/ItemProvider/CmsPageConfigReader.php @@ -18,21 +18,14 @@ class CmsPageConfigReader implements ConfigReaderInterface const XML_PATH_PRIORITY = 'sitemap/page/priority'; /**#@-*/ - /** - * Scope config - * - * @var ScopeConfigInterface - */ - private $scopeConfig; - /** * CategoryItemResolverConfigReader constructor. * - * @param ScopeConfigInterface $scopeConfig + * @param ScopeConfigInterface $scopeConfig Scope config */ - public function __construct(ScopeConfigInterface $scopeConfig) - { - $this->scopeConfig = $scopeConfig; + public function __construct( + private readonly ScopeConfigInterface $scopeConfig + ) { } /** diff --git a/app/code/Magento/Sitemap/Model/ItemProvider/Composite.php b/app/code/Magento/Sitemap/Model/ItemProvider/Composite.php index 60137fac6e013..24e8d2af5a211 100644 --- a/app/code/Magento/Sitemap/Model/ItemProvider/Composite.php +++ b/app/code/Magento/Sitemap/Model/ItemProvider/Composite.php @@ -8,21 +8,14 @@ class Composite implements ItemProviderInterface { - /** - * Item resolvers - * - * @var ItemProviderInterface[] - */ - private $itemProviders; - /** * Composite constructor. * - * @param ItemProviderInterface[] $itemProviders + * @param ItemProviderInterface[] $itemProviders Item resolvers */ - public function __construct($itemProviders = []) - { - $this->itemProviders = $itemProviders; + public function __construct( + private $itemProviders = [] + ) { } /** diff --git a/app/code/Magento/Sitemap/Model/ItemProvider/Product.php b/app/code/Magento/Sitemap/Model/ItemProvider/Product.php index aecba66580794..1d94cdaefd116 100644 --- a/app/code/Magento/Sitemap/Model/ItemProvider/Product.php +++ b/app/code/Magento/Sitemap/Model/ItemProvider/Product.php @@ -11,42 +11,18 @@ class Product implements ItemProviderInterface { - /** - * Product factory - * - * @var ProductFactory - */ - private $productFactory; - - /** - * Sitemap item factory - * - * @var SitemapItemInterfaceFactory - */ - private $itemFactory; - - /** - * Config reader - * - * @var ConfigReaderInterface - */ - private $configReader; - /** * ProductSitemapItemResolver constructor. * - * @param ConfigReaderInterface $configReader + * @param ConfigReaderInterface $configReader Config reader * @param ProductFactory $productFactory * @param SitemapItemInterfaceFactory $itemFactory */ public function __construct( - ConfigReaderInterface $configReader, - ProductFactory $productFactory, - SitemapItemInterfaceFactory $itemFactory + private readonly ConfigReaderInterface $configReader, + private readonly ProductFactory $productFactory, + private readonly SitemapItemInterfaceFactory $itemFactory ) { - $this->productFactory = $productFactory; - $this->itemFactory = $itemFactory; - $this->configReader = $configReader; } /** diff --git a/app/code/Magento/Sitemap/Model/ItemProvider/ProductConfigReader.php b/app/code/Magento/Sitemap/Model/ItemProvider/ProductConfigReader.php index c1a01d2ed60c4..03e682f3f3d59 100644 --- a/app/code/Magento/Sitemap/Model/ItemProvider/ProductConfigReader.php +++ b/app/code/Magento/Sitemap/Model/ItemProvider/ProductConfigReader.php @@ -18,21 +18,14 @@ class ProductConfigReader implements ConfigReaderInterface const XML_PATH_PRIORITY = 'sitemap/product/priority'; /**#@-*/ - /** - * Scope config - * - * @var ScopeConfigInterface - */ - private $scopeConfig; - /** * CategoryItemResolverConfigReader constructor. * - * @param ScopeConfigInterface $scopeConfig + * @param ScopeConfigInterface $scopeConfig Scope config */ - public function __construct(ScopeConfigInterface $scopeConfig) - { - $this->scopeConfig = $scopeConfig; + public function __construct( + private readonly ScopeConfigInterface $scopeConfig + ) { } /** diff --git a/app/code/Magento/Sitemap/Model/ItemProvider/StoreUrl.php b/app/code/Magento/Sitemap/Model/ItemProvider/StoreUrl.php index 11a2d585d8da6..377cd917fd85a 100644 --- a/app/code/Magento/Sitemap/Model/ItemProvider/StoreUrl.php +++ b/app/code/Magento/Sitemap/Model/ItemProvider/StoreUrl.php @@ -13,32 +13,16 @@ */ class StoreUrl implements ItemProviderInterface { - /** - * Sitemap item factory - * - * @var SitemapItemInterfaceFactory - */ - private $itemFactory; - - /** - * Config reader - * - * @var ConfigReaderInterface - */ - private $configReader; - /** * StoreUrlSitemapItemResolver constructor. * - * @param ConfigReaderInterface $configReader - * @param SitemapItemInterfaceFactory $itemFactory + * @param ConfigReaderInterface $configReader Config reader + * @param SitemapItemInterfaceFactory $itemFactory Sitemap item factory */ public function __construct( - ConfigReaderInterface $configReader, - SitemapItemInterfaceFactory $itemFactory + private readonly ConfigReaderInterface $configReader, + private readonly SitemapItemInterfaceFactory $itemFactory ) { - $this->itemFactory = $itemFactory; - $this->configReader = $configReader; } /** diff --git a/app/code/Magento/Sitemap/Model/ItemProvider/StoreUrlConfigReader.php b/app/code/Magento/Sitemap/Model/ItemProvider/StoreUrlConfigReader.php index b18dd73fb2836..6d2bb87a70a79 100644 --- a/app/code/Magento/Sitemap/Model/ItemProvider/StoreUrlConfigReader.php +++ b/app/code/Magento/Sitemap/Model/ItemProvider/StoreUrlConfigReader.php @@ -21,21 +21,14 @@ class StoreUrlConfigReader implements ConfigReaderInterface const XML_PATH_PRIORITY = 'sitemap/store/priority'; /**#@-*/ - /** - * Scope config - * - * @var ScopeConfigInterface - */ - private $scopeConfig; - /** * CategoryItemResolverConfigReader constructor. * - * @param ScopeConfigInterface $scopeConfig + * @param ScopeConfigInterface $scopeConfig Scope config */ - public function __construct(ScopeConfigInterface $scopeConfig) - { - $this->scopeConfig = $scopeConfig; + public function __construct( + private readonly ScopeConfigInterface $scopeConfig + ) { } /** diff --git a/app/code/Magento/Sitemap/Model/Observer.php b/app/code/Magento/Sitemap/Model/Observer.php index 4333c71c7497f..2be477ce970ea 100644 --- a/app/code/Magento/Sitemap/Model/Observer.php +++ b/app/code/Magento/Sitemap/Model/Observer.php @@ -7,10 +7,13 @@ namespace Magento\Sitemap\Model; +use Exception; use Magento\Framework\App\Area; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Sitemap\Model\EmailNotification as SitemapEmail; +use Magento\Sitemap\Model\ResourceModel\Sitemap\Collection as SitemapCollection; use Magento\Sitemap\Model\ResourceModel\Sitemap\CollectionFactory; +use Magento\Sitemap\Model\Sitemap as ModelSitemap; use Magento\Store\Model\App\Emulation; use Magento\Store\Model\ScopeInterface; @@ -48,52 +51,26 @@ class Observer */ const XML_PATH_ERROR_RECIPIENT = 'sitemap/generate/error_email'; - /** - * Core store config - * - * @var \Magento\Framework\App\Config\ScopeConfigInterface - */ - private $scopeConfig; - - /** - * @var \Magento\Sitemap\Model\ResourceModel\Sitemap\CollectionFactory - */ - private $collectionFactory; - - /** - * @var $emailNotification - */ - private $emailNotification; - - /** - * @var Emulation - */ - private $appEmulation; - /** * Observer constructor. - * @param ScopeConfigInterface $scopeConfig + * @param ScopeConfigInterface $scopeConfig Core store config * @param CollectionFactory $collectionFactory * @param EmailNotification $emailNotification * @param Emulation $appEmulation */ public function __construct( - ScopeConfigInterface $scopeConfig, - CollectionFactory $collectionFactory, - SitemapEmail $emailNotification, - Emulation $appEmulation + private readonly ScopeConfigInterface $scopeConfig, + private readonly CollectionFactory $collectionFactory, + private readonly SitemapEmail $emailNotification, + private readonly Emulation $appEmulation ) { - $this->scopeConfig = $scopeConfig; - $this->collectionFactory = $collectionFactory; - $this->emailNotification = $emailNotification; - $this->appEmulation = $appEmulation; } /** * Generate sitemaps * * @return void - * @throws \Exception + * @throws Exception * @SuppressWarnings(PHPMD.UnusedLocalVariable) */ public function scheduledGenerateSitemaps() @@ -113,9 +90,9 @@ public function scheduledGenerateSitemaps() } $collection = $this->collectionFactory->create(); - /* @var $collection \Magento\Sitemap\Model\ResourceModel\Sitemap\Collection */ + /* @var SitemapCollection $collection */ foreach ($collection as $sitemap) { - /* @var $sitemap \Magento\Sitemap\Model\Sitemap */ + /* @var ModelSitemap $sitemap */ try { $this->appEmulation->startEnvironmentEmulation( $sitemap->getStoreId(), @@ -123,7 +100,7 @@ public function scheduledGenerateSitemaps() true ); $sitemap->generateXml(); - } catch (\Exception $e) { + } catch (Exception $e) { $errors[] = $e->getMessage(); } finally { $this->appEmulation->stopEnvironmentEmulation(); diff --git a/app/code/Magento/Sitemap/Model/ResourceModel/Catalog/Category.php b/app/code/Magento/Sitemap/Model/ResourceModel/Catalog/Category.php index 6a8190c2b7653..4e87ef5025853 100644 --- a/app/code/Magento/Sitemap/Model/ResourceModel/Catalog/Category.php +++ b/app/code/Magento/Sitemap/Model/ResourceModel/Catalog/Category.php @@ -5,7 +5,16 @@ */ namespace Magento\Sitemap\Model\ResourceModel\Catalog; +use Magento\Catalog\Api\Data\CategoryInterface; +use Magento\Catalog\Model\ResourceModel\Category as ResourceCategory; use Magento\CatalogUrlRewrite\Model\CategoryUrlRewriteGenerator; +use Magento\Framework\DataObject; +use Magento\Framework\DB\Select; +use Magento\Framework\EntityManager\MetadataPool; +use Magento\Framework\Model\ResourceModel\Db\AbstractDb; +use Magento\Framework\Model\ResourceModel\Db\Context as DbContext; +use Magento\Store\Model\Store as ModelStore; +use Magento\Store\Model\StoreManagerInterface; /** * Sitemap resource catalog collection model @@ -13,12 +22,12 @@ * @api * @since 100.0.2 */ -class Category extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb +class Category extends AbstractDb { /** * Collection Zend Db select * - * @var \Magento\Framework\DB\Select + * @var Select */ protected $_select; @@ -30,39 +39,32 @@ class Category extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb protected $_attributesCache = []; /** - * @var \Magento\Store\Model\StoreManagerInterface + * @var StoreManagerInterface */ protected $_storeManager; /** - * @var \Magento\Catalog\Model\ResourceModel\Category + * @var ResourceCategory */ protected $_categoryResource; /** - * @var \Magento\Framework\EntityManager\MetadataPool - * @since 100.1.0 - */ - protected $metadataPool; - - /** - * @param \Magento\Framework\Model\ResourceModel\Db\Context $context - * @param \Magento\Store\Model\StoreManagerInterface $storeManager - * @param \Magento\Catalog\Model\ResourceModel\Category $categoryResource - * @param \Magento\Framework\EntityManager\MetadataPool $metadataPool + * @param DbContext $context + * @param StoreManagerInterface $storeManager + * @param ResourceCategory $categoryResource + * @param MetadataPool $metadataPool * @param string $connectionName */ public function __construct( - \Magento\Framework\Model\ResourceModel\Db\Context $context, - \Magento\Store\Model\StoreManagerInterface $storeManager, - \Magento\Catalog\Model\ResourceModel\Category $categoryResource, - \Magento\Framework\EntityManager\MetadataPool $metadataPool, + DbContext $context, + StoreManagerInterface $storeManager, + ResourceCategory $categoryResource, + protected readonly MetadataPool $metadataPool, $connectionName = null ) { $this->_storeManager = $storeManager; $this->_categoryResource = $categoryResource; parent::__construct($context, $connectionName); - $this->metadataPool = $metadataPool; } /** @@ -76,14 +78,14 @@ protected function _construct() /** * Get category collection array * - * @param null|string|bool|int|\Magento\Store\Model\Store $storeId + * @param null|string|bool|int|ModelStore $storeId * @return array|bool */ public function getCollection($storeId) { $categories = []; - /* @var $store \Magento\Store\Model\Store */ + /* @var ModelStore $store */ $store = $this->_storeManager->getStore($storeId); if (!$store) { @@ -133,11 +135,11 @@ public function getCollection($storeId) * Prepare category * * @param array $categoryRow - * @return \Magento\Framework\DataObject + * @return DataObject */ protected function _prepareCategory(array $categoryRow) { - $category = new \Magento\Framework\DataObject(); + $category = new DataObject(); $category->setId($categoryRow[$this->getIdFieldName()]); $categoryUrl = !empty($categoryRow['url']) ? $categoryRow['url'] : 'catalog/category/view/id/' . $category->getId(); @@ -153,14 +155,14 @@ protected function _prepareCategory(array $categoryRow) * @param string $attributeCode * @param mixed $value * @param string $type - * @return \Magento\Framework\DB\Select|bool + * @return Select|bool */ protected function _addFilter($storeId, $attributeCode, $value, $type = '=') { - $meta = $this->metadataPool->getMetadata(\Magento\Catalog\Api\Data\CategoryInterface::class); + $meta = $this->metadataPool->getMetadata(CategoryInterface::class); $linkField = $meta->getLinkField(); - if (!$this->_select instanceof \Magento\Framework\DB\Select) { + if (!$this->_select instanceof Select) { return false; } diff --git a/app/code/Magento/Sitemap/Model/ResourceModel/Catalog/Product.php b/app/code/Magento/Sitemap/Model/ResourceModel/Catalog/Product.php index 41347263839ed..0fc0a09bd4b07 100644 --- a/app/code/Magento/Sitemap/Model/ResourceModel/Catalog/Product.php +++ b/app/code/Magento/Sitemap/Model/ResourceModel/Catalog/Product.php @@ -5,10 +5,30 @@ */ namespace Magento\Sitemap\Model\ResourceModel\Catalog; +use Magento\Catalog\Helper\Image as CatalogImageHelper; +use Magento\Catalog\Model\Product as ModelProduct; +use Magento\Catalog\Model\Product\Attribute\Source\Status as SourceStatus; +use Magento\Catalog\Model\Product\Gallery\ReadHandler as GalleryReadHandler; use Magento\Catalog\Model\Product\Image\UrlBuilder; +use Magento\Catalog\Model\Product\Media\Config as ProductMediaConfig; +use Magento\Catalog\Model\Product\Visibility as ProductVisibility; +use Magento\Catalog\Model\ResourceModel\Product as ResourceProduct; +use Magento\Catalog\Model\ResourceModel\Product\Gallery as ResourceProductGallery; use Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator; +use Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface; +use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\App\ObjectManager; +use Magento\Framework\DataObject; +use Magento\Framework\DB\Select; +use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Exception\NoSuchEntityException; +use Magento\Framework\Model\ResourceModel\Db\AbstractDb; +use Magento\Framework\Model\ResourceModel\Db\Context as DbContext; +use Magento\Sitemap\Helper\Data as SitemapHelper; +use Magento\Sitemap\Model\Source\Product\Image\IncludeImage; use Magento\Store\Model\Store; +use Magento\Store\Model\StoreManagerInterface; +use Zend_Db_Statement_Exception; /** * Sitemap resource product collection model @@ -17,14 +37,14 @@ * @api * @since 100.0.2 */ -class Product extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb +class Product extends AbstractDb { const NOT_SELECTED_IMAGE = 'no_selection'; /** * Collection Zend Db select * - * @var \Magento\Framework\DB\Select + * @var Select */ protected $_select; @@ -35,47 +55,35 @@ class Product extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb */ protected $_attributesCache = []; - /** - * @var \Magento\Catalog\Model\Product\Gallery\ReadHandler - * @since 100.1.0 - */ - protected $mediaGalleryReadHandler; - /** * Sitemap data * - * @var \Magento\Sitemap\Helper\Data + * @var SitemapHelper */ protected $_sitemapData = null; /** - * @var \Magento\Catalog\Model\ResourceModel\Product + * @var ResourceProduct */ protected $_productResource; /** - * @var \Magento\Store\Model\StoreManagerInterface + * @var StoreManagerInterface */ protected $_storeManager; /** - * @var \Magento\Catalog\Model\Product\Visibility + * @var ProductVisibility */ protected $_productVisibility; /** - * @var \Magento\Catalog\Model\Product\Attribute\Source\Status + * @var SourceStatus */ protected $_productStatus; /** - * @var \Magento\Catalog\Model\ResourceModel\Product\Gallery - * @since 100.1.0 - */ - protected $mediaGalleryResourceModel; - - /** - * @var \Magento\Catalog\Model\Product\Media\Config + * @var ProductMediaConfig * @deprecated 100.2.0 unused */ protected $_mediaConfig; @@ -88,45 +96,43 @@ class Product extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb /** * Product constructor. * - * @param \Magento\Framework\Model\ResourceModel\Db\Context $context - * @param \Magento\Sitemap\Helper\Data $sitemapData - * @param \Magento\Catalog\Model\ResourceModel\Product $productResource - * @param \Magento\Store\Model\StoreManagerInterface $storeManager - * @param \Magento\Catalog\Model\Product\Visibility $productVisibility - * @param \Magento\Catalog\Model\Product\Attribute\Source\Status $productStatus - * @param \Magento\Catalog\Model\ResourceModel\Product\Gallery $mediaGalleryResourceModel - * @param \Magento\Catalog\Model\Product\Gallery\ReadHandler $mediaGalleryReadHandler - * @param \Magento\Catalog\Model\Product\Media\Config $mediaConfig + * @param DbContext $context + * @param SitemapHelper $sitemapData + * @param ResourceProduct $productResource + * @param StoreManagerInterface $storeManager + * @param ProductVisibility $productVisibility + * @param SourceStatus $productStatus + * @param ResourceProductGallery $mediaGalleryResourceModel + * @param GalleryReadHandler $mediaGalleryReadHandler + * @param ProductMediaConfig $mediaConfig * @param string $connectionName - * @param \Magento\Catalog\Model\Product $productModel - * @param \Magento\Catalog\Helper\Image $catalogImageHelper - * @param \Magento\Framework\App\Config\ScopeConfigInterface|null $scopeConfig + * @param ModelProduct $productModel + * @param CatalogImageHelper $catalogImageHelper + * @param ScopeConfigInterface|null $scopeConfig * @param UrlBuilder $urlBuilder * @SuppressWarnings(PHPMD.ExcessiveParameterList) * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function __construct( - \Magento\Framework\Model\ResourceModel\Db\Context $context, - \Magento\Sitemap\Helper\Data $sitemapData, - \Magento\Catalog\Model\ResourceModel\Product $productResource, - \Magento\Store\Model\StoreManagerInterface $storeManager, - \Magento\Catalog\Model\Product\Visibility $productVisibility, - \Magento\Catalog\Model\Product\Attribute\Source\Status $productStatus, - \Magento\Catalog\Model\ResourceModel\Product\Gallery $mediaGalleryResourceModel, - \Magento\Catalog\Model\Product\Gallery\ReadHandler $mediaGalleryReadHandler, - \Magento\Catalog\Model\Product\Media\Config $mediaConfig, + DbContext $context, + SitemapHelper $sitemapData, + ResourceProduct $productResource, + StoreManagerInterface $storeManager, + ProductVisibility $productVisibility, + SourceStatus $productStatus, + protected readonly ResourceProductGallery $mediaGalleryResourceModel, + protected readonly GalleryReadHandler $mediaGalleryReadHandler, + ProductMediaConfig $mediaConfig, $connectionName = null, - \Magento\Catalog\Model\Product $productModel = null, - \Magento\Catalog\Helper\Image $catalogImageHelper = null, - \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig = null, + ModelProduct $productModel = null, + CatalogImageHelper $catalogImageHelper = null, + ScopeConfigInterface $scopeConfig = null, UrlBuilder $urlBuilder = null ) { $this->_productResource = $productResource; $this->_storeManager = $storeManager; $this->_productVisibility = $productVisibility; $this->_productStatus = $productStatus; - $this->mediaGalleryResourceModel = $mediaGalleryResourceModel; - $this->mediaGalleryReadHandler = $mediaGalleryReadHandler; $this->_mediaConfig = $mediaConfig; $this->_sitemapData = $sitemapData; $this->imageUrlBuilder = $urlBuilder ?? ObjectManager::getInstance()->get(UrlBuilder::class); @@ -152,12 +158,12 @@ protected function _construct() * @param mixed $value * @param string $type * - * @return \Magento\Framework\DB\Select|bool - * @throws \Magento\Framework\Exception\LocalizedException + * @return Select|bool + * @throws LocalizedException */ protected function _addFilter($storeId, $attributeCode, $value, $type = '=') { - if (!$this->_select instanceof \Magento\Framework\DB\Select) { + if (!$this->_select instanceof Select) { return false; } @@ -200,7 +206,7 @@ protected function _addFilter($storeId, $attributeCode, $value, $type = '=') * @param string $column Add attribute value to given column * * @return void - * @throws \Magento\Framework\Exception\LocalizedException + * @throws LocalizedException */ protected function _joinAttribute($storeId, $attributeCode, $column = null) { @@ -247,7 +253,7 @@ protected function _joinAttribute($storeId, $attributeCode, $column = null) * @param string $attributeCode * * @return array - * @throws \Magento\Framework\Exception\LocalizedException + * @throws LocalizedException */ protected function _getAttribute($attributeCode) { @@ -259,7 +265,7 @@ protected function _getAttribute($attributeCode) 'attribute_id' => $attribute->getId(), 'table' => $attribute->getBackend()->getTable(), 'is_global' => $attribute->getIsGlobal() == - \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL, + ScopedAttributeInterface::SCOPE_GLOBAL, 'backend_type' => $attribute->getBackendType(), ]; } @@ -272,15 +278,15 @@ protected function _getAttribute($attributeCode) * @param null|string|bool|int|Store $storeId * * @return array|bool - * @throws \Magento\Framework\Exception\LocalizedException - * @throws \Magento\Framework\Exception\NoSuchEntityException - * @throws \Zend_Db_Statement_Exception + * @throws LocalizedException + * @throws NoSuchEntityException + * @throws Zend_Db_Statement_Exception */ public function getCollection($storeId) { $products = []; - /* @var $store Store */ + /* @var Store $store */ $store = $this->_storeManager->getStore($storeId); if (!$store) { return false; @@ -311,11 +317,11 @@ public function getCollection($storeId) // Join product images required attributes $imageIncludePolicy = $this->_sitemapData->getProductImageIncludePolicy($store->getId()); - if (\Magento\Sitemap\Model\Source\Product\Image\IncludeImage::INCLUDE_NONE != $imageIncludePolicy) { + if (IncludeImage::INCLUDE_NONE != $imageIncludePolicy) { $this->_joinAttribute($store->getId(), 'name', 'name'); - if (\Magento\Sitemap\Model\Source\Product\Image\IncludeImage::INCLUDE_ALL == $imageIncludePolicy) { + if (IncludeImage::INCLUDE_ALL == $imageIncludePolicy) { $this->_joinAttribute($store->getId(), 'thumbnail', 'thumbnail'); - } elseif (\Magento\Sitemap\Model\Source\Product\Image\IncludeImage::INCLUDE_BASE == $imageIncludePolicy) { + } elseif (IncludeImage::INCLUDE_BASE == $imageIncludePolicy) { $this->_joinAttribute($store->getId(), 'image', 'image'); } } @@ -335,12 +341,12 @@ public function getCollection($storeId) * @param array $productRow * @param int $storeId * - * @return \Magento\Framework\DataObject - * @throws \Magento\Framework\Exception\LocalizedException + * @return DataObject + * @throws LocalizedException */ protected function _prepareProduct(array $productRow, $storeId) { - $product = new \Magento\Framework\DataObject(); + $product = new DataObject(); $product['id'] = $productRow[$this->getIdFieldName()]; if (empty($productRow['url'])) { @@ -355,27 +361,27 @@ protected function _prepareProduct(array $productRow, $storeId) /** * Load product images * - * @param \Magento\Framework\DataObject $product + * @param DataObject $product * @param int $storeId * @return void */ protected function _loadProductImages($product, $storeId) { $this->_storeManager->setCurrentStore($storeId); - /** @var $helper \Magento\Sitemap\Helper\Data */ + /** @var SitemapHelper $helper */ $helper = $this->_sitemapData; $imageIncludePolicy = $helper->getProductImageIncludePolicy($storeId); // Get product images $imagesCollection = []; - if (\Magento\Sitemap\Model\Source\Product\Image\IncludeImage::INCLUDE_ALL == $imageIncludePolicy) { + if (IncludeImage::INCLUDE_ALL == $imageIncludePolicy) { $imagesCollection = $this->_getAllProductImages($product, $storeId); - } elseif (\Magento\Sitemap\Model\Source\Product\Image\IncludeImage::INCLUDE_BASE == $imageIncludePolicy && + } elseif (IncludeImage::INCLUDE_BASE == $imageIncludePolicy && $product->getImage() && $product->getImage() != self::NOT_SELECTED_IMAGE ) { $imagesCollection = [ - new \Magento\Framework\DataObject( + new DataObject( ['url' => $this->getProductImageUrl($product->getImage())] ), ]; @@ -391,7 +397,7 @@ protected function _loadProductImages($product, $storeId) } $product->setImages( - new \Magento\Framework\DataObject( + new DataObject( ['collection' => $imagesCollection, 'title' => $product->getName(), 'thumbnail' => $thumbnail] ) ); @@ -401,7 +407,7 @@ protected function _loadProductImages($product, $storeId) /** * Get all product images * - * @param \Magento\Framework\DataObject $product + * @param DataObject $product * @param int $storeId * @return array */ @@ -416,7 +422,7 @@ protected function _getAllProductImages($product, $storeId) $imagesCollection = []; if ($gallery) { foreach ($gallery as $image) { - $imagesCollection[] = new \Magento\Framework\DataObject( + $imagesCollection[] = new DataObject( [ 'url' => $this->getProductImageUrl($image['file']), 'caption' => $image['label'] ? $image['label'] : $image['label_default'], @@ -431,7 +437,7 @@ protected function _getAllProductImages($product, $storeId) /** * Get media config * - * @return \Magento\Catalog\Model\Product\Media\Config + * @return ProductMediaConfig * @deprecated 100.2.0 No longer used, as we're getting full image URL from getProductImageUrl method * @see getProductImageUrl() */ @@ -443,11 +449,11 @@ protected function _getMediaConfig() /** * Allow to modify select statement with plugins * - * @param \Magento\Framework\DB\Select $select - * @return \Magento\Framework\DB\Select + * @param Select $select + * @return Select * @since 100.2.1 */ - public function prepareSelectStatement(\Magento\Framework\DB\Select $select) + public function prepareSelectStatement(Select $select) { return $select; } diff --git a/app/code/Magento/Sitemap/Model/ResourceModel/Cms/Page.php b/app/code/Magento/Sitemap/Model/ResourceModel/Cms/Page.php index 92cbcbd500e8a..f4b0ca0c60018 100644 --- a/app/code/Magento/Sitemap/Model/ResourceModel/Cms/Page.php +++ b/app/code/Magento/Sitemap/Model/ResourceModel/Cms/Page.php @@ -9,6 +9,7 @@ use Magento\Cms\Api\GetUtilityPageIdentifiersInterface; use Magento\Cms\Model\Page as CmsPage; use Magento\Framework\App\ObjectManager; +use Magento\Framework\DataObject; use Magento\Framework\DB\Select; use Magento\Framework\EntityManager\EntityManager; use Magento\Framework\EntityManager\MetadataPool; @@ -25,38 +26,19 @@ class Page extends AbstractDb { /** - * @var MetadataPool - * @since 100.1.0 - */ - protected $metadataPool; - - /** - * @var EntityManager - * @since 100.1.0 - */ - protected $entityManager; - - /** - * @var GetUtilityPageIdentifiersInterface - */ - private $getUtilityPageIdentifiers; - - /** - * @param Context $context - * @param MetadataPool $metadataPool - * @param EntityManager $entityManager - * @param string $connectionName + * @param Context $context + * @param MetadataPool $metadataPool + * @param EntityManager $entityManager + * @param string $connectionName * @param GetUtilityPageIdentifiersInterface $getUtilityPageIdentifiers */ public function __construct( Context $context, - MetadataPool $metadataPool, - EntityManager $entityManager, + protected readonly MetadataPool $metadataPool, + protected readonly EntityManager $entityManager, $connectionName = null, - GetUtilityPageIdentifiersInterface $getUtilityPageIdentifiers = null + private ?GetUtilityPageIdentifiersInterface $getUtilityPageIdentifiers = null ) { - $this->metadataPool = $metadataPool; - $this->entityManager = $entityManager; $this->getUtilityPageIdentifiers = $getUtilityPageIdentifiers ?: ObjectManager::getInstance()->get(GetUtilityPageIdentifiersInterface::class); parent::__construct($context, $connectionName); @@ -123,11 +105,11 @@ public function getCollection($storeId) * Prepare page object * * @param array $data - * @return \Magento\Framework\DataObject + * @return DataObject */ protected function _prepareObject(array $data) { - $object = new \Magento\Framework\DataObject(); + $object = new DataObject(); $object->setId($data[$this->getIdFieldName()]); $object->setUrl($data['url']); $object->setUpdatedAt($data['updated_at']); diff --git a/app/code/Magento/Sitemap/Model/ResourceModel/Sitemap.php b/app/code/Magento/Sitemap/Model/ResourceModel/Sitemap.php index 2aef790b96c81..c178a9117bd95 100644 --- a/app/code/Magento/Sitemap/Model/ResourceModel/Sitemap.php +++ b/app/code/Magento/Sitemap/Model/ResourceModel/Sitemap.php @@ -5,13 +5,15 @@ */ namespace Magento\Sitemap\Model\ResourceModel; +use Magento\Framework\Model\ResourceModel\Db\AbstractDb; + /** * Sitemap resource model * * @api * @since 100.0.2 */ -class Sitemap extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb +class Sitemap extends AbstractDb { /** * Init resource model diff --git a/app/code/Magento/Sitemap/Model/ResourceModel/Sitemap/Collection.php b/app/code/Magento/Sitemap/Model/ResourceModel/Sitemap/Collection.php index 9b2128ffe3328..a5e6b2a8f6f38 100644 --- a/app/code/Magento/Sitemap/Model/ResourceModel/Sitemap/Collection.php +++ b/app/code/Magento/Sitemap/Model/ResourceModel/Sitemap/Collection.php @@ -5,6 +5,10 @@ */ namespace Magento\Sitemap\Model\ResourceModel\Sitemap; +use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection; +use Magento\Sitemap\Model\ResourceModel\Sitemap as ResourceSitemap; +use Magento\Sitemap\Model\Sitemap as ModelSitemap; + /** * Sitemap resource model collection * @@ -12,7 +16,7 @@ * @api * @since 100.0.2 */ -class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection +class Collection extends AbstractCollection { /** * Init collection @@ -21,7 +25,7 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\Ab */ public function _construct() { - $this->_init(\Magento\Sitemap\Model\Sitemap::class, \Magento\Sitemap\Model\ResourceModel\Sitemap::class); + $this->_init(ModelSitemap::class, ResourceSitemap::class); } /** diff --git a/app/code/Magento/Sitemap/Model/Sitemap.php b/app/code/Magento/Sitemap/Model/Sitemap.php index b88ff704b5807..4a391ab12b80d 100644 --- a/app/code/Magento/Sitemap/Model/Sitemap.php +++ b/app/code/Magento/Sitemap/Model/Sitemap.php @@ -6,30 +6,49 @@ namespace Magento\Sitemap\Model; +use DateTime; +use DOMDocument; use Magento\Config\Model\Config\Reader\Source\Deployed\DocumentRoot; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\App\ObjectManager; +use Magento\Framework\App\RequestInterface; +use Magento\Framework\Data\Collection\AbstractDb; use Magento\Framework\DataObject; +use Magento\Framework\DataObject\IdentityInterface; +use Magento\Framework\Escaper; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Filesystem; +use Magento\Framework\Filesystem\File\WriteInterface as FileWriteInterface; +use Magento\Framework\Model\AbstractModel; +use Magento\Framework\Model\Context as ModelContext; +use Magento\Framework\Model\ResourceModel\AbstractResource; +use Magento\Framework\Registry; +use Magento\Framework\Stdlib\DateTime as FrameworkDateTime; +use Magento\Framework\Stdlib\DateTime\DateTime as ModelDateTime; use Magento\Framework\UrlInterface; use Magento\Robots\Model\Config\Value; +use Magento\Sitemap\Helper\Data as SitemapHelper; use Magento\Sitemap\Model\ItemProvider\ItemProviderInterface; +use Magento\Sitemap\Model\ResourceModel\Catalog\CategoryFactory; +use Magento\Sitemap\Model\ResourceModel\Catalog\ProductFactory; +use Magento\Sitemap\Model\ResourceModel\Cms\PageFactory; use Magento\Sitemap\Model\ResourceModel\Sitemap as SitemapResource; +use Magento\Store\Model\Store as ModelStore; +use Magento\Store\Model\StoreManagerInterface; /** * Sitemap model. * * @method string getSitemapType() - * @method \Magento\Sitemap\Model\Sitemap setSitemapType(string $value) + * @method Sitemap setSitemapType(string $value) * @method string getSitemapFilename() - * @method \Magento\Sitemap\Model\Sitemap setSitemapFilename(string $value) + * @method Sitemap setSitemapFilename(string $value) * @method string getSitemapPath() - * @method \Magento\Sitemap\Model\Sitemap setSitemapPath(string $value) + * @method Sitemap setSitemapPath(string $value) * @method string getSitemapTime() - * @method \Magento\Sitemap\Model\Sitemap setSitemapTime(string $value) + * @method Sitemap setSitemapTime(string $value) * @method int getStoreId() - * @method \Magento\Sitemap\Model\Sitemap setStoreId(int $value) + * @method Sitemap setStoreId(int $value) * @SuppressWarnings(PHPMD.TooManyFields) * @SuppressWarnings(PHPMD.CouplingBetweenObjects) * @SuppressWarnings(PHPMD.UnusedPrivateField) @@ -37,7 +56,7 @@ * @api * @since 100.0.2 */ -class Sitemap extends \Magento\Framework\Model\AbstractModel implements \Magento\Framework\DataObject\IdentityInterface +class Sitemap extends AbstractModel implements IdentityInterface { public const OPEN_TAG_KEY = 'start'; @@ -114,50 +133,45 @@ class Sitemap extends \Magento\Framework\Model\AbstractModel implements \Magento protected $_stream; /** - * @var \Magento\Sitemap\Helper\Data + * @var SitemapHelper */ protected $_sitemapData; /** - * @var \Magento\Framework\Escaper + * @var Escaper */ protected $_escaper; /** - * @var \Magento\Sitemap\Model\ResourceModel\Catalog\CategoryFactory + * @var CategoryFactory */ protected $_categoryFactory; /** - * @var \Magento\Sitemap\Model\ResourceModel\Catalog\ProductFactory + * @var ProductFactory */ protected $_productFactory; /** - * @var \Magento\Sitemap\Model\ResourceModel\Cms\PageFactory + * @var PageFactory */ protected $_cmsFactory; /** - * @var \Magento\Framework\Stdlib\DateTime\DateTime + * @var ModelDateTime */ protected $_dateModel; /** - * @var \Magento\Store\Model\StoreManagerInterface + * @var StoreManagerInterface */ protected $_storeManager; /** - * @var \Magento\Framework\App\RequestInterface + * @var RequestInterface */ protected $_request; - /** - * @var \Magento\Framework\Stdlib\DateTime - */ - protected $dateTime; - /** * @inheritdoc * @@ -167,25 +181,6 @@ class Sitemap extends \Magento\Framework\Model\AbstractModel implements \Magento */ protected $_cacheTag = [Value::CACHE_TAG]; - /** - * Item resolver - * - * @var ItemProviderInterface - */ - private $itemProvider; - - /** - * Sitemap config reader - * - * @var SitemapConfigReaderInterface - */ - private $configReader; - - /** - * @var \Magento\Sitemap\Model\SitemapItemInterfaceFactory - */ - private $sitemapItemFactory; - /** * Last mode min timestamp value * @@ -193,11 +188,6 @@ class Sitemap extends \Magento\Framework\Model\AbstractModel implements \Magento */ private $lastModMinTsVal; - /** - * @var Filesystem - */ - private $filesystem; - /** * @var DocumentRoot */ @@ -206,51 +196,50 @@ class Sitemap extends \Magento\Framework\Model\AbstractModel implements \Magento /** * Initialize dependencies. * - * @param \Magento\Framework\Model\Context $context - * @param \Magento\Framework\Registry $registry - * @param \Magento\Framework\Escaper $escaper - * @param \Magento\Sitemap\Helper\Data $sitemapData - * @param \Magento\Framework\Filesystem $filesystem - * @param ResourceModel\Catalog\CategoryFactory $categoryFactory - * @param ResourceModel\Catalog\ProductFactory $productFactory - * @param ResourceModel\Cms\PageFactory $cmsFactory - * @param \Magento\Framework\Stdlib\DateTime\DateTime $modelDate - * @param \Magento\Store\Model\StoreManagerInterface $storeManager - * @param \Magento\Framework\App\RequestInterface $request - * @param \Magento\Framework\Stdlib\DateTime $dateTime - * @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource - * @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection + * @param ModelContext $context + * @param Registry $registry + * @param Escaper $escaper + * @param SitemapHelper $sitemapData + * @param Filesystem $filesystem + * @param CategoryFactory $categoryFactory + * @param ProductFactory $productFactory + * @param PageFactory $cmsFactory + * @param ModelDateTime $modelDate + * @param StoreManagerInterface $storeManager + * @param RequestInterface $request + * @param FrameworkDateTime $dateTime + * @param AbstractResource|null $resource + * @param AbstractDb|null $resourceCollection * @param array $data * @param DocumentRoot|null $documentRoot - * @param ItemProviderInterface|null $itemProvider - * @param SitemapConfigReaderInterface|null $configReader - * @param \Magento\Sitemap\Model\SitemapItemInterfaceFactory|null $sitemapItemFactory + * @param ItemProviderInterface|null $itemProvider Item resolver + * @param SitemapConfigReaderInterface|null $configReader Sitemap config reader + * @param SitemapItemInterfaceFactory|null $sitemapItemFactory * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( - \Magento\Framework\Model\Context $context, - \Magento\Framework\Registry $registry, - \Magento\Framework\Escaper $escaper, - \Magento\Sitemap\Helper\Data $sitemapData, - \Magento\Framework\Filesystem $filesystem, - \Magento\Sitemap\Model\ResourceModel\Catalog\CategoryFactory $categoryFactory, - \Magento\Sitemap\Model\ResourceModel\Catalog\ProductFactory $productFactory, - \Magento\Sitemap\Model\ResourceModel\Cms\PageFactory $cmsFactory, - \Magento\Framework\Stdlib\DateTime\DateTime $modelDate, - \Magento\Store\Model\StoreManagerInterface $storeManager, - \Magento\Framework\App\RequestInterface $request, - \Magento\Framework\Stdlib\DateTime $dateTime, - \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, - \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, + ModelContext $context, + Registry $registry, + Escaper $escaper, + SitemapHelper $sitemapData, + private readonly Filesystem $filesystem, + CategoryFactory $categoryFactory, + ProductFactory $productFactory, + PageFactory $cmsFactory, + ModelDateTime $modelDate, + StoreManagerInterface $storeManager, + RequestInterface $request, + protected readonly FrameworkDateTime $dateTime, + AbstractResource $resource = null, + AbstractDb $resourceCollection = null, array $data = [], - \Magento\Config\Model\Config\Reader\Source\Deployed\DocumentRoot $documentRoot = null, - ItemProviderInterface $itemProvider = null, - SitemapConfigReaderInterface $configReader = null, - \Magento\Sitemap\Model\SitemapItemInterfaceFactory $sitemapItemFactory = null + DocumentRoot $documentRoot = null, + private ?ItemProviderInterface $itemProvider = null, + private ?SitemapConfigReaderInterface $configReader = null, + private ?SitemapItemInterfaceFactory $sitemapItemFactory = null ) { $this->_escaper = $escaper; $this->_sitemapData = $sitemapData; - $this->filesystem = $filesystem; $this->_directory = $filesystem->getDirectoryWrite(DirectoryList::PUB); $this->_categoryFactory = $categoryFactory; $this->_productFactory = $productFactory; @@ -258,11 +247,10 @@ public function __construct( $this->_dateModel = $modelDate; $this->_storeManager = $storeManager; $this->_request = $request; - $this->dateTime = $dateTime; $this->itemProvider = $itemProvider ?: ObjectManager::getInstance()->get(ItemProviderInterface::class); $this->configReader = $configReader ?: ObjectManager::getInstance()->get(SitemapConfigReaderInterface::class); $this->sitemapItemFactory = $sitemapItemFactory ?: ObjectManager::getInstance()->get( - \Magento\Sitemap\Model\SitemapItemInterfaceFactory::class + SitemapItemInterfaceFactory::class ); parent::__construct($context, $registry, $resource, $resourceCollection, $data); @@ -281,7 +269,7 @@ protected function _construct() /** * Get file handler * - * @return \Magento\Framework\Filesystem\File\WriteInterface + * @return FileWriteInterface * @throws LocalizedException */ protected function _getStream() @@ -319,7 +307,7 @@ public function addSitemapItem(DataObject $sitemapItem) */ public function collectSitemapItems() { - /** @var $helper \Magento\Sitemap\Helper\Data */ + /** @var SitemapHelper $helper */ $helper = $this->_sitemapData; $storeId = $this->getStoreId(); @@ -387,7 +375,7 @@ protected function _initSitemapItems() /** * Check sitemap file location and permissions * - * @return \Magento\Framework\Model\AbstractModel + * @return AbstractModel * @throws LocalizedException */ public function beforeSave() @@ -454,7 +442,7 @@ public function generateXml() { $this->_initSitemapItems(); - /** @var $item SitemapItemInterface */ + /** @var SitemapItemInterface $item */ foreach ($this->_sitemapItems as $item) { $xml = $this->_getSitemapRow( $item->getUrl(), @@ -520,7 +508,7 @@ protected function _createSitemapIndex() */ protected function _getCurrentDateTime() { - return (new \DateTime())->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT); + return (new DateTime())->format(FrameworkDateTime::DATETIME_PHP_FORMAT); } /** @@ -550,7 +538,7 @@ protected function _isSplitRequired($row) * @param null|string $lastmod * @param null|string $changefreq * @param null|string $priority - * @param null|array|\Magento\Framework\DataObject $images + * @param null|array|DataObject $images * @return string * Sitemap images * @see http://support.google.com/webmasters/bin/answer.py?hl=en&answer=178636 @@ -600,7 +588,7 @@ protected function _getSitemapRow($url, $lastmod = null, $changefreq = null, $pr */ private function escapeXmlText(string $text): string { - $doc = new \DOMDocument('1.0', 'UTF-8'); + $doc = new DOMDocument('1.0', 'UTF-8'); $fragment = $doc->createDocumentFragment(); $fragment->appendChild($doc->createTextNode($text)); return $doc->saveXML($fragment); @@ -706,7 +694,7 @@ protected function _getBaseDir() */ protected function _getStoreBaseUrl($type = UrlInterface::URL_TYPE_LINK) { - /** @var \Magento\Store\Model\Store $store */ + /** @var ModelStore $store */ $store = $this->_storeManager->getStore($this->getStoreId()); $isSecure = $store->isUrlSecure(); return rtrim($store->getBaseUrl($type, $isSecure), '/') . '/'; diff --git a/app/code/Magento/Sitemap/Model/SitemapConfigReader.php b/app/code/Magento/Sitemap/Model/SitemapConfigReader.php index 201e80d281ca3..7e26db03ccbbf 100644 --- a/app/code/Magento/Sitemap/Model/SitemapConfigReader.php +++ b/app/code/Magento/Sitemap/Model/SitemapConfigReader.php @@ -38,21 +38,14 @@ class SitemapConfigReader implements SitemapConfigReaderInterface */ const XML_PATH_PRODUCT_IMAGES_INCLUDE = 'sitemap/product/image_include'; - /** - * Scope config - * - * @var ScopeConfigInterface - */ - private $scopeConfig; - /** * Sitemap Config Reader constructor. * - * @param ScopeConfigInterface $scopeConfig + * @param ScopeConfigInterface $scopeConfig Scope config */ - public function __construct(ScopeConfigInterface $scopeConfig) - { - $this->scopeConfig = $scopeConfig; + public function __construct( + private readonly ScopeConfigInterface $scopeConfig + ) { } /** diff --git a/app/code/Magento/Sitemap/Model/SitemapItem.php b/app/code/Magento/Sitemap/Model/SitemapItem.php index 2436a6f797d98..62a38f28abb10 100644 --- a/app/code/Magento/Sitemap/Model/SitemapItem.php +++ b/app/code/Magento/Sitemap/Model/SitemapItem.php @@ -8,31 +8,6 @@ class SitemapItem implements SitemapItemInterface { - /** - * @var string - */ - private $url; - - /** - * @var string - */ - private $priority; - - /** - * @var string - */ - private $changeFrequency; - - /** - * @var array - */ - private $images; - - /** - * @var string - */ - private $updatedAt; - /** * SitemapItem constructor. * @@ -42,13 +17,13 @@ class SitemapItem implements SitemapItemInterface * @param string|null $updatedAt * @param array|null $images */ - public function __construct($url, $priority, $changeFrequency, $updatedAt = null, $images = null) - { - $this->url = $url; - $this->priority = $priority; - $this->changeFrequency = $changeFrequency; - $this->updatedAt = $updatedAt; - $this->images = $images; + public function __construct( + private $url, + private $priority, + private $changeFrequency, + private $updatedAt = null, + private $images = null + ) { } /** diff --git a/app/code/Magento/Sitemap/Model/Source/Product/Image/IncludeImage.php b/app/code/Magento/Sitemap/Model/Source/Product/Image/IncludeImage.php index 9dd905d63d9e2..c8620f60de925 100644 --- a/app/code/Magento/Sitemap/Model/Source/Product/Image/IncludeImage.php +++ b/app/code/Magento/Sitemap/Model/Source/Product/Image/IncludeImage.php @@ -10,11 +10,13 @@ */ namespace Magento\Sitemap\Model\Source\Product\Image; +use Magento\Framework\Option\ArrayInterface; + /** * @api * @since 100.0.2 */ -class IncludeImage implements \Magento\Framework\Option\ArrayInterface +class IncludeImage implements ArrayInterface { /**#@+ * Add Images into Sitemap possible values diff --git a/app/code/Magento/Sitemap/registration.php b/app/code/Magento/Sitemap/registration.php index b713ddb98f381..21a76e31e2da8 100644 --- a/app/code/Magento/Sitemap/registration.php +++ b/app/code/Magento/Sitemap/registration.php @@ -6,4 +6,8 @@ use Magento\Framework\Component\ComponentRegistrar; -ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_Sitemap', __DIR__); +ComponentRegistrar::register( + ComponentRegistrar::MODULE, + 'Magento_Sitemap', + __DIR__ +);