From 64085bfc588b5d23b3d5cfe2935d65a88baf23da Mon Sep 17 00:00:00 2001 From: Leon Helmus Date: Wed, 8 Mar 2023 17:45:45 +0100 Subject: [PATCH] Use constructor property promotion in module Theme Replace allmost all properties with constructor property promotion in module Theme: https://stitcher.io/blog/constructor-promotion-in-php-8 * Readable code * Make Magento less complex by removing properties which take up a lot of lines. * Imported all classes to make code more readable. I think the code would be a lot cleaner if all modules start using constructor promotions, since of 2.4.6 php 7.4 is dropped we can now make use of it. So let's start on it right now :). --- .../Adminhtml/Design/Config/Edit/Scope.php | 8 +- .../Block/Adminhtml/System/Design/Theme.php | 7 +- .../Adminhtml/System/Design/Theme/Edit.php | 27 ++-- .../System/Design/Theme/Edit/AbstractTab.php | 33 ++-- .../System/Design/Theme/Edit/Form.php | 11 +- .../Design/Theme/Edit/Form/Element/File.php | 4 +- .../Design/Theme/Edit/Form/Element/Image.php | 4 +- .../Design/Theme/Edit/Form/Element/Links.php | 19 ++- .../System/Design/Theme/Edit/Tab/Css.php | 86 ++++++----- .../System/Design/Theme/Edit/Tab/General.php | 58 ++++--- .../System/Design/Theme/Edit/Tab/Js.php | 21 ++- .../System/Design/Theme/Edit/Tabs.php | 4 +- .../Block/Adminhtml/Wysiwyg/Files/Content.php | 30 ++-- .../Adminhtml/Wysiwyg/Files/Content/Files.php | 7 +- .../Wysiwyg/Files/Content/Uploader.php | 25 ++-- .../Block/Adminhtml/Wysiwyg/Files/Tree.php | 48 +++--- .../Magento/Theme/Block/Html/Breadcrumbs.php | 12 +- app/code/Magento/Theme/Block/Html/Footer.php | 31 ++-- app/code/Magento/Theme/Block/Html/Header.php | 21 ++- .../Theme/Block/Html/Header/CriticalCss.php | 16 +- .../Magento/Theme/Block/Html/Header/Logo.php | 25 ++-- app/code/Magento/Theme/Block/Html/Notices.php | 16 +- app/code/Magento/Theme/Block/Html/Pager.php | 16 +- app/code/Magento/Theme/Block/Html/Title.php | 8 +- app/code/Magento/Theme/Block/Html/Topmenu.php | 18 +-- .../Console/Command/ThemeUninstallCommand.php | 141 ++++-------------- .../Adminhtml/Design/Config/Edit.php | 24 +-- .../Design/Config/FileUploader/Save.php | 9 +- .../Adminhtml/Design/Config/Index.php | 13 +- .../Adminhtml/Design/Config/Save.php | 30 +--- .../Adminhtml/System/Design/Theme.php | 37 +++-- .../Adminhtml/System/Design/Theme/Delete.php | 22 ++- .../System/Design/Theme/DownloadCss.php | 19 +-- .../System/Design/Theme/DownloadCustomCss.php | 20 ++- .../Adminhtml/System/Design/Theme/Edit.php | 30 ++-- .../Adminhtml/System/Design/Theme/Grid.php | 4 +- .../Adminhtml/System/Design/Theme/Index.php | 3 +- .../System/Design/Theme/NewAction.php | 4 +- .../Adminhtml/System/Design/Theme/Save.php | 41 +++-- .../System/Design/Theme/UploadCss.php | 21 ++- .../System/Design/Theme/UploadJs.php | 40 +++-- .../Adminhtml/System/Design/Wysiwyg/Files.php | 32 ++-- .../System/Design/Wysiwyg/Files/Contents.php | 10 +- .../Design/Wysiwyg/Files/DeleteFiles.php | 16 +- .../Design/Wysiwyg/Files/DeleteFolder.php | 10 +- .../System/Design/Wysiwyg/Files/Index.php | 4 +- .../System/Design/Wysiwyg/Files/NewFolder.php | 16 +- .../System/Design/Wysiwyg/Files/OnInsert.php | 9 +- .../Design/Wysiwyg/Files/PreviewImage.php | 14 +- .../System/Design/Wysiwyg/Files/TreeJson.php | 16 +- .../System/Design/Wysiwyg/Files/Upload.php | 10 +- .../Controller/Result/AsyncCssPlugin.php | 14 +- .../Controller/Result/JsFooterPlugin.php | 11 +- .../Theme/Controller/Result/MessagePlugin.php | 71 +++------ .../Magento/Theme/CustomerData/Messages.php | 27 +--- .../Theme/CustomerData/MessagesProvider.php | 12 +- app/code/Magento/Theme/Helper/Storage.php | 94 ++++++------ app/code/Magento/Theme/Helper/Theme.php | 32 ++-- app/code/Magento/Theme/Model/Config.php | 57 ++++--- .../Theme/Model/Config/Customization.php | 16 +- .../Magento/Theme/Model/Config/Importer.php | 23 +-- .../Model/Config/Processor/DesignTheme.php | 22 +-- app/code/Magento/Theme/Model/CopyService.php | 59 +++++--- .../Theme/Model/Data/Design/Config.php | 3 +- .../Theme/Model/Data/Design/ConfigFactory.php | 48 +----- app/code/Magento/Theme/Model/Design.php | 52 +++---- .../Theme/Model/Design/Backend/Exceptions.php | 49 +++--- .../Theme/Model/Design/Backend/Favicon.php | 3 +- .../Theme/Model/Design/Backend/File.php | 22 +-- .../Theme/Model/Design/Backend/Theme.php | 43 +++--- .../Model/Design/BackendModelFactory.php | 16 +- .../Model/Design/Config/DataProvider.php | 20 +-- .../Design/Config/DataProvider/DataLoader.php | 24 +-- .../Config/DataProvider/MetadataLoader.php | 32 +--- .../Config/FileUploader/FileProcessor.php | 37 +---- .../Model/Design/Config/MetadataProvider.php | 11 +- .../Theme/Model/Design/Config/Plugin.php | 16 +- .../Theme/Model/Design/Config/Plugin/Dump.php | 21 +-- .../Theme/Model/Design/Config/Storage.php | 55 ++----- .../Theme/Model/Design/Config/Validator.php | 18 +-- .../Model/Design/Config/ValueChecker.php | 26 +--- .../Model/Design/Config/ValueProcessor.php | 8 +- .../Theme/Model/Design/Theme/Label.php | 4 +- .../Theme/Model/DesignConfigRepository.php | 32 +--- .../Magento/Theme/Model/Favicon/Favicon.php | 53 +++---- .../Theme/Model/Indexer/Design/Config.php | 58 ++----- .../Indexer/Design/Config/FieldsProvider.php | 11 +- .../Indexer/Design/Config/Plugin/Store.php | 11 +- .../Design/Config/Plugin/StoreGroup.php | 8 +- .../Indexer/Design/Config/Plugin/Website.php | 13 +- .../Model/Indexer/Design/IndexerHandler.php | 9 +- .../Magento/Theme/Model/Layout/Config.php | 20 ++- .../Theme/Model/Layout/Config/Converter.php | 4 +- .../Theme/Model/Layout/Config/Reader.php | 4 +- .../Model/Layout/Config/SchemaLocator.php | 3 +- .../Theme/Model/Layout/Source/Layout.php | 14 +- .../Theme/Model/PageLayout/Config/Builder.php | 37 +---- .../Theme/Model/ResourceModel/Design.php | 42 +++--- .../Model/ResourceModel/Design/Collection.php | 55 ++++--- .../Model/ResourceModel/Design/Config.php | 4 +- .../Design/Config/Collection.php | 8 +- .../Design/Config/Scope/Collection.php | 41 ++--- .../Theme/Model/ResourceModel/Theme.php | 4 +- .../Model/ResourceModel/Theme/Collection.php | 44 +++--- .../Theme/Customization/Update.php | 4 +- .../ResourceModel/Theme/Data/Collection.php | 12 +- .../Theme/Model/ResourceModel/Theme/File.php | 4 +- .../ResourceModel/Theme/File/Collection.php | 15 +- .../ResourceModel/Theme/Grid/Collection.php | 9 +- .../Theme/Model/Source/InitialThemeSource.php | 30 +--- app/code/Magento/Theme/Model/Theme.php | 89 ++++++----- .../Magento/Theme/Model/Theme/Collection.php | 4 +- .../Model/Theme/Customization/Config.php | 18 +-- .../Theme/Customization/File/CustomCss.php | 9 +- app/code/Magento/Theme/Model/Theme/Data.php | 7 +- .../Theme/Model/Theme/Data/Collection.php | 6 +- .../Theme/Model/Theme/Domain/Physical.php | 47 +++--- .../Theme/Model/Theme/Domain/Staging.php | 20 ++- .../Theme/Model/Theme/Domain/Virtual.php | 44 +++--- app/code/Magento/Theme/Model/Theme/File.php | 52 ++++--- .../Theme/Model/Theme/FileProvider.php | 24 +-- .../Magento/Theme/Model/Theme/Image/Path.php | 36 ++--- .../Theme/Model/Theme/Plugin/Registration.php | 45 +----- .../Theme/Model/Theme/Registration.php | 20 +-- .../Magento/Theme/Model/Theme/Resolver.php | 45 +++--- .../Magento/Theme/Model/Theme/SingleFile.php | 19 ++- .../Theme/Model/Theme/Source/Theme.php | 11 +- .../Model/Theme/StoreDefaultThemeResolver.php | 17 +-- .../Theme/StoreUserAgentThemeResolver.php | 14 +- .../Model/Theme/ThemeDependencyChecker.php | 33 +--- .../Theme/Model/Theme/ThemePackageInfo.php | 34 ++--- .../Theme/Model/Theme/ThemeProvider.php | 63 +++----- .../Theme/Model/Theme/ThemeUninstaller.php | 25 +--- .../Magento/Theme/Model/ThemeValidator.php | 31 +--- .../Magento/Theme/Model/Uploader/Service.php | 49 +++--- .../Theme/Model/Url/Plugin/Signature.php | 35 ++--- app/code/Magento/Theme/Model/View/Design.php | 69 +++++---- .../Magento/Theme/Model/Wysiwyg/Storage.php | 77 ++++------ .../ApplyThemeCustomizationObserver.php | 53 ++++--- .../Observer/CheckThemeIsAssignedObserver.php | 27 ++-- .../CleanThemeRelatedContentObserver.php | 43 ++---- .../Magento/Theme/Plugin/LoadDesignPlugin.php | 16 +- .../Patch/Data/ConvertSerializedData.php | 27 +--- .../Theme/Setup/Patch/Data/RegisterThemes.php | 18 +-- .../Magento/Theme/Setup/RecurringData.php | 20 +-- .../Component/Design/Config/DataProvider.php | 12 +- .../Config/SearchRobots/ResetButton.php | 14 +- .../Component/Listing/Column/EditAction.php | 8 +- .../Component/Listing/Column/ViewAction.php | 8 +- .../Theme/DataProvider/SearchResult.php | 12 +- .../Block/Html/Header/LogoPathResolver.php | 8 +- .../Block/Html/Header/LogoSizeResolver.php | 8 +- .../Theme/ViewModel/Block/SessionConfig.php | 10 +- app/code/Magento/Theme/registration.php | 6 +- 154 files changed, 1614 insertions(+), 2264 deletions(-) diff --git a/app/code/Magento/Theme/Block/Adminhtml/Design/Config/Edit/Scope.php b/app/code/Magento/Theme/Block/Adminhtml/Design/Config/Edit/Scope.php index 278808afb915c..d50643897926f 100644 --- a/app/code/Magento/Theme/Block/Adminhtml/Design/Config/Edit/Scope.php +++ b/app/code/Magento/Theme/Block/Adminhtml/Design/Config/Edit/Scope.php @@ -18,21 +18,15 @@ */ class Scope extends Template { - /** - * @var ScopeResolverPool - */ - private $scopeResolverPool; - /** * @param Context $context * @param ScopeResolverPool $scopeResolverPool */ public function __construct( Context $context, - ScopeResolverPool $scopeResolverPool + private readonly ScopeResolverPool $scopeResolverPool ) { parent::__construct($context); - $this->scopeResolverPool = $scopeResolverPool; } /** diff --git a/app/code/Magento/Theme/Block/Adminhtml/System/Design/Theme.php b/app/code/Magento/Theme/Block/Adminhtml/System/Design/Theme.php index 0b2aa41f4b67b..7550cd3af7696 100644 --- a/app/code/Magento/Theme/Block/Adminhtml/System/Design/Theme.php +++ b/app/code/Magento/Theme/Block/Adminhtml/System/Design/Theme.php @@ -5,13 +5,16 @@ */ namespace Magento\Theme\Block\Adminhtml\System\Design; +use Magento\Backend\Block\Widget\Grid\Container; +use Magento\Framework\Phrase; + /** * Container for theme grid * * @api * @since 100.0.2 */ -class Theme extends \Magento\Backend\Block\Widget\Grid\Container +class Theme extends Container { /** * Initialize grid container and prepare controls @@ -33,7 +36,7 @@ public function _construct() /** * Prepare header for container * - * @return \Magento\Framework\Phrase + * @return Phrase */ public function getHeaderText() { diff --git a/app/code/Magento/Theme/Block/Adminhtml/System/Design/Theme/Edit.php b/app/code/Magento/Theme/Block/Adminhtml/System/Design/Theme/Edit.php index 749a9f8dafac5..2e2127d42af98 100644 --- a/app/code/Magento/Theme/Block/Adminhtml/System/Design/Theme/Edit.php +++ b/app/code/Magento/Theme/Block/Adminhtml/System/Design/Theme/Edit.php @@ -9,27 +9,34 @@ */ namespace Magento\Theme\Block\Adminhtml\System\Design\Theme; +use Magento\Backend\Block\Widget\Context; +use Magento\Backend\Block\Widget\Form\Container; +use Magento\Framework\Registry; +use Magento\Framework\View\Design\ThemeInterface; +use Magento\Framework\View\Element\AbstractBlock; +use Magento\Theme\Model\Theme; + /** * @api * @since 100.0.2 */ -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 Context $context + * @param Registry $registry * @param array $data */ public function __construct( - \Magento\Backend\Block\Widget\Context $context, - \Magento\Framework\Registry $registry, + Context $context, + Registry $registry, array $data = [] ) { $this->_coreRegistry = $registry; @@ -39,7 +46,7 @@ public function __construct( /** * Prepare layout * - * @return \Magento\Framework\View\Element\AbstractBlock + * @return AbstractBlock */ protected function _prepareLayout() { @@ -51,7 +58,7 @@ protected function _prepareLayout() $this->getLayout()->getBlock('page.title')->setPageTitle($this->getHeaderText()); } - /** @var $theme \Magento\Framework\View\Design\ThemeInterface */ + /** @var ThemeInterface $theme */ $theme = $this->_getCurrentTheme(); if ($theme) { if ($theme->isEditable()) { @@ -98,7 +105,7 @@ protected function _prepareLayout() */ public function getHeaderText() { - /** @var $theme \Magento\Framework\View\Design\ThemeInterface */ + /** @var ThemeInterface $theme */ $theme = $this->_getCurrentTheme(); if ($theme->getId()) { $header = __('Theme: %1', $theme->getThemeTitle()); @@ -111,7 +118,7 @@ public function getHeaderText() /** * Get current theme * - * @return \Magento\Theme\Model\Theme + * @return Theme */ protected function _getCurrentTheme() { diff --git a/app/code/Magento/Theme/Block/Adminhtml/System/Design/Theme/Edit/AbstractTab.php b/app/code/Magento/Theme/Block/Adminhtml/System/Design/Theme/Edit/AbstractTab.php index a2587975846af..f1ead8c7d1477 100644 --- a/app/code/Magento/Theme/Block/Adminhtml/System/Design/Theme/Edit/AbstractTab.php +++ b/app/code/Magento/Theme/Block/Adminhtml/System/Design/Theme/Edit/AbstractTab.php @@ -5,39 +5,46 @@ */ namespace Magento\Theme\Block\Adminhtml\System\Design\Theme\Edit; +use Magento\Backend\Block\Template\Context; +use Magento\Backend\Block\Widget\Form\Generic; +use Magento\Backend\Block\Widget\Tab\TabInterface; +use Magento\Framework\Data\FormFactory; +use Magento\Framework\ObjectManagerInterface; +use Magento\Framework\Registry; +use Magento\Theme\Model\Theme; + /** * Theme form tab abstract block * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) * @SuppressWarnings(PHPMD.DepthOfInheritance) */ -abstract class AbstractTab extends \Magento\Backend\Block\Widget\Form\Generic implements - \Magento\Backend\Block\Widget\Tab\TabInterface +abstract class AbstractTab extends Generic implements TabInterface { /** - * @var \Magento\Framework\ObjectManagerInterface + * @var ObjectManagerInterface */ protected $_objectManager; /** * Core registry * - * @var \Magento\Framework\Registry + * @var Registry */ protected $_coreRegistry = null; /** - * @param \Magento\Backend\Block\Template\Context $context - * @param \Magento\Framework\Registry $registry - * @param \Magento\Framework\Data\FormFactory $formFactory - * @param \Magento\Framework\ObjectManagerInterface $objectManager + * @param Context $context + * @param Registry $registry + * @param FormFactory $formFactory + * @param ObjectManagerInterface $objectManager * @param array $data */ public function __construct( - \Magento\Backend\Block\Template\Context $context, - \Magento\Framework\Registry $registry, - \Magento\Framework\Data\FormFactory $formFactory, - \Magento\Framework\ObjectManagerInterface $objectManager, + Context $context, + Registry $registry, + FormFactory $formFactory, + ObjectManagerInterface $objectManager, array $data = [] ) { parent::__construct($context, $registry, $formFactory, $data); @@ -47,7 +54,7 @@ public function __construct( /** * Get theme that is edited currently * - * @return \Magento\Theme\Model\Theme + * @return Theme */ protected function _getCurrentTheme() { diff --git a/app/code/Magento/Theme/Block/Adminhtml/System/Design/Theme/Edit/Form.php b/app/code/Magento/Theme/Block/Adminhtml/System/Design/Theme/Edit/Form.php index 3f458ac44af05..97c5436a9f3c3 100644 --- a/app/code/Magento/Theme/Block/Adminhtml/System/Design/Theme/Edit/Form.php +++ b/app/code/Magento/Theme/Block/Adminhtml/System/Design/Theme/Edit/Form.php @@ -5,21 +5,26 @@ */ namespace Magento\Theme\Block\Adminhtml\System\Design\Theme\Edit; +use Magento\Backend\Block\Widget\Form as WidgetForm; +use Magento\Backend\Block\Widget\Form\Generic; +use Magento\Framework\Data\Form as FormData; +use Magento\Theme\Block\Adminhtml\System\Design\Theme\Edit\Form as SystemDesignThemeEditForm; + /** * Theme Edit Form * * @SuppressWarnings(PHPMD.DepthOfInheritance) */ -class Form extends \Magento\Backend\Block\Widget\Form\Generic +class Form extends Generic { /** * Initialize theme form * - * @return \Magento\Theme\Block\Adminhtml\System\Design\Theme\Edit\Form|\Magento\Backend\Block\Widget\Form + * @return SystemDesignThemeEditForm|WidgetForm */ protected function _prepareForm() { - /** @var \Magento\Framework\Data\Form $form */ + /** @var FormData $form */ $form = $this->_formFactory->create( [ 'data' => [ diff --git a/app/code/Magento/Theme/Block/Adminhtml/System/Design/Theme/Edit/Form/Element/File.php b/app/code/Magento/Theme/Block/Adminhtml/System/Design/Theme/Edit/Form/Element/File.php index 5fc3106008166..f61ff45b0ee40 100644 --- a/app/code/Magento/Theme/Block/Adminhtml/System/Design/Theme/Edit/Form/Element/File.php +++ b/app/code/Magento/Theme/Block/Adminhtml/System/Design/Theme/Edit/Form/Element/File.php @@ -9,7 +9,9 @@ */ namespace Magento\Theme\Block\Adminhtml\System\Design\Theme\Edit\Form\Element; -class File extends \Magento\Framework\Data\Form\Element\File +use Magento\Framework\Data\Form\Element\File as FormElementFile; + +class File extends FormElementFile { /** * Additional html attributes diff --git a/app/code/Magento/Theme/Block/Adminhtml/System/Design/Theme/Edit/Form/Element/Image.php b/app/code/Magento/Theme/Block/Adminhtml/System/Design/Theme/Edit/Form/Element/Image.php index acb76d1ee19d4..dee5c2f0f2c60 100644 --- a/app/code/Magento/Theme/Block/Adminhtml/System/Design/Theme/Edit/Form/Element/Image.php +++ b/app/code/Magento/Theme/Block/Adminhtml/System/Design/Theme/Edit/Form/Element/Image.php @@ -6,12 +6,14 @@ namespace Magento\Theme\Block\Adminhtml\System\Design\Theme\Edit\Form\Element; +use Magento\Framework\Data\Form\Element\Image as FormElementImage; + /** * Image form element that generates correct thumbnail image URL for theme preview image * * @method \Magento\Theme\Model\Theme getTheme() */ -class Image extends \Magento\Framework\Data\Form\Element\Image +class Image extends FormElementImage { /** * Get image preview url diff --git a/app/code/Magento/Theme/Block/Adminhtml/System/Design/Theme/Edit/Form/Element/Links.php b/app/code/Magento/Theme/Block/Adminhtml/System/Design/Theme/Edit/Form/Element/Links.php index 05f6c64492b11..b63a8361404c5 100644 --- a/app/code/Magento/Theme/Block/Adminhtml/System/Design/Theme/Edit/Form/Element/Links.php +++ b/app/code/Magento/Theme/Block/Adminhtml/System/Design/Theme/Edit/Form/Element/Links.php @@ -11,18 +11,23 @@ */ namespace Magento\Theme\Block\Adminhtml\System\Design\Theme\Edit\Form\Element; -class Links extends \Magento\Framework\Data\Form\Element\AbstractElement +use Magento\Framework\Data\Form\Element\AbstractElement; +use Magento\Framework\Data\Form\Element\CollectionFactory; +use Magento\Framework\Data\Form\Element\Factory; +use Magento\Framework\Escaper; + +class Links extends AbstractElement { /** - * @param \Magento\Framework\Data\Form\Element\Factory $factoryElement - * @param \Magento\Framework\Data\Form\Element\CollectionFactory $factoryCollection - * @param \Magento\Framework\Escaper $escaper + * @param Factory $factoryElement + * @param CollectionFactory $factoryCollection + * @param Escaper $escaper * @param array $data */ public function __construct( - \Magento\Framework\Data\Form\Element\Factory $factoryElement, - \Magento\Framework\Data\Form\Element\CollectionFactory $factoryCollection, - \Magento\Framework\Escaper $escaper, + Factory $factoryElement, + CollectionFactory $factoryCollection, + Escaper $escaper, $data = [] ) { parent::__construct($factoryElement, $factoryCollection, $escaper, $data); diff --git a/app/code/Magento/Theme/Block/Adminhtml/System/Design/Theme/Edit/Tab/Css.php b/app/code/Magento/Theme/Block/Adminhtml/System/Design/Theme/Edit/Tab/Css.php index 5e3bb8774d246..0e477ef259e31 100644 --- a/app/code/Magento/Theme/Block/Adminhtml/System/Design/Theme/Edit/Tab/Css.php +++ b/app/code/Magento/Theme/Block/Adminhtml/System/Design/Theme/Edit/Tab/Css.php @@ -5,61 +5,73 @@ */ namespace Magento\Theme\Block\Adminhtml\System\Design\Theme\Edit\Tab; +use Magento\Backend\Block\Template\Context; +use Magento\Backend\Block\Widget\Button; +use Magento\Backend\Model\Session; +use Magento\Framework\Data\Form as FormData; +use Magento\Framework\Data\FormFactory; +use Magento\Framework\Encryption\UrlCoder; +use Magento\Framework\File\Size; +use Magento\Framework\ObjectManagerInterface; +use Magento\Framework\Phrase; +use Magento\Framework\Registry; +use Magento\Framework\View\Asset\LocalInterface; +use Magento\Theme\Block\Adminhtml\System\Design\Theme\Edit\AbstractTab; +use Magento\Theme\Block\Adminhtml\System\Design\Theme\Edit\Form\Element\File as FormElementFile; +use Magento\Theme\Block\Adminhtml\System\Design\Theme\Edit\Form\Element\Links; use Magento\Theme\Helper\Storage; +use Magento\Theme\Model\Theme\Customization\File\CustomCss; +use Magento\Theme\Model\Theme\File; +use Magento\Theme\Model\Uploader\Service; +use Magento\Theme\Model\Wysiwyg\Storage as WysiwygStorage; /** * Theme form, Css editor tab * * @api - * @method \Magento\Theme\Block\Adminhtml\System\Design\Theme\Edit\Tab\Css setFiles(array $files) + * @method Css setFiles(array $files) * @method array getFiles() * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) * @SuppressWarnings(PHPMD.DepthOfInheritance) * @since 100.0.2 */ -class Css extends \Magento\Theme\Block\Adminhtml\System\Design\Theme\Edit\AbstractTab +class Css extends AbstractTab { /** * Uploader service * - * @var \Magento\Theme\Model\Uploader\Service + * @var Service */ protected $_uploaderService; /** * Theme custom css file * - * @var \Magento\Theme\Model\Theme\File + * @var File */ protected $_customCssFile; /** - * @var \Magento\Framework\Encryption\UrlCoder - */ - protected $urlCoder; - - /** - * @param \Magento\Backend\Block\Template\Context $context - * @param \Magento\Framework\Registry $registry - * @param \Magento\Framework\Data\FormFactory $formFactory - * @param \Magento\Framework\ObjectManagerInterface $objectManager - * @param \Magento\Theme\Model\Uploader\Service $uploaderService - * @param \Magento\Framework\Encryption\UrlCoder $urlCoder + * @param Context $context + * @param Registry $registry + * @param FormFactory $formFactory + * @param ObjectManagerInterface $objectManager + * @param Service $uploaderService + * @param UrlCoder $urlCoder * @param array $data */ public function __construct( - \Magento\Backend\Block\Template\Context $context, - \Magento\Framework\Registry $registry, - \Magento\Framework\Data\FormFactory $formFactory, - \Magento\Framework\ObjectManagerInterface $objectManager, - \Magento\Theme\Model\Uploader\Service $uploaderService, - \Magento\Framework\Encryption\UrlCoder $urlCoder, + Context $context, + Registry $registry, + FormFactory $formFactory, + ObjectManagerInterface $objectManager, + Service $uploaderService, + protected readonly UrlCoder $urlCoder, array $data = [] ) { parent::__construct($context, $registry, $formFactory, $objectManager, $data); $this->_uploaderService = $uploaderService; - $this->urlCoder = $urlCoder; } /** @@ -69,21 +81,21 @@ public function __construct( */ protected function _prepareForm() { - /** @var \Magento\Framework\Data\Form $form */ + /** @var FormData $form */ $form = $this->_formFactory->create(); $this->setForm($form); $this->_addThemeCssFieldset(); $customFiles = $this->_getCurrentTheme()->getCustomization()->getFilesByType( - \Magento\Theme\Model\Theme\Customization\File\CustomCss::TYPE + CustomCss::TYPE ); $this->_customCssFile = reset($customFiles); $this->_addCustomCssFieldset(); $formData['custom_css_content'] = $this->_customCssFile ? $this->_customCssFile->getContent() : null; - /** @var $session \Magento\Backend\Model\Session */ - $session = $this->_objectManager->get(\Magento\Backend\Model\Session::class); + /** @var Session $session */ + $session = $this->_objectManager->get(Session::class); $cssFileContent = $session->getThemeCustomCssData(); if ($cssFileContent) { $formData['custom_css_content'] = $cssFileContent; @@ -109,7 +121,7 @@ protected function _addThemeCssFieldset() $this->_addElementTypes($themeFieldset); $links = []; - /** @var \Magento\Framework\View\Asset\LocalInterface $asset */ + /** @var LocalInterface $asset */ foreach ($this->getFiles() as $fileId => $asset) { $links[$fileId] = [ 'href' => $this->getDownloadUrl($fileId, $this->_getCurrentTheme()->getId()), @@ -178,9 +190,9 @@ protected function _addCustomCssFieldset() } $themeFieldset->addField('css_download_button', 'button', $downloadButtonConfig); - /** @var $imageButton \Magento\Backend\Block\Widget\Button */ + /** @var Button $imageButton */ $imageButton = $this->getLayout()->createBlock( - \Magento\Backend\Block\Widget\Button::class + Button::class )->setData( [ 'id' => 'css_images_manager', @@ -191,7 +203,7 @@ protected function _addCustomCssFieldset() [ 'target_element_id' => 'custom_css_content', Storage::PARAM_THEME_ID => $this->_getCurrentTheme()->getId(), - Storage::PARAM_CONTENT_TYPE => \Magento\Theme\Model\Wysiwyg\Storage::TYPE_IMAGE + Storage::PARAM_CONTENT_TYPE => WysiwygStorage::TYPE_IMAGE ] ) . "', null, null,'" . $this->escapeJs( __('Upload Images') @@ -205,9 +217,9 @@ protected function _addCustomCssFieldset() ['label' => __("Images Assets"), 'text' => $imageButton->toHtml()] ); - /** @var $fontButton \Magento\Backend\Block\Widget\Button */ + /** @var Button $fontButton */ $fontButton = $this->getLayout()->createBlock( - \Magento\Backend\Block\Widget\Button::class + Button::class )->setData( [ 'id' => 'css_fonts_manager', @@ -218,7 +230,7 @@ protected function _addCustomCssFieldset() [ 'target_element_id' => 'custom_css_content', Storage::PARAM_THEME_ID => $this->_getCurrentTheme()->getId(), - Storage::PARAM_CONTENT_TYPE => \Magento\Theme\Model\Wysiwyg\Storage::TYPE_FONT + Storage::PARAM_CONTENT_TYPE => WysiwygStorage::TYPE_FONT ] ) . "', null, null,'" . $this->escapeJs( __('Upload Fonts') @@ -252,7 +264,7 @@ protected function _getUploadCssFileNote() __('Allowed file types *.css.'), __('This file will replace the current custom.css file and can\'t be more than 2 MB.'), ]; - $maxFileSize = $this->_objectManager->get(\Magento\Framework\File\Size::class)->getMaxFileSizeInMb(); + $maxFileSize = $this->_objectManager->get(Size::class)->getMaxFileSizeInMb(); if ($maxFileSize) { $messages[] = __('Max file size to upload %1M', $maxFileSize); } else { @@ -269,15 +281,15 @@ protected function _getUploadCssFileNote() */ protected function _getAdditionalElementTypes() { - $linksElement = \Magento\Theme\Block\Adminhtml\System\Design\Theme\Edit\Form\Element\Links::class; - $fileElement = \Magento\Theme\Block\Adminhtml\System\Design\Theme\Edit\Form\Element\File::class; + $linksElement = Links::class; + $fileElement = FormElementFile::class; return ['links' => $linksElement, 'css_file' => $fileElement]; } /** * Return Tab label * - * @return \Magento\Framework\Phrase + * @return Phrase */ public function getTabLabel() { diff --git a/app/code/Magento/Theme/Block/Adminhtml/System/Design/Theme/Edit/Tab/General.php b/app/code/Magento/Theme/Block/Adminhtml/System/Design/Theme/Edit/Tab/General.php index 46bef2eb4d2f7..11e64b39ec706 100644 --- a/app/code/Magento/Theme/Block/Adminhtml/System/Design/Theme/Edit/Tab/General.php +++ b/app/code/Magento/Theme/Block/Adminhtml/System/Design/Theme/Edit/Tab/General.php @@ -5,16 +5,28 @@ */ namespace Magento\Theme\Block\Adminhtml\System\Design\Theme\Edit\Tab; +use Magento\Backend\Block\Template\Context; +use Magento\Backend\Model\Session; use Magento\Framework\App\Area; +use Magento\Framework\Data\Form as FormData; +use Magento\Framework\Data\FormFactory; +use Magento\Framework\File\Size; +use Magento\Framework\Json\Helper\Data as JsonHelper; +use Magento\Framework\ObjectManagerInterface; +use Magento\Framework\Phrase; +use Magento\Framework\Registry; use Magento\Framework\View\Design\ThemeInterface; +use Magento\Theme\Block\Adminhtml\System\Design\Theme\Edit\AbstractTab; +use Magento\Theme\Block\Adminhtml\System\Design\Theme\Edit\Form\Element\Image; use Magento\Theme\Model\Theme\Collection; +use Magento\Theme\Model\Theme\Collection as ThemeCollection; /** * Theme form, general tab * * @SuppressWarnings(PHPMD.DepthOfInheritance) */ -class General extends \Magento\Theme\Block\Adminhtml\System\Design\Theme\Edit\AbstractTab +class General extends AbstractTab { /** * Whether theme is editable @@ -24,26 +36,26 @@ class General extends \Magento\Theme\Block\Adminhtml\System\Design\Theme\Edit\Ab protected $_isThemeEditable = false; /** - * @var \Magento\Framework\File\Size + * @var Size */ protected $_fileSize; /** * Constructor * - * @param \Magento\Backend\Block\Template\Context $context - * @param \Magento\Framework\Registry $registry - * @param \Magento\Framework\Data\FormFactory $formFactory - * @param \Magento\Framework\ObjectManagerInterface $objectManager - * @param \Magento\Framework\File\Size $fileSize + * @param Context $context + * @param Registry $registry + * @param FormFactory $formFactory + * @param ObjectManagerInterface $objectManager + * @param Size $fileSize * @param array $data */ public function __construct( - \Magento\Backend\Block\Template\Context $context, - \Magento\Framework\Registry $registry, - \Magento\Framework\Data\FormFactory $formFactory, - \Magento\Framework\ObjectManagerInterface $objectManager, - \Magento\Framework\File\Size $fileSize, + Context $context, + Registry $registry, + FormFactory $formFactory, + ObjectManagerInterface $objectManager, + Size $fileSize, array $data = [] ) { $this->_fileSize = $fileSize; @@ -57,8 +69,8 @@ public function __construct( */ protected function _prepareForm() { - /** @var \Magento\Backend\Model\Session $session */ - $session = $this->_objectManager->get(\Magento\Backend\Model\Session::class); + /** @var Session $session */ + $session = $this->_objectManager->get(Session::class); $formDataFromSession = $session->getThemeData(); $this->_isThemeEditable = $this->_getCurrentTheme()->isEditable(); /** @var ThemeInterface $currentTheme */ @@ -71,7 +83,7 @@ protected function _prepareForm() } $this->setIsThemeExist(isset($formData['theme_id'])); - /** @var \Magento\Framework\Data\Form $form */ + /** @var FormData $form */ $form = $this->_formFactory->create(); $this->_addThemeFieldset($form, $formData, $currentTheme); if (!$this->getIsThemeExist()) { @@ -86,7 +98,7 @@ protected function _prepareForm() /** * Add theme fieldset * - * @param \Magento\Framework\Data\Form $form + * @param FormData $form * @param array $formData * @param ThemeInterface $theme * @return $this @@ -102,10 +114,10 @@ protected function _addThemeFieldset($form, $formData, ThemeInterface $theme) } /** @var Collection $themesCollections */ - $themesCollections = $this->_objectManager->create(\Magento\Theme\Model\Theme\Collection::class); + $themesCollections = $this->_objectManager->create(ThemeCollection::class); - /** @var \Magento\Framework\Json\Helper\Data $helper */ - $helper = $this->_objectManager->get(\Magento\Framework\Json\Helper\Data::class); + /** @var JsonHelper $helper */ + $helper = $this->_objectManager->get(JsonHelper::class); $themesCollections->addConstraint(Collection::CONSTRAINT_AREA, Area::AREA_FRONTEND); $onChangeScript = sprintf( @@ -118,7 +130,7 @@ protected function _addThemeFieldset($form, $formData, ThemeInterface $theme) ); /** @var ThemeInterface $parentTheme */ - $parentTheme = $this->_objectManager->create(\Magento\Framework\View\Design\ThemeInterface::class); + $parentTheme = $this->_objectManager->create(ThemeInterface::class); if (!empty($formData['parent_id'])) { $parentTheme->load($formData['parent_id']); } @@ -241,14 +253,14 @@ protected function _getFieldTextType() */ protected function _getAdditionalElementTypes() { - $element = \Magento\Theme\Block\Adminhtml\System\Design\Theme\Edit\Form\Element\Image::class; + $element = Image::class; return ['image' => $element]; } /** * Prepare label for tab * - * @return \Magento\Framework\Phrase + * @return Phrase */ public function getTabLabel() { @@ -303,7 +315,7 @@ protected function _getDefaultsInherited($themesCollections) /** * Get note string for theme's preview image * - * @return \Magento\Framework\Phrase + * @return Phrase */ protected function _getPreviewImageNote() { diff --git a/app/code/Magento/Theme/Block/Adminhtml/System/Design/Theme/Edit/Tab/Js.php b/app/code/Magento/Theme/Block/Adminhtml/System/Design/Theme/Edit/Tab/Js.php index 14a661e672195..309bdb59bd133 100644 --- a/app/code/Magento/Theme/Block/Adminhtml/System/Design/Theme/Edit/Tab/Js.php +++ b/app/code/Magento/Theme/Block/Adminhtml/System/Design/Theme/Edit/Tab/Js.php @@ -5,6 +5,13 @@ */ namespace Magento\Theme\Block\Adminhtml\System\Design\Theme\Edit\Tab; +use Magento\Backend\Block\Widget\Form\Renderer\Fieldset; +use Magento\Framework\Data\Form as FormData; +use Magento\Framework\Phrase; +use Magento\Framework\View\Design\Theme\Customization\File\Js as CustomizationFileJs; +use Magento\Theme\Block\Adminhtml\System\Design\Theme\Edit\AbstractTab; +use Magento\Theme\Block\Adminhtml\System\Design\Theme\Edit\Form\Element\File; + /** * Theme form, Js editor tab * @@ -12,7 +19,7 @@ * @SuppressWarnings(PHPMD.DepthOfInheritance) * @since 100.0.2 */ -class Js extends \Magento\Theme\Block\Adminhtml\System\Design\Theme\Edit\AbstractTab +class Js extends AbstractTab { /** * Create a form element with necessary controls @@ -21,7 +28,7 @@ class Js extends \Magento\Theme\Block\Adminhtml\System\Design\Theme\Edit\Abstrac */ protected function _prepareForm() { - /** @var \Magento\Framework\Data\Form $form */ + /** @var FormData $form */ $form = $this->_formFactory->create(); $this->setForm($form); $this->_addThemeJsFieldset(); @@ -40,10 +47,10 @@ protected function _addThemeJsFieldset() $themeFieldset = $form->addFieldset('theme_js', ['legend' => __('Theme JavaScript')]); $customization = $this->_getCurrentTheme()->getCustomization(); $customJsFiles = $customization->getFilesByType( - \Magento\Framework\View\Design\Theme\Customization\File\Js::TYPE + CustomizationFileJs::TYPE ); - /** @var $jsFieldsetRenderer \Magento\Backend\Block\Widget\Form\Renderer\Fieldset */ + /** @var Fieldset $jsFieldsetRenderer */ $jsFieldsetRenderer = $this->getChildBlock('theme_edit_tabs_tab_js_tab_content'); $jsFieldsetRenderer->setJsFiles($customization->generateFileInfo($customJsFiles)); @@ -81,14 +88,14 @@ protected function _addThemeJsFieldset() */ protected function _getAdditionalElementTypes() { - $fileElement = \Magento\Theme\Block\Adminhtml\System\Design\Theme\Edit\Form\Element\File::class; + $fileElement = File::class; return ['js_files' => $fileElement]; } /** * Return Tab label * - * @return \Magento\Framework\Phrase + * @return Phrase */ public function getTabLabel() { @@ -111,7 +118,7 @@ public function getJsUploadUrl() /** * Get note string for js file to Upload * - * @return \Magento\Framework\Phrase + * @return Phrase */ protected function _getUploadJsFileNote() { diff --git a/app/code/Magento/Theme/Block/Adminhtml/System/Design/Theme/Edit/Tabs.php b/app/code/Magento/Theme/Block/Adminhtml/System/Design/Theme/Edit/Tabs.php index b27c622b5bd35..8323fae58dcfc 100644 --- a/app/code/Magento/Theme/Block/Adminhtml/System/Design/Theme/Edit/Tabs.php +++ b/app/code/Magento/Theme/Block/Adminhtml/System/Design/Theme/Edit/Tabs.php @@ -5,13 +5,15 @@ */ namespace Magento\Theme\Block\Adminhtml\System\Design\Theme\Edit; +use Magento\Backend\Block\Widget\Tabs as WidgetTabs; + /** * Theme editor tab container * * @api * @since 100.0.2 */ -class Tabs extends \Magento\Backend\Block\Widget\Tabs +class Tabs extends WidgetTabs { /** * Initialize tabs and define tabs block settings diff --git a/app/code/Magento/Theme/Block/Adminhtml/Wysiwyg/Files/Content.php b/app/code/Magento/Theme/Block/Adminhtml/Wysiwyg/Files/Content.php index 4cf9029c1b81c..3d1fb92d82758 100644 --- a/app/code/Magento/Theme/Block/Adminhtml/Wysiwyg/Files/Content.php +++ b/app/code/Magento/Theme/Block/Adminhtml/Wysiwyg/Files/Content.php @@ -5,6 +5,12 @@ */ namespace Magento\Theme\Block\Adminhtml\Wysiwyg\Files; +use Magento\Backend\Block\Widget\Container; +use Magento\Backend\Block\Widget\Context; +use Magento\Framework\DataObject; +use Magento\Framework\Json\Helper\Data as JsonHelper; +use Magento\Theme\Helper\Storage as StorageHelper; + /** * Files content block * @@ -12,31 +18,25 @@ * @SuppressWarnings(PHPMD.CouplingBetweenObjects) * @since 100.0.2 */ -class Content extends \Magento\Backend\Block\Widget\Container +class Content extends Container { /** - * @var \Magento\Theme\Helper\Storage + * @var StorageHelper */ protected $_storageHelper; /** - * @var \Magento\Framework\Json\Helper\Data - */ - protected $jsonHelper; - - /** - * @param \Magento\Backend\Block\Widget\Context $context - * @param \Magento\Theme\Helper\Storage $storageHelper - * @param \Magento\Framework\Json\Helper\Data $jsonHelper + * @param Context $context + * @param StorageHelper $storageHelper + * @param JsonHelper $jsonHelper * @param array $data */ public function __construct( - \Magento\Backend\Block\Widget\Context $context, - \Magento\Theme\Helper\Storage $storageHelper, - \Magento\Framework\Json\Helper\Data $jsonHelper, + Context $context, + StorageHelper $storageHelper, + protected readonly JsonHelper $jsonHelper, array $data = [] ) { - $this->jsonHelper = $jsonHelper; $this->_storageHelper = $storageHelper; parent::__construct($context, $data); } @@ -116,7 +116,7 @@ public function getContentsUrl() */ public function getFilebrowserSetupObject() { - $setupObject = new \Magento\Framework\DataObject(); + $setupObject = new DataObject(); $setupObject->setData( [ diff --git a/app/code/Magento/Theme/Block/Adminhtml/Wysiwyg/Files/Content/Files.php b/app/code/Magento/Theme/Block/Adminhtml/Wysiwyg/Files/Content/Files.php index 0ac05e1e2f21b..bbcbe33ba229e 100644 --- a/app/code/Magento/Theme/Block/Adminhtml/Wysiwyg/Files/Content/Files.php +++ b/app/code/Magento/Theme/Block/Adminhtml/Wysiwyg/Files/Content/Files.php @@ -5,16 +5,19 @@ */ namespace Magento\Theme\Block\Adminhtml\Wysiwyg\Files\Content; +use Magento\Backend\Block\Template; +use Magento\Theme\Model\Wysiwyg\Storage; + /** * Files files block * * @api * @method * \Magento\Theme\Block\Adminhtml\Wysiwyg\Files\Content\Files setStorage(\Magento\Theme\Model\Wysiwyg\Storage $storage) - * @method \Magento\Theme\Model\Wysiwyg\Storage getStorage() + * @method Storage getStorage() * @since 100.0.2 */ -class Files extends \Magento\Backend\Block\Template +class Files extends Template { /** * Files list diff --git a/app/code/Magento/Theme/Block/Adminhtml/Wysiwyg/Files/Content/Uploader.php b/app/code/Magento/Theme/Block/Adminhtml/Wysiwyg/Files/Content/Uploader.php index e99500dbd0694..69b25009865c3 100644 --- a/app/code/Magento/Theme/Block/Adminhtml/Wysiwyg/Files/Content/Uploader.php +++ b/app/code/Magento/Theme/Block/Adminhtml/Wysiwyg/Files/Content/Uploader.php @@ -5,6 +5,11 @@ */ namespace Magento\Theme\Block\Adminhtml\Wysiwyg\Files\Content; +use Magento\Backend\Block\Media\Uploader as MediaUploader; +use Magento\Backend\Block\Template\Context; +use Magento\Framework\File\Size; +use Magento\Theme\Helper\Storage as StorageHelper; + /** * Files uploader block * @@ -12,7 +17,7 @@ * @SuppressWarnings(PHPMD.CouplingBetweenObjects) * @since 100.0.2 */ -class Uploader extends \Magento\Backend\Block\Media\Uploader +class Uploader extends MediaUploader { /** * Path to uploader template @@ -22,20 +27,20 @@ class Uploader extends \Magento\Backend\Block\Media\Uploader protected $_template = 'Magento_Theme::browser/content/uploader.phtml'; /** - * @var \Magento\Theme\Helper\Storage + * @var StorageHelper */ protected $_storageHelper; /** - * @param \Magento\Backend\Block\Template\Context $context - * @param \Magento\Framework\File\Size $fileSize - * @param \Magento\Theme\Helper\Storage $storageHelper + * @param Context $context + * @param Size $fileSize + * @param StorageHelper $storageHelper * @param array $data */ public function __construct( - \Magento\Backend\Block\Template\Context $context, - \Magento\Framework\File\Size $fileSize, - \Magento\Theme\Helper\Storage $storageHelper, + Context $context, + Size $fileSize, + StorageHelper $storageHelper, array $data = [] ) { $this->_storageHelper = $storageHelper; @@ -45,7 +50,7 @@ public function __construct( /** * Prepare layout * - * @return \Magento\Backend\Block\Media\Uploader + * @return MediaUploader */ protected function _prepareLayout() { @@ -56,7 +61,7 @@ protected function _prepareLayout() /** * Return storage helper * - * @return \Magento\Theme\Helper\Storage + * @return StorageHelper */ public function getHelperStorage() { diff --git a/app/code/Magento/Theme/Block/Adminhtml/Wysiwyg/Files/Tree.php b/app/code/Magento/Theme/Block/Adminhtml/Wysiwyg/Files/Tree.php index 1c09668244d10..4d19d337190ea 100644 --- a/app/code/Magento/Theme/Block/Adminhtml/Wysiwyg/Files/Tree.php +++ b/app/code/Magento/Theme/Block/Adminhtml/Wysiwyg/Files/Tree.php @@ -5,6 +5,15 @@ */ namespace Magento\Theme\Block\Adminhtml\Wysiwyg\Files; +use Magento\Backend\Block\Template; +use Magento\Backend\Block\Template\Context; +use Magento\Framework\App\ObjectManager; +use Magento\Framework\Phrase; +use Magento\Framework\Serialize\Serializer\Json; +use Magento\Framework\Url\EncoderInterface; +use Magento\Theme\Helper\Storage; +use RuntimeException; + /** * Files tree block * @@ -12,42 +21,31 @@ * @SuppressWarnings(PHPMD.CouplingBetweenObjects) * @since 100.0.2 */ -class Tree extends \Magento\Backend\Block\Template +class Tree extends Template { /** - * @var \Magento\Theme\Helper\Storage + * @var Storage */ protected $_storageHelper; /** - * @var \Magento\Framework\Url\EncoderInterface - */ - protected $urlEncoder; - - /** - * @var \Magento\Framework\Serialize\Serializer\Json - */ - private $serializer; - - /** - * @param \Magento\Backend\Block\Template\Context $context - * @param \Magento\Theme\Helper\Storage $storageHelper - * @param \Magento\Framework\Url\EncoderInterface $urlEncoder + * @param Context $context + * @param Storage $storageHelper + * @param EncoderInterface $urlEncoder * @param array $data - * @param \Magento\Framework\Serialize\Serializer\Json|null $serializer - * @throws \RuntimeException + * @param Json|null $serializer + * @throws RuntimeException */ public function __construct( - \Magento\Backend\Block\Template\Context $context, - \Magento\Theme\Helper\Storage $storageHelper, - \Magento\Framework\Url\EncoderInterface $urlEncoder, + Context $context, + Storage $storageHelper, + protected readonly EncoderInterface $urlEncoder, array $data = [], - \Magento\Framework\Serialize\Serializer\Json $serializer = null + private ?Json $serializer = null ) { $this->_storageHelper = $storageHelper; - $this->urlEncoder = $urlEncoder; - $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() - ->get(\Magento\Framework\Serialize\Serializer\Json::class); + $this->serializer = $serializer ?: ObjectManager::getInstance() + ->get(Json::class); parent::__construct($context, $data); } @@ -75,7 +73,7 @@ public function getTreeJson($data) /** * Get root node name of tree * - * @return \Magento\Framework\Phrase + * @return Phrase */ public function getRootNodeName() { diff --git a/app/code/Magento/Theme/Block/Html/Breadcrumbs.php b/app/code/Magento/Theme/Block/Html/Breadcrumbs.php index cff87fc8726bd..950f585f16fc5 100644 --- a/app/code/Magento/Theme/Block/Html/Breadcrumbs.php +++ b/app/code/Magento/Theme/Block/Html/Breadcrumbs.php @@ -5,6 +5,7 @@ */ namespace Magento\Theme\Block\Html; +use Magento\Framework\App\ObjectManager; use Magento\Framework\Serialize\Serializer\Json; use Magento\Framework\View\Element\Template; @@ -14,7 +15,7 @@ * @api * @since 100.0.2 */ -class Breadcrumbs extends \Magento\Framework\View\Element\Template +class Breadcrumbs extends Template { /** * Current template name @@ -44,11 +45,6 @@ class Breadcrumbs extends \Magento\Framework\View\Element\Template */ protected $_cacheKeyInfo; - /** - * @var Json - */ - private $serializer; - /** * @param Template\Context $context * @param array $data @@ -57,11 +53,11 @@ class Breadcrumbs extends \Magento\Framework\View\Element\Template public function __construct( Template\Context $context, array $data = [], - Json $serializer = null + private ?Json $serializer = null ) { parent::__construct($context, $data); $this->serializer = - $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()->get(Json::class); + $serializer ?: ObjectManager::getInstance()->get(Json::class); } /** diff --git a/app/code/Magento/Theme/Block/Html/Footer.php b/app/code/Magento/Theme/Block/Html/Footer.php index 7f9b9cf86a809..caf83f10dd417 100644 --- a/app/code/Magento/Theme/Block/Html/Footer.php +++ b/app/code/Magento/Theme/Block/Html/Footer.php @@ -5,7 +5,14 @@ */ namespace Magento\Theme\Block\Html; +use Magento\Cms\Model\Block; use Magento\Customer\Model\Context; +use Magento\Framework\App\Http\Context as HttpContext; +use Magento\Framework\DataObject\IdentityInterface; +use Magento\Framework\View\Element\Template; +use Magento\Framework\View\Element\Template\Context as TemplateContext; +use Magento\Store\Model\ScopeInterface; +use Magento\Store\Model\Store; /** * Html page footer block @@ -13,7 +20,7 @@ * @api * @since 100.0.2 */ -class Footer extends \Magento\Framework\View\Element\Template implements \Magento\Framework\DataObject\IdentityInterface +class Footer extends Template implements IdentityInterface { /** * Copyright information @@ -30,21 +37,15 @@ class Footer extends \Magento\Framework\View\Element\Template implements \Magent private $miscellaneousHtml; /** - * @var \Magento\Framework\App\Http\Context - */ - protected $httpContext; - - /** - * @param \Magento\Framework\View\Element\Template\Context $context - * @param \Magento\Framework\App\Http\Context $httpContext + * @param TemplateContext $context + * @param HttpContext $httpContext * @param array $data */ public function __construct( - \Magento\Framework\View\Element\Template\Context $context, - \Magento\Framework\App\Http\Context $httpContext, + TemplateContext $context, + protected readonly HttpContext $httpContext, array $data = [] ) { - $this->httpContext = $httpContext; parent::__construct($context, $data); } @@ -57,7 +58,7 @@ protected function _construct() { $this->addData( [ - 'cache_tags' => [\Magento\Store\Model\Store::CACHE_TAG, \Magento\Cms\Model\Block::CACHE_TAG], + 'cache_tags' => [Store::CACHE_TAG, Block::CACHE_TAG], ] ); } @@ -90,7 +91,7 @@ public function getCopyright() if (!$this->_copyright) { $this->_copyright = $this->_scopeConfig->getValue( 'design/footer/copyright', - \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ScopeInterface::SCOPE_STORE ); } return __($this->_copyright); @@ -107,7 +108,7 @@ public function getMiscellaneousHtml() if ($this->miscellaneousHtml === null) { $this->miscellaneousHtml = $this->_scopeConfig->getValue( 'design/footer/absolute_footer', - \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ScopeInterface::SCOPE_STORE ); } return $this->miscellaneousHtml; @@ -120,7 +121,7 @@ public function getMiscellaneousHtml() */ public function getIdentities() { - return [\Magento\Store\Model\Store::CACHE_TAG, \Magento\Cms\Model\Block::CACHE_TAG]; + return [Store::CACHE_TAG, Block::CACHE_TAG]; } /** diff --git a/app/code/Magento/Theme/Block/Html/Header.php b/app/code/Magento/Theme/Block/Html/Header.php index 95c146253bae3..644b92d3f08ef 100644 --- a/app/code/Magento/Theme/Block/Html/Header.php +++ b/app/code/Magento/Theme/Block/Html/Header.php @@ -7,6 +7,9 @@ namespace Magento\Theme\Block\Html; use Magento\Framework\Escaper; +use Magento\Framework\View\Element\Template; +use Magento\Framework\View\Element\Template\Context; +use Magento\Store\Model\ScopeInterface; /** * Html page header block @@ -14,26 +17,20 @@ * @api * @since 100.0.2 */ -class Header extends \Magento\Framework\View\Element\Template +class Header extends Template { - /** - * @var Escaper - */ - private $escaper; - /** * Constructor * - * @param \Magento\Framework\View\Element\Template\Context $context - * @param Magento\Framework\Escaper $escaper + * @param Context $context + * @param Escaper $escaper * @param array $data */ public function __construct( - \Magento\Framework\View\Element\Template\Context $context, - \Magento\Framework\Escaper $escaper, + Context $context, + private readonly Escaper $escaper, array $data = [] ) { - $this->escaper = $escaper; parent::__construct($context, $data); } @@ -54,7 +51,7 @@ public function getWelcome() if (empty($this->_data['welcome'])) { $this->_data['welcome'] = $this->_scopeConfig->getValue( 'design/header/welcome', - \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ScopeInterface::SCOPE_STORE ); } return $this->escaper->escapeQuote(__($this->_data['welcome'])->render(), true); diff --git a/app/code/Magento/Theme/Block/Html/Header/CriticalCss.php b/app/code/Magento/Theme/Block/Html/Header/CriticalCss.php index 34c7c301ba85f..81a1aa6ba4cd5 100644 --- a/app/code/Magento/Theme/Block/Html/Header/CriticalCss.php +++ b/app/code/Magento/Theme/Block/Html/Header/CriticalCss.php @@ -18,26 +18,14 @@ */ class CriticalCss implements ArgumentInterface { - /** - * @var Repository - */ - private $assetRepo; - - /** - * @var $filePath - */ - private $filePath; - /** * @param Repository $assetRepo * @param string $filePath */ public function __construct( - Repository $assetRepo, - string $filePath = '' + private readonly Repository $assetRepo, + private readonly string $filePath = '' ) { - $this->assetRepo = $assetRepo; - $this->filePath = $filePath; } /** diff --git a/app/code/Magento/Theme/Block/Html/Header/Logo.php b/app/code/Magento/Theme/Block/Html/Header/Logo.php index 3c43e5bfc6fe1..cd3e4dcc3961a 100644 --- a/app/code/Magento/Theme/Block/Html/Header/Logo.php +++ b/app/code/Magento/Theme/Block/Html/Header/Logo.php @@ -6,6 +6,11 @@ namespace Magento\Theme\Block\Html\Header; +use Magento\Framework\UrlInterface; +use Magento\Framework\View\Element\Template; +use Magento\Framework\View\Element\Template\Context; +use Magento\MediaStorage\Helper\File\Storage\Database; +use Magento\Store\Model\ScopeInterface; use Magento\Theme\ViewModel\Block\Html\Header\LogoPathResolverInterface; /** @@ -14,7 +19,7 @@ * @api * @since 100.0.2 */ -class Logo extends \Magento\Framework\View\Element\Template +class Logo extends Template { /** * Current template name @@ -24,18 +29,18 @@ class Logo extends \Magento\Framework\View\Element\Template protected $_template = 'Magento_Theme::html/header/logo.phtml'; /** - * @var \Magento\MediaStorage\Helper\File\Storage\Database + * @var Database */ protected $_fileStorageHelper; /** - * @param \Magento\Framework\View\Element\Template\Context $context - * @param \Magento\MediaStorage\Helper\File\Storage\Database $fileStorageHelper + * @param Context $context + * @param Database $fileStorageHelper * @param array $data */ public function __construct( - \Magento\Framework\View\Element\Template\Context $context, - \Magento\MediaStorage\Helper\File\Storage\Database $fileStorageHelper, + Context $context, + Database $fileStorageHelper, array $data = [] ) { $this->_fileStorageHelper = $fileStorageHelper; @@ -81,7 +86,7 @@ public function getLogoAlt() if (empty($this->_data['logo_alt'])) { $this->_data['logo_alt'] = $this->_scopeConfig->getValue( 'design/header/logo_alt', - \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ScopeInterface::SCOPE_STORE ); } return $this->_data['logo_alt']; @@ -97,7 +102,7 @@ public function getLogoWidth() if (empty($this->_data['logo_width'])) { $this->_data['logo_width'] = $this->_scopeConfig->getValue( 'design/header/logo_width', - \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ScopeInterface::SCOPE_STORE ); } return (int)$this->_data['logo_width']; @@ -113,7 +118,7 @@ public function getLogoHeight() if (empty($this->_data['logo_height'])) { $this->_data['logo_height'] = $this->_scopeConfig->getValue( 'design/header/logo_height', - \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ScopeInterface::SCOPE_STORE ); } return (int)$this->_data['logo_height']; @@ -133,7 +138,7 @@ protected function _getLogoUrl() $path = $logoPathResolver->getPath(); } $logoUrl = $this->_urlBuilder - ->getBaseUrl(['_type' => \Magento\Framework\UrlInterface::URL_TYPE_MEDIA]) . $path; + ->getBaseUrl(['_type' => UrlInterface::URL_TYPE_MEDIA]) . $path; if ($path !== null && $this->_isFile($path)) { $url = $logoUrl; diff --git a/app/code/Magento/Theme/Block/Html/Notices.php b/app/code/Magento/Theme/Block/Html/Notices.php index 8a37033e734e4..dcf9f5505efba 100644 --- a/app/code/Magento/Theme/Block/Html/Notices.php +++ b/app/code/Magento/Theme/Block/Html/Notices.php @@ -5,19 +5,23 @@ */ namespace Magento\Theme\Block\Html; +use Magento\Framework\View\Element\Template; +use Magento\Framework\View\Element\Template\Context; +use Magento\Store\Model\ScopeInterface; + /** * Html page notices block * * @api * @since 100.0.2 */ -class Notices extends \Magento\Framework\View\Element\Template +class Notices extends Template { /** - * @param \Magento\Framework\View\Element\Template\Context $context + * @param Context $context * @param array $data */ - public function __construct(\Magento\Framework\View\Element\Template\Context $context, array $data = []) + public function __construct(Context $context, array $data = []) { parent::__construct($context, $data); } @@ -31,7 +35,7 @@ public function displayNoscriptNotice() { return $this->_scopeConfig->getValue( 'web/browser_capabilities/javascript', - \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ScopeInterface::SCOPE_STORE ); } @@ -44,7 +48,7 @@ public function displayNoLocalStorageNotice() { return $this->_scopeConfig->getValue( 'web/browser_capabilities/local_storage', - \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ScopeInterface::SCOPE_STORE ); } @@ -57,7 +61,7 @@ public function displayDemoNotice() { return $this->_scopeConfig->getValue( 'design/head/demonotice', - \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ScopeInterface::SCOPE_STORE ); } } diff --git a/app/code/Magento/Theme/Block/Html/Pager.php b/app/code/Magento/Theme/Block/Html/Pager.php index 764b2e9ca42f0..2ebf2b68a993a 100644 --- a/app/code/Magento/Theme/Block/Html/Pager.php +++ b/app/code/Magento/Theme/Block/Html/Pager.php @@ -6,6 +6,10 @@ namespace Magento\Theme\Block\Html; +use Magento\Framework\Data\Collection; +use Magento\Framework\View\Element\Template; +use Magento\Store\Model\ScopeInterface; + /** * Html pager block * @@ -13,7 +17,7 @@ * @api * @since 100.0.2 */ -class Pager extends \Magento\Framework\View\Element\Template +class Pager extends Template { /** * Current template name @@ -23,7 +27,7 @@ class Pager extends \Magento\Framework\View\Element\Template protected $_template = 'Magento_Theme::html/pager.phtml'; /** - * @var \Magento\Framework\Data\Collection + * @var Collection */ protected $_collection; @@ -168,7 +172,7 @@ public function setLimit($limit) /** * Set collection for pagination * - * @param \Magento\Framework\Data\Collection $collection + * @param Collection $collection * @return $this */ public function setCollection($collection) @@ -187,7 +191,7 @@ public function setCollection($collection) /** * Returns data collection * - * @return \Magento\Framework\Data\Collection + * @return Collection */ public function getCollection() { @@ -777,7 +781,7 @@ public function getAnchorTextForPrevious() { return $this->_scopeConfig->getValue( 'design/pagination/anchor_text_for_previous', - \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ScopeInterface::SCOPE_STORE ); } @@ -790,7 +794,7 @@ public function getAnchorTextForNext() { return $this->_scopeConfig->getValue( 'design/pagination/anchor_text_for_next', - \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ScopeInterface::SCOPE_STORE ); } diff --git a/app/code/Magento/Theme/Block/Html/Title.php b/app/code/Magento/Theme/Block/Html/Title.php index a2ef83117ccf5..88381f2d1053e 100644 --- a/app/code/Magento/Theme/Block/Html/Title.php +++ b/app/code/Magento/Theme/Block/Html/Title.php @@ -26,11 +26,6 @@ class Title extends Template */ private const XML_PATH_HEADER_TRANSLATE_TITLE = 'design/header/translate_title'; - /** - * @var ScopeConfigInterface - */ - private $scopeConfig; - /** * Own page title to display on the page * @@ -47,11 +42,10 @@ class Title extends Template */ public function __construct( Template\Context $context, - ScopeConfigInterface $scopeConfig, + private readonly ScopeConfigInterface $scopeConfig, array $data = [] ) { parent::__construct($context, $data); - $this->scopeConfig = $scopeConfig; } /** diff --git a/app/code/Magento/Theme/Block/Html/Topmenu.php b/app/code/Magento/Theme/Block/Html/Topmenu.php index f8460b43ba2ff..5c470f7e1e266 100644 --- a/app/code/Magento/Theme/Block/Html/Topmenu.php +++ b/app/code/Magento/Theme/Block/Html/Topmenu.php @@ -36,16 +36,6 @@ class Topmenu extends Template implements IdentityInterface */ protected $_menu; - /** - * @var NodeFactory - */ - private $nodeFactory; - - /** - * @var TreeFactory - */ - private $treeFactory; - /** * @param Template\Context $context * @param NodeFactory $nodeFactory @@ -54,13 +44,11 @@ class Topmenu extends Template implements IdentityInterface */ public function __construct( Template\Context $context, - NodeFactory $nodeFactory, - TreeFactory $treeFactory, + private readonly NodeFactory $nodeFactory, + private readonly TreeFactory $treeFactory, array $data = [] ) { parent::__construct($context, $data); - $this->nodeFactory = $nodeFactory; - $this->treeFactory = $treeFactory; } /** @@ -120,7 +108,7 @@ protected function _countItems($items) { $total = $items->count(); foreach ($items as $item) { - /** @var $item Menu\Item */ + /** @var Menu\Item $item */ if ($item->hasChildren()) { $total += $this->_countItems($item->getChildren()); } diff --git a/app/code/Magento/Theme/Console/Command/ThemeUninstallCommand.php b/app/code/Magento/Theme/Console/Command/ThemeUninstallCommand.php index 404e2f3c49c4f..443e68f45dcee 100644 --- a/app/code/Magento/Theme/Console/Command/ThemeUninstallCommand.php +++ b/app/code/Magento/Theme/Console/Command/ThemeUninstallCommand.php @@ -6,6 +6,7 @@ namespace Magento\Theme\Console\Command; +use Exception; use Magento\Framework\App\Cache; use Magento\Framework\App\Console\MaintenanceModeEnabler; use Magento\Framework\App\ObjectManager; @@ -13,6 +14,7 @@ use Magento\Framework\App\State\CleanupFiles; use Magento\Framework\Composer\ComposerInformation; use Magento\Framework\Composer\DependencyChecker; +use Magento\Framework\Console\Cli; use Magento\Theme\Model\Theme\Data\Collection; use Magento\Theme\Model\Theme\ThemePackageInfo; use Magento\Theme\Model\Theme\ThemeUninstaller; @@ -40,123 +42,38 @@ class ThemeUninstallCommand extends Command const INPUT_KEY_THEMES = 'theme'; const INPUT_KEY_CLEAR_STATIC_CONTENT = 'clear-static-content'; - /** - * Composer general dependency checker - * - * @var DependencyChecker - */ - private $dependencyChecker; - - /** - * Root composer.json information - * - * @var ComposerInformation - */ - private $composer; - - /** - * Theme collection in filesystem - * - * @var Collection - */ - private $themeCollection; - - /** - * System cache model - * - * @var Cache - */ - private $cache; - - /** - * Cleaning up application state service - * - * @var CleanupFiles - */ - private $cleanupFiles; - - /** - * BackupRollback factory - * - * @var BackupRollbackFactory - */ - private $backupRollbackFactory; - - /** - * Theme Validator - * - * @var ThemeValidator - */ - private $themeValidator; - - /** - * Package name finder - * - * @var ThemePackageInfo - */ - private $themePackageInfo; - - /** - * Theme Uninstaller - * - * @var ThemeUninstaller - */ - private $themeUninstaller; - - /** - * Theme Dependency Checker - * - * @var ThemeDependencyChecker - */ - private $themeDependencyChecker; - - /** - * @var MaintenanceModeEnabler - */ - private $maintenanceModeEnabler; - /** * Constructor * - * @param Cache $cache - * @param CleanupFiles $cleanupFiles - * @param ComposerInformation $composer + * @param Cache $cache System cache model + * @param CleanupFiles $cleanupFiles Cleaning up application state service + * @param ComposerInformation $composer Root composer.json information * @param MaintenanceMode $maintenanceMode deprecated, use $maintenanceModeEnabler instead - * @param DependencyChecker $dependencyChecker - * @param Collection $themeCollection - * @param BackupRollbackFactory $backupRollbackFactory - * @param ThemeValidator $themeValidator - * @param ThemePackageInfo $themePackageInfo - * @param ThemeUninstaller $themeUninstaller - * @param ThemeDependencyChecker $themeDependencyChecker + * @param DependencyChecker $dependencyChecker Composer general dependency checker + * @param Collection $themeCollection Theme collection in filesystem + * @param BackupRollbackFactory $backupRollbackFactory BackupRollback factory + * @param ThemeValidator $themeValidator Theme Validator + * @param ThemePackageInfo $themePackageInfo Package name finder + * @param ThemeUninstaller $themeUninstaller Theme Uninstaller + * @param ThemeDependencyChecker $themeDependencyChecker Theme Dependency Checker * @param MaintenanceModeEnabler $maintenanceModeEnabler * * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function __construct( - Cache $cache, - CleanupFiles $cleanupFiles, - ComposerInformation $composer, - MaintenanceMode $maintenanceMode, - DependencyChecker $dependencyChecker, - Collection $themeCollection, - BackupRollbackFactory $backupRollbackFactory, - ThemeValidator $themeValidator, - ThemePackageInfo $themePackageInfo, - ThemeUninstaller $themeUninstaller, - ThemeDependencyChecker $themeDependencyChecker, - MaintenanceModeEnabler $maintenanceModeEnabler = null + private readonly Cache $cache, + private readonly CleanupFiles $cleanupFiles, + private readonly ComposerInformation $composer, + private readonly MaintenanceMode $maintenanceMode, + private readonly DependencyChecker $dependencyChecker, + private readonly Collection $themeCollection, + private readonly BackupRollbackFactory $backupRollbackFactory, + private readonly ThemeValidator $themeValidator, + private readonly ThemePackageInfo $themePackageInfo, + private readonly ThemeUninstaller $themeUninstaller, + private readonly ThemeDependencyChecker $themeDependencyChecker, + private ?MaintenanceModeEnabler $maintenanceModeEnabler = null ) { - $this->cache = $cache; - $this->cleanupFiles = $cleanupFiles; - $this->composer = $composer; - $this->dependencyChecker = $dependencyChecker; - $this->themeCollection = $themeCollection; - $this->backupRollbackFactory = $backupRollbackFactory; - $this->themeValidator = $themeValidator; - $this->themePackageInfo = $themePackageInfo; - $this->themeUninstaller = $themeUninstaller; - $this->themeDependencyChecker = $themeDependencyChecker; $this->maintenanceModeEnabler = $maintenanceModeEnabler ?: ObjectManager::getInstance()->get(MaintenanceModeEnabler::class); parent::__construct(); @@ -201,7 +118,7 @@ protected function execute(InputInterface $input, OutputInterface $output) if (!empty($messages)) { $output->writeln($messages); // we must have an exit code higher than zero to indicate something was wrong - return \Magento\Framework\Console\Cli::RETURN_FAILURE; + return Cli::RETURN_FAILURE; } $messages = array_merge( $messages, @@ -215,7 +132,7 @@ protected function execute(InputInterface $input, OutputInterface $output) . PHP_EOL . implode(PHP_EOL, $messages) ); // we must have an exit code higher than zero to indicate something was wrong - return \Magento\Framework\Console\Cli::RETURN_FAILURE; + return Cli::RETURN_FAILURE; } $result = $this->maintenanceModeEnabler->executeInMaintenanceMode( @@ -231,12 +148,12 @@ function () use ($input, $output, $themePaths) { $this->themeUninstaller->uninstallCode($output, $themePaths); $this->cleanup($input, $output); - return \Magento\Framework\Console\Cli::RETURN_SUCCESS; - } catch (\Exception $e) { + return Cli::RETURN_SUCCESS; + } catch (Exception $e) { $output->writeln('' . $e->getMessage() . ''); $output->writeln('Please disable maintenance mode after you resolved above issues'); // we must have an exit code higher than zero to indicate something was wrong - return \Magento\Framework\Console\Cli::RETURN_FAILURE; + return Cli::RETURN_FAILURE; } }, $output, diff --git a/app/code/Magento/Theme/Controller/Adminhtml/Design/Config/Edit.php b/app/code/Magento/Theme/Controller/Adminhtml/Design/Config/Edit.php index 2b1eaf1fdea1e..a73fdf239a04c 100644 --- a/app/code/Magento/Theme/Controller/Adminhtml/Design/Config/Edit.php +++ b/app/code/Magento/Theme/Controller/Adminhtml/Design/Config/Edit.php @@ -19,21 +19,6 @@ */ class Edit extends Action { - /** - * @var ResultPageFactory - */ - protected $resultPageFactory; - - /** - * @var ScopeValidator - */ - protected $scopeValidator; - - /** - * @var ScopeResolverPool - */ - protected $scopeResolverPool; - /** * @param Context $context * @param ResultPageFactory $resultPageFactory @@ -42,13 +27,10 @@ class Edit extends Action */ public function __construct( Context $context, - ResultPageFactory $resultPageFactory, - ScopeValidator $scopeValidator, - ScopeResolverPool $scopeResolverPool + protected readonly ResultPageFactory $resultPageFactory, + protected readonly ScopeValidator $scopeValidator, + protected readonly ScopeResolverPool $scopeResolverPool ) { - $this->resultPageFactory = $resultPageFactory; - $this->scopeValidator = $scopeValidator; - $this->scopeResolverPool = $scopeResolverPool; parent::__construct($context); } diff --git a/app/code/Magento/Theme/Controller/Adminhtml/Design/Config/FileUploader/Save.php b/app/code/Magento/Theme/Controller/Adminhtml/Design/Config/FileUploader/Save.php index baa9b6131d15e..38b0289db5e37 100644 --- a/app/code/Magento/Theme/Controller/Adminhtml/Design/Config/FileUploader/Save.php +++ b/app/code/Magento/Theme/Controller/Adminhtml/Design/Config/FileUploader/Save.php @@ -18,12 +18,6 @@ */ class Save extends Action { - /** - * @var FileProcessor - * @since 100.1.0 - */ - protected $fileProcessor; - /** * Authorization level */ @@ -35,10 +29,9 @@ class Save extends Action */ public function __construct( Context $context, - FileProcessor $fileProcessor + protected readonly FileProcessor $fileProcessor ) { parent::__construct($context); - $this->fileProcessor = $fileProcessor; } /** diff --git a/app/code/Magento/Theme/Controller/Adminhtml/Design/Config/Index.php b/app/code/Magento/Theme/Controller/Adminhtml/Design/Config/Index.php index 3c9191db70ba6..5e7c7cd166766 100644 --- a/app/code/Magento/Theme/Controller/Adminhtml/Design/Config/Index.php +++ b/app/code/Magento/Theme/Controller/Adminhtml/Design/Config/Index.php @@ -7,6 +7,7 @@ use Magento\Backend\App\Action; use Magento\Backend\App\Action\Context; +use Magento\Backend\Model\View\Result\Page as ResultPage; use Magento\Framework\View\Result\PageFactory; /** @@ -14,31 +15,25 @@ */ class Index extends Action { - /** - * @var PageFactory - */ - protected $resultPageFactory; - /** * @param Context $context * @param PageFactory $resultPageFactory */ public function __construct( Context $context, - PageFactory $resultPageFactory + protected readonly PageFactory $resultPageFactory ) { parent::__construct($context); - $this->resultPageFactory = $resultPageFactory; } /** * Design config list action * - * @return \Magento\Backend\Model\View\Result\Page + * @return ResultPage */ public function execute() { - /** @var \Magento\Backend\Model\View\Result\Page $resultPage */ + /** @var ResultPage $resultPage */ $resultPage = $this->resultPageFactory->create(); $resultPage->setActiveMenu('Magento_Theme::design_config'); $resultPage->getConfig()->getTitle()->prepend(__('Design Configuration')); diff --git a/app/code/Magento/Theme/Controller/Adminhtml/Design/Config/Save.php b/app/code/Magento/Theme/Controller/Adminhtml/Design/Config/Save.php index 4f7a1cd47af58..c68e10a84b558 100644 --- a/app/code/Magento/Theme/Controller/Adminhtml/Design/Config/Save.php +++ b/app/code/Magento/Theme/Controller/Adminhtml/Design/Config/Save.php @@ -5,8 +5,10 @@ */ namespace Magento\Theme\Controller\Adminhtml\Design\Config; +use Exception; use Magento\Backend\App\Action; use Magento\Framework\App\Request\DataPersistorInterface; +use Magento\Framework\Controller\Result\Redirect as ResultRedirect; use Magento\Framework\Exception\NotFoundException; use Magento\Theme\Model\DesignConfigRepository; use Magento\Backend\App\Action\Context; @@ -18,21 +20,6 @@ */ class Save extends Action { - /** - * @var DesignConfigRepository - */ - protected $designConfigRepository; - - /** - * @var ConfigFactory - */ - protected $configFactory; - - /** - * @var DataPersistorInterface - */ - protected $dataPersistor; - /** * @param Context $context * @param DesignConfigRepository $designConfigRepository @@ -41,13 +28,10 @@ class Save extends Action */ public function __construct( Context $context, - DesignConfigRepository $designConfigRepository, - ConfigFactory $configFactory, - DataPersistorInterface $dataPersistor + protected readonly DesignConfigRepository $designConfigRepository, + protected readonly ConfigFactory $configFactory, + protected readonly DataPersistorInterface $dataPersistor ) { - $this->designConfigRepository = $designConfigRepository; - $this->configFactory = $configFactory; - $this->dataPersistor = $dataPersistor; parent::__construct($context); } @@ -62,7 +46,7 @@ protected function _isAllowed() } /** - * @return \Magento\Framework\Controller\Result\Redirect + * @return ResultRedirect * * @throws NotFoundException */ @@ -95,7 +79,7 @@ public function execute() foreach ($messages as $message) { $this->messageManager->addErrorMessage(__('%1', $message)); } - } catch (\Exception $e) { + } catch (Exception $e) { $this->messageManager->addExceptionMessage( $e, __('Something went wrong while saving this configuration:') . ' ' . $e->getMessage() diff --git a/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme.php b/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme.php index f0cd2872c0488..ae1cf6b36d3f9 100644 --- a/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme.php +++ b/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme.php @@ -9,7 +9,14 @@ */ namespace Magento\Theme\Controller\Adminhtml\System\Design; -abstract class Theme extends \Magento\Backend\App\Action +use Magento\Backend\App\Action; +use Magento\Backend\App\Action\Context; +use Magento\Framework\App\Response\Http\FileFactory as ResponseHttpFileFactory; +use Magento\Framework\Filesystem; +use Magento\Framework\Registry; +use Magento\Framework\View\Asset\Repository as AssetRepository; + +abstract class Theme extends Action { /** * Authorization level of a basic admin session @@ -21,38 +28,38 @@ abstract class Theme extends \Magento\Backend\App\Action /** * Core registry * - * @var \Magento\Framework\Registry + * @var Registry */ protected $_coreRegistry = null; /** - * @var \Magento\Framework\App\Response\Http\FileFactory + * @var ResponseHttpFileFactory */ protected $_fileFactory; /** - * @var \Magento\Framework\View\Asset\Repository + * @var AssetRepository */ protected $_assetRepo; /** - * @var \Magento\Framework\Filesystem + * @var Filesystem */ protected $_appFileSystem; /** - * @param \Magento\Backend\App\Action\Context $context - * @param \Magento\Framework\Registry $coreRegistry - * @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory - * @param \Magento\Framework\View\Asset\Repository $assetRepo - * @param \Magento\Framework\Filesystem $appFileSystem + * @param Context $context + * @param Registry $coreRegistry + * @param ResponseHttpFileFactory $fileFactory + * @param AssetRepository $assetRepo + * @param Filesystem $appFileSystem */ public function __construct( - \Magento\Backend\App\Action\Context $context, - \Magento\Framework\Registry $coreRegistry, - \Magento\Framework\App\Response\Http\FileFactory $fileFactory, - \Magento\Framework\View\Asset\Repository $assetRepo, - \Magento\Framework\Filesystem $appFileSystem + Context $context, + Registry $coreRegistry, + ResponseHttpFileFactory $fileFactory, + AssetRepository $assetRepo, + Filesystem $appFileSystem ) { $this->_coreRegistry = $coreRegistry; $this->_fileFactory = $fileFactory; diff --git a/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme/Delete.php b/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme/Delete.php index 04e52a2e2a7eb..8d0b8010a1268 100644 --- a/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme/Delete.php +++ b/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme/Delete.php @@ -6,9 +6,15 @@ namespace Magento\Theme\Controller\Adminhtml\System\Design\Theme; +use Exception; +use InvalidArgumentException; +use Magento\Backend\Model\View\Result\Redirect; use Magento\Framework\App\Action\HttpGetActionInterface; use Magento\Framework\Controller\ResultFactory; +use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\View\Design\ThemeInterface; use Magento\Theme\Controller\Adminhtml\System\Design\Theme; +use Psr\Log\LoggerInterface; /** * The admin area controller to delete theme. @@ -20,36 +26,36 @@ class Delete extends Theme implements HttpGetActionInterface /** * Delete action * - * @return \Magento\Backend\Model\View\Result\Redirect + * @return Redirect */ public function execute() { $themeId = $this->getRequest()->getParam('id'); try { if ($themeId) { - /** @var $theme \Magento\Framework\View\Design\ThemeInterface */ + /** @var ThemeInterface $theme */ $theme = $this->_objectManager->create( - \Magento\Framework\View\Design\ThemeInterface::class + ThemeInterface::class )->load($themeId); if (!$theme->getId()) { - throw new \InvalidArgumentException(__( + throw new InvalidArgumentException(__( 'We cannot find a theme with id "%1".', $themeId )->render()); } if (!$theme->isVirtual()) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( sprintf('Only virtual theme is possible to delete and theme "%s" isn\'t virtual', $themeId) ); } $theme->delete(); $this->messageManager->addSuccess(__('You deleted the theme.')); } - } catch (\Magento\Framework\Exception\LocalizedException $e) { + } catch (LocalizedException $e) { $this->messageManager->addError($e->getMessage()); - } catch (\Exception $e) { + } catch (Exception $e) { $this->messageManager->addException($e, __('We cannot delete the theme.')); - $this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e); + $this->_objectManager->get(LoggerInterface::class)->critical($e); } $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); return $resultRedirect->setPath('adminhtml/*/'); diff --git a/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme/DownloadCss.php b/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme/DownloadCss.php index fd8b2f91e164f..a3b3278f94676 100644 --- a/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme/DownloadCss.php +++ b/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme/DownloadCss.php @@ -6,6 +6,8 @@ */ namespace Magento\Theme\Controller\Adminhtml\System\Design\Theme; +use Exception; +use InvalidArgumentException; use Magento\Backend\App\Action\Context; use Magento\Framework\App\Action\HttpGetActionInterface; use Magento\Framework\App\Response\Http\FileFactory; @@ -28,11 +30,6 @@ */ class DownloadCss extends Theme implements HttpGetActionInterface { - /** - * @var Escaper - */ - private $escaper; - /** * DownloadCss constructor. * @param Context $context @@ -48,7 +45,7 @@ public function __construct( FileFactory $fileFactory, Repository $assetRepo, Filesystem $appFileSystem, - Escaper $escaper = null + private ?Escaper $escaper = null ) { $this->escaper = $escaper ?? $context->getObjectManager()->get(Escaper::class); parent::__construct($context, $coreRegistry, $fileFactory, $assetRepo, $appFileSystem); @@ -64,14 +61,14 @@ public function execute() $themeId = $this->getRequest()->getParam('theme_id'); $file = $this->getRequest()->getParam('file'); - /** @var $urlDecoder DecoderInterface */ + /** @var DecoderInterface $urlDecoder */ $urlDecoder = $this->_objectManager->get(DecoderInterface::class); $fileId = $urlDecoder->decode($file); try { - /** @var $theme ThemeInterface */ + /** @var ThemeInterface $theme */ $theme = $this->_objectManager->create(ThemeInterface::class)->load($themeId); if (!$theme->getId()) { - throw new \InvalidArgumentException(sprintf('Theme not found: "%d".', $themeId)); + throw new InvalidArgumentException(sprintf('Theme not found: "%d".', $themeId)); } $asset = $this->_assetRepo->createAsset($fileId, ['themeModel' => $theme]); $relPath = $this->_appFileSystem->getDirectoryRead(DirectoryList::ROOT) @@ -85,11 +82,11 @@ public function execute() ], DirectoryList::ROOT ); - } catch (\InvalidArgumentException $e) { + } catch (InvalidArgumentException $e) { $this->messageManager->addException($e, __('Theme not found: "%1".', $this->escaper->escapeHtml($themeId))); $this->getResponse()->setRedirect($this->_redirect->getRefererUrl()); $this->_objectManager->get(LoggerInterface::class)->critical($e); - } catch (\Exception $e) { + } catch (Exception $e) { $this->messageManager->addException($e, __('File not found: "%1".', $this->escaper->escapeHtml($fileId))); $this->getResponse()->setRedirect($this->_redirect->getRefererUrl()); $this->_objectManager->get(LoggerInterface::class)->critical($e); diff --git a/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme/DownloadCustomCss.php b/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme/DownloadCustomCss.php index 9bee1b78b636e..9145fe3f01494 100644 --- a/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme/DownloadCustomCss.php +++ b/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme/DownloadCustomCss.php @@ -6,11 +6,17 @@ namespace Magento\Theme\Controller\Adminhtml\System\Design\Theme; +use Exception; +use InvalidArgumentException; use Magento\Framework\App\Action\HttpGetActionInterface; use Magento\Framework\App\Action\HttpPostActionInterface; use Magento\Framework\App\ResponseInterface; use Magento\Framework\App\Filesystem\DirectoryList; +use Magento\Framework\View\Design\Theme\FileInterface; +use Magento\Framework\View\Design\Theme\FlyweightFactory; use Magento\Theme\Controller\Adminhtml\System\Design\Theme; +use Magento\Theme\Model\Theme\Customization\File\CustomCss; +use Psr\Log\LoggerInterface; /** * The admin area controller to download custom css. @@ -28,20 +34,20 @@ public function execute() { $themeId = $this->getRequest()->getParam('theme_id'); try { - /** @var $themeFactory \Magento\Framework\View\Design\Theme\FlyweightFactory */ - $themeFactory = $this->_objectManager->create(\Magento\Framework\View\Design\Theme\FlyweightFactory::class); + /** @var FlyweightFactory $themeFactory */ + $themeFactory = $this->_objectManager->create(FlyweightFactory::class); $theme = $themeFactory->create($themeId); if ($theme === null || !$theme->getId()) { - throw new \InvalidArgumentException(__( + throw new InvalidArgumentException(__( 'We cannot find a theme with id "%1".', $themeId )->render()); } $customCssFiles = $theme->getCustomization()->getFilesByType( - \Magento\Theme\Model\Theme\Customization\File\CustomCss::TYPE + CustomCss::TYPE ); - /** @var $customCssFile \Magento\Framework\View\Design\Theme\FileInterface */ + /** @var FileInterface $customCssFile */ $customCssFile = reset($customCssFiles); if ($customCssFile && $customCssFile->getContent()) { return $this->_fileFactory->create( @@ -50,13 +56,13 @@ public function execute() DirectoryList::ROOT ); } - } catch (\Exception $e) { + } catch (Exception $e) { $this->messageManager->addExceptionMessage( $e, __('We can\'t find file.')->render() ); $this->getResponse()->setRedirect($this->_redirect->getRefererUrl()); - $this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e); + $this->_objectManager->get(LoggerInterface::class)->critical($e); } } } diff --git a/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme/Edit.php b/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme/Edit.php index 6f8381c2b5b15..c677f32c706eb 100644 --- a/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme/Edit.php +++ b/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme/Edit.php @@ -6,11 +6,19 @@ */ namespace Magento\Theme\Controller\Adminhtml\System\Design\Theme; +use Exception; +use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\View\Design\ThemeInterface; +use Magento\Theme\Block\Adminhtml\System\Design\Theme\Edit\Tab\Css; +use Magento\Theme\Controller\Adminhtml\System\Design\Theme; +use Magento\Theme\Helper\Theme as ThemeHelper; +use Psr\Log\LoggerInterface; + /** * Class Edit * @deprecated 100.2.0 */ -class Edit extends \Magento\Theme\Controller\Adminhtml\System\Design\Theme +class Edit extends Theme { /** * Edit theme @@ -20,32 +28,32 @@ class Edit extends \Magento\Theme\Controller\Adminhtml\System\Design\Theme public function execute() { $themeId = (int)$this->getRequest()->getParam('id'); - /** @var $theme \Magento\Framework\View\Design\ThemeInterface */ - $theme = $this->_objectManager->create(\Magento\Framework\View\Design\ThemeInterface::class); + /** @var ThemeInterface $theme */ + $theme = $this->_objectManager->create(ThemeInterface::class); try { - $theme->setType(\Magento\Framework\View\Design\ThemeInterface::TYPE_VIRTUAL); + $theme->setType(ThemeInterface::TYPE_VIRTUAL); if ($themeId && (!$theme->load($themeId)->getId() || !$theme->isVisible())) { - throw new \Magento\Framework\Exception\LocalizedException(__('We cannot find theme "%1".', $themeId)); + throw new LocalizedException(__('We cannot find theme "%1".', $themeId)); } $this->_coreRegistry->register('current_theme', $theme); $this->_view->loadLayout(); - /** @var $tab \Magento\Theme\Block\Adminhtml\System\Design\Theme\Edit\Tab\Css */ + /** @var Css $tab */ $tab = $this->_view->getLayout()->getBlock('theme_edit_tabs_tab_css_tab'); if ($tab && $tab->canShowTab()) { - /** @var $helper \Magento\Theme\Helper\Theme */ - $helper = $this->_objectManager->get(\Magento\Theme\Helper\Theme::class); + /** @var ThemeHelper $helper */ + $helper = $this->_objectManager->get(ThemeHelper::class); $files = $helper->getCssAssets($theme); $tab->setFiles($files); } $this->_setActiveMenu('Magento_Theme::system_design_theme'); $this->_view->renderLayout(); - } catch (\Magento\Framework\Exception\LocalizedException $e) { + } catch (LocalizedException $e) { $this->messageManager->addError($e->getMessage()); $this->_redirect('adminhtml/*/'); - } catch (\Exception $e) { + } catch (Exception $e) { $this->messageManager->addError(__('We cannot find the theme.')); - $this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e); + $this->_objectManager->get(LoggerInterface::class)->critical($e); $this->_redirect('adminhtml/*/'); } } diff --git a/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme/Grid.php b/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme/Grid.php index eb963708269d7..38b62337ec12e 100644 --- a/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme/Grid.php +++ b/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme/Grid.php @@ -6,11 +6,13 @@ */ namespace Magento\Theme\Controller\Adminhtml\System\Design\Theme; +use Magento\Theme\Controller\Adminhtml\System\Design\Theme; + /** * Class Grid * @deprecated 100.2.0 */ -class Grid extends \Magento\Theme\Controller\Adminhtml\System\Design\Theme +class Grid extends Theme { /** * Grid ajax action diff --git a/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme/Index.php b/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme/Index.php index 1a136cca4d62a..6d8c35c7ec751 100644 --- a/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme/Index.php +++ b/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme/Index.php @@ -7,12 +7,13 @@ namespace Magento\Theme\Controller\Adminhtml\System\Design\Theme; use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; +use Magento\Theme\Controller\Adminhtml\System\Design\Theme; /** * Class Index * @deprecated 100.2.0 */ -class Index extends \Magento\Theme\Controller\Adminhtml\System\Design\Theme implements HttpGetActionInterface +class Index extends Theme implements HttpGetActionInterface { /** * Index action diff --git a/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme/NewAction.php b/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme/NewAction.php index 8c046321eaeec..3e4e6d98088af 100644 --- a/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme/NewAction.php +++ b/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme/NewAction.php @@ -6,11 +6,13 @@ */ namespace Magento\Theme\Controller\Adminhtml\System\Design\Theme; +use Magento\Theme\Controller\Adminhtml\System\Design\Theme; + /** * Class NewAction * @deprecated 100.2.0 */ -class NewAction extends \Magento\Theme\Controller\Adminhtml\System\Design\Theme +class NewAction extends Theme { /** * Create new theme diff --git a/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme/Save.php b/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme/Save.php index 878768cadab88..7b23b3727c49a 100644 --- a/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme/Save.php +++ b/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme/Save.php @@ -6,12 +6,23 @@ */ namespace Magento\Theme\Controller\Adminhtml\System\Design\Theme; +use Exception; +use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\View\Design\Theme\Customization\File\Js; +use Magento\Framework\View\Design\Theme\FlyweightFactory; +use Magento\Framework\View\Design\ThemeInterface; +use Magento\Theme\Controller\Adminhtml\System\Design\Theme; +use Magento\Theme\Model\Theme as ModelTheme; +use Magento\Theme\Model\Theme\Customization\File\CustomCss; +use Magento\Theme\Model\Theme\SingleFile; +use Psr\Log\LoggerInterface; + /** * Class Save use to save Theme data * @SuppressWarnings(PHPMD.AllPurposeAction) * @deprecated 100.2.0 */ -class Save extends \Magento\Theme\Controller\Adminhtml\System\Design\Theme +class Save extends Theme { /** * Save action @@ -27,30 +38,30 @@ public function execute() $removeJsFiles = (array)$this->getRequest()->getParam('js_removed_files'); $reorderJsFiles = array_keys($this->getRequest()->getParam('js_order', [])); - /** @var $themeFactory \Magento\Framework\View\Design\Theme\FlyweightFactory */ - $themeFactory = $this->_objectManager->get(\Magento\Framework\View\Design\Theme\FlyweightFactory::class); - /** @var $cssService \Magento\Theme\Model\Theme\Customization\File\CustomCss */ - $cssService = $this->_objectManager->get(\Magento\Theme\Model\Theme\Customization\File\CustomCss::class); - /** @var $singleFile \Magento\Theme\Model\Theme\SingleFile */ + /** @var FlyweightFactory $themeFactory */ + $themeFactory = $this->_objectManager->get(FlyweightFactory::class); + /** @var CustomCss $cssService */ + $cssService = $this->_objectManager->get(CustomCss::class); + /** @var SingleFile $singleFile */ $singleFile = $this->_objectManager->create( - \Magento\Theme\Model\Theme\SingleFile::class, + SingleFile::class, ['fileService' => $cssService] ); try { if ($this->getRequest()->getPostValue()) { - /** @var $theme \Magento\Theme\Model\Theme */ + /** @var ModelTheme $theme */ if (!empty($themeData['theme_id'])) { $theme = $themeFactory->create($themeData['theme_id']); } else { $parentTheme = $themeFactory->create($themeData['parent_id']); $theme = $parentTheme->getDomainModel( - \Magento\Framework\View\Design\ThemeInterface::TYPE_PHYSICAL + ThemeInterface::TYPE_PHYSICAL )->createVirtualTheme( $parentTheme ); } if ($theme && !$theme->isEditable()) { - throw new \Magento\Framework\Exception\LocalizedException(__('This theme is not editable.')); + throw new LocalizedException(__('This theme is not editable.')); } $theme->addData( $this->extractMutableData($themeData) @@ -59,25 +70,25 @@ public function execute() $theme->getThemeImage()->removePreviewImage(); } $theme->getThemeImage()->uploadPreviewImage('preview'); - $theme->setType(\Magento\Framework\View\Design\ThemeInterface::TYPE_VIRTUAL); + $theme->setType(ThemeInterface::TYPE_VIRTUAL); $theme->save(); $customization = $theme->getCustomization(); $customization->reorder( - \Magento\Framework\View\Design\Theme\Customization\File\Js::TYPE, + Js::TYPE, $reorderJsFiles ); $customization->delete($removeJsFiles); $singleFile->update($theme, $customCssData); $this->messageManager->addSuccess(__('You saved the theme.')); } - } catch (\Magento\Framework\Exception\LocalizedException $e) { + } catch (LocalizedException $e) { $this->messageManager->addError($e->getMessage()); $this->_getSession()->setThemeData($themeData); $this->_getSession()->setThemeCustomCssData($customCssData); $redirectBack = true; - } catch (\Exception $e) { + } catch (Exception $e) { $this->messageManager->addError('The theme was not saved'); - $this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e); + $this->_objectManager->get(LoggerInterface::class)->critical($e); } $redirectBack //phpstan:ignore diff --git a/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme/UploadCss.php b/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme/UploadCss.php index 3519ff955ed73..8516d56c7013b 100644 --- a/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme/UploadCss.php +++ b/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme/UploadCss.php @@ -6,11 +6,18 @@ */ namespace Magento\Theme\Controller\Adminhtml\System\Design\Theme; +use Exception; +use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Json\Helper\Data as JsonHelper; +use Magento\Theme\Controller\Adminhtml\System\Design\Theme; +use Magento\Theme\Model\Uploader\Service; +use Psr\Log\LoggerInterface; + /** * Class UploadCss * @deprecated 100.2.0 */ -class UploadCss extends \Magento\Theme\Controller\Adminhtml\System\Design\Theme +class UploadCss extends Theme { /** * Upload css file @@ -19,19 +26,19 @@ class UploadCss extends \Magento\Theme\Controller\Adminhtml\System\Design\Theme */ public function execute() { - /** @var $serviceModel \Magento\Theme\Model\Uploader\Service */ - $serviceModel = $this->_objectManager->get(\Magento\Theme\Model\Uploader\Service::class); + /** @var Service $serviceModel */ + $serviceModel = $this->_objectManager->get(Service::class); try { $cssFileContent = $serviceModel->uploadCssFile('css_file_uploader'); $result = ['error' => false, 'content' => $cssFileContent['content']]; - } catch (\Magento\Framework\Exception\LocalizedException $e) { + } catch (LocalizedException $e) { $result = ['error' => true, 'message' => $e->getMessage()]; - } catch (\Exception $e) { + } catch (Exception $e) { $result = ['error' => true, 'message' => __('We can\'t upload the CSS file right now.')]; - $this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e); + $this->_objectManager->get(LoggerInterface::class)->critical($e); } $this->getResponse()->representJson( - $this->_objectManager->get(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($result) + $this->_objectManager->get(JsonHelper::class)->jsonEncode($result) ); } } diff --git a/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme/UploadJs.php b/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme/UploadJs.php index fb2ceb0a91fc9..1c3a3e13174c5 100644 --- a/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme/UploadJs.php +++ b/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme/UploadJs.php @@ -7,13 +7,23 @@ namespace Magento\Theme\Controller\Adminhtml\System\Design\Theme; +use Exception; use Magento\Framework\App\Action\HttpGetActionInterface; +use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Json\Helper\Data as JsonHelper; +use Magento\Framework\View\Design\Theme\Customization; +use Magento\Framework\View\Design\Theme\Customization\File\Js as CustomizationFileJs; +use Magento\Framework\View\Design\Theme\CustomizationInterface; +use Magento\Framework\View\Design\Theme\FlyweightFactory; +use Magento\Theme\Controller\Adminhtml\System\Design\Theme; +use Magento\Theme\Model\Uploader\Service; +use Psr\Log\LoggerInterface; /** * Class UploadJs * @deprecated 101.0.0 */ -class UploadJs extends \Magento\Theme\Controller\Adminhtml\System\Design\Theme implements HttpGetActionInterface +class UploadJs extends Theme implements HttpGetActionInterface { /** * Upload js file @@ -23,16 +33,16 @@ class UploadJs extends \Magento\Theme\Controller\Adminhtml\System\Design\Theme i public function execute() { $themeId = $this->getRequest()->getParam('id'); - /** @var $serviceModel \Magento\Theme\Model\Uploader\Service */ - $serviceModel = $this->_objectManager->get(\Magento\Theme\Model\Uploader\Service::class); - /** @var $themeFactory \Magento\Framework\View\Design\Theme\FlyweightFactory */ - $themeFactory = $this->_objectManager->get(\Magento\Framework\View\Design\Theme\FlyweightFactory::class); - /** @var $jsService \Magento\Framework\View\Design\Theme\Customization\File\Js */ - $jsService = $this->_objectManager->get(\Magento\Framework\View\Design\Theme\Customization\File\Js::class); + /** @var Service $serviceModel */ + $serviceModel = $this->_objectManager->get(Service::class); + /** @var FlyweightFactory $themeFactory */ + $themeFactory = $this->_objectManager->get(FlyweightFactory::class); + /** @var CustomizationFileJs $jsService */ + $jsService = $this->_objectManager->get(CustomizationFileJs::class); try { $theme = $themeFactory->create($themeId); if (!$theme) { - throw new \Magento\Framework\Exception\LocalizedException( + throw new LocalizedException( __('We cannot find a theme with id "%1".', $themeId) ); } @@ -43,23 +53,23 @@ public function execute() $jsFile->setData('content', $jsFileData['content']); $jsFile->save(); - /** @var $customization \Magento\Framework\View\Design\Theme\Customization */ + /** @var Customization $customization */ $customization = $this->_objectManager->create( - \Magento\Framework\View\Design\Theme\CustomizationInterface::class, + CustomizationInterface::class, ['theme' => $theme] ); $customJsFiles = $customization->getFilesByType( - \Magento\Framework\View\Design\Theme\Customization\File\Js::TYPE + CustomizationFileJs::TYPE ); $result = ['error' => false, 'files' => $customization->generateFileInfo($customJsFiles)]; - } catch (\Magento\Framework\Exception\LocalizedException $e) { + } catch (LocalizedException $e) { $result = ['error' => true, 'message' => $e->getMessage()]; - } catch (\Exception $e) { + } catch (Exception $e) { $result = ['error' => true, 'message' => __('We can\'t upload the JS file right now.')]; - $this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e); + $this->_objectManager->get(LoggerInterface::class)->critical($e); } $this->getResponse()->representJson( - $this->_objectManager->get(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($result) + $this->_objectManager->get(JsonHelper::class)->jsonEncode($result) ); } } diff --git a/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Wysiwyg/Files.php b/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Wysiwyg/Files.php index 394ddd5eb5aac..677a7c9eed9db 100644 --- a/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Wysiwyg/Files.php +++ b/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Wysiwyg/Files.php @@ -9,7 +9,13 @@ */ namespace Magento\Theme\Controller\Adminhtml\System\Design\Wysiwyg; -abstract class Files extends \Magento\Backend\App\Action +use Magento\Backend\App\Action; +use Magento\Backend\App\Action\Context; +use Magento\Framework\App\Response\Http\FileFactory; +use Magento\Theme\Helper\Storage as ThemeStorageHelper; +use Magento\Theme\Model\Wysiwyg\Storage; + +abstract class Files extends Action { /** * Authorization level of a basic admin session @@ -19,37 +25,31 @@ abstract class Files extends \Magento\Backend\App\Action const ADMIN_RESOURCE = 'Magento_Theme::theme'; /** - * @var \Magento\Framework\App\Response\Http\FileFactory + * @var FileFactory */ protected $_fileFactory; /** - * @var \Magento\Theme\Helper\Storage - */ - protected $storage; - - /** - * @param \Magento\Backend\App\Action\Context $context - * @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory - * @param \Magento\Theme\Helper\Storage $storage + * @param Context $context + * @param FileFactory $fileFactory + * @param ThemeStorageHelper $storage */ public function __construct( - \Magento\Backend\App\Action\Context $context, - \Magento\Framework\App\Response\Http\FileFactory $fileFactory, - \Magento\Theme\Helper\Storage $storage + Context $context, + FileFactory $fileFactory, + protected readonly ThemeStorageHelper $storage ) { $this->_fileFactory = $fileFactory; - $this->storage = $storage; parent::__construct($context); } /** * Get storage * - * @return \Magento\Theme\Model\Wysiwyg\Storage + * @return Storage */ protected function _getStorage() { - return $this->_objectManager->get(\Magento\Theme\Model\Wysiwyg\Storage::class); + return $this->_objectManager->get(Storage::class); } } diff --git a/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Wysiwyg/Files/Contents.php b/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Wysiwyg/Files/Contents.php index 0c87537978830..1ce29a10eb926 100644 --- a/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Wysiwyg/Files/Contents.php +++ b/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Wysiwyg/Files/Contents.php @@ -6,7 +6,11 @@ */ namespace Magento\Theme\Controller\Adminhtml\System\Design\Wysiwyg\Files; -class Contents extends \Magento\Theme\Controller\Adminhtml\System\Design\Wysiwyg\Files +use Exception; +use Magento\Framework\Json\Helper\Data as JsonHelper; +use Magento\Theme\Controller\Adminhtml\System\Design\Wysiwyg\Files; + +class Contents extends Files { /** * Contents action @@ -21,10 +25,10 @@ public function execute() $this->_view->renderLayout(); $this->_getSession()->setStoragePath($this->storage->getCurrentPath()); - } catch (\Exception $e) { + } catch (Exception $e) { $result = ['error' => true, 'message' => $e->getMessage()]; $this->getResponse()->representJson( - $this->_objectManager->get(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($result) + $this->_objectManager->get(JsonHelper::class)->jsonEncode($result) ); } } diff --git a/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Wysiwyg/Files/DeleteFiles.php b/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Wysiwyg/Files/DeleteFiles.php index 0012e80e04044..26cf42eb490ff 100644 --- a/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Wysiwyg/Files/DeleteFiles.php +++ b/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Wysiwyg/Files/DeleteFiles.php @@ -6,32 +6,36 @@ */ namespace Magento\Theme\Controller\Adminhtml\System\Design\Wysiwyg\Files; -class DeleteFiles extends \Magento\Theme\Controller\Adminhtml\System\Design\Wysiwyg\Files +use Exception; +use Magento\Framework\Json\Helper\Data as JsonHelper; +use Magento\Theme\Controller\Adminhtml\System\Design\Wysiwyg\Files; + +class DeleteFiles extends Files { /** * Delete file from media storage * * @return void - * @throws \Exception + * @throws Exception */ public function execute() { try { if (!$this->getRequest()->isPost()) { - throw new \Exception('Wrong request'); + throw new Exception('Wrong request'); } $files = $this->_objectManager->get( - \Magento\Framework\Json\Helper\Data::class + JsonHelper::class )->jsonDecode( $this->getRequest()->getParam('files') ); foreach ($files as $file) { $this->_getStorage()->deleteFile($file); } - } catch (\Exception $e) { + } catch (Exception $e) { $result = ['error' => true, 'message' => $e->getMessage()]; $this->getResponse()->representJson( - $this->_objectManager->get(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($result) + $this->_objectManager->get(JsonHelper::class)->jsonEncode($result) ); } } diff --git a/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Wysiwyg/Files/DeleteFolder.php b/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Wysiwyg/Files/DeleteFolder.php index 03377d63fc707..8fe014825dead 100644 --- a/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Wysiwyg/Files/DeleteFolder.php +++ b/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Wysiwyg/Files/DeleteFolder.php @@ -6,7 +6,11 @@ */ namespace Magento\Theme\Controller\Adminhtml\System\Design\Wysiwyg\Files; -class DeleteFolder extends \Magento\Theme\Controller\Adminhtml\System\Design\Wysiwyg\Files +use Exception; +use Magento\Framework\Json\Helper\Data as JsonHelper; +use Magento\Theme\Controller\Adminhtml\System\Design\Wysiwyg\Files; + +class DeleteFolder extends Files { /** * Delete folder action @@ -18,10 +22,10 @@ public function execute() try { $path = $this->storage->getCurrentPath(); $this->_getStorage()->deleteDirectory($path); - } catch (\Exception $e) { + } catch (Exception $e) { $result = ['error' => true, 'message' => $e->getMessage()]; $this->getResponse()->representJson( - $this->_objectManager->get(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($result) + $this->_objectManager->get(JsonHelper::class)->jsonEncode($result) ); } } diff --git a/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Wysiwyg/Files/Index.php b/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Wysiwyg/Files/Index.php index 631e0d3f4c666..f4f046d2d3401 100644 --- a/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Wysiwyg/Files/Index.php +++ b/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Wysiwyg/Files/Index.php @@ -6,7 +6,9 @@ */ namespace Magento\Theme\Controller\Adminhtml\System\Design\Wysiwyg\Files; -class Index extends \Magento\Theme\Controller\Adminhtml\System\Design\Wysiwyg\Files +use Magento\Theme\Controller\Adminhtml\System\Design\Wysiwyg\Files; + +class Index extends Files { /** * Index action diff --git a/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Wysiwyg/Files/NewFolder.php b/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Wysiwyg/Files/NewFolder.php index b25f65a749b6e..6ce9956b51f08 100644 --- a/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Wysiwyg/Files/NewFolder.php +++ b/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Wysiwyg/Files/NewFolder.php @@ -6,7 +6,13 @@ */ namespace Magento\Theme\Controller\Adminhtml\System\Design\Wysiwyg\Files; -class NewFolder extends \Magento\Theme\Controller\Adminhtml\System\Design\Wysiwyg\Files +use Exception; +use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Json\Helper\Data as JsonHelper; +use Magento\Theme\Controller\Adminhtml\System\Design\Wysiwyg\Files; +use Psr\Log\LoggerInterface; + +class NewFolder extends Files { /** * New folder action @@ -19,14 +25,14 @@ public function execute() try { $path = $this->storage->getCurrentPath(); $result = $this->_getStorage()->createFolder($name, $path); - } catch (\Magento\Framework\Exception\LocalizedException $e) { + } catch (LocalizedException $e) { $result = ['error' => true, 'message' => $e->getMessage()]; - } catch (\Exception $e) { + } catch (Exception $e) { $result = ['error' => true, 'message' => __('Sorry, something went wrong. That\'s all we know.')]; - $this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e); + $this->_objectManager->get(LoggerInterface::class)->critical($e); } $this->getResponse()->representJson( - $this->_objectManager->get(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($result) + $this->_objectManager->get(JsonHelper::class)->jsonEncode($result) ); } } diff --git a/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Wysiwyg/Files/OnInsert.php b/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Wysiwyg/Files/OnInsert.php index f8787754b41ba..b7ea26ff43049 100644 --- a/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Wysiwyg/Files/OnInsert.php +++ b/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Wysiwyg/Files/OnInsert.php @@ -6,7 +6,10 @@ */ namespace Magento\Theme\Controller\Adminhtml\System\Design\Wysiwyg\Files; -class OnInsert extends \Magento\Theme\Controller\Adminhtml\System\Design\Wysiwyg\Files +use Magento\Theme\Controller\Adminhtml\System\Design\Wysiwyg\Files; +use Magento\Theme\Helper\Storage; + +class OnInsert extends Files { /** * Fire when select image @@ -15,8 +18,8 @@ class OnInsert extends \Magento\Theme\Controller\Adminhtml\System\Design\Wysiwyg */ public function execute() { - /** @var $helperStorage \Magento\Theme\Helper\Storage */ - $helperStorage = $this->_objectManager->get(\Magento\Theme\Helper\Storage::class); + /** @var Storage $helperStorage */ + $helperStorage = $this->_objectManager->get(Storage::class); $this->getResponse()->setBody($helperStorage->getRelativeUrl()); } } diff --git a/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Wysiwyg/Files/PreviewImage.php b/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Wysiwyg/Files/PreviewImage.php index 0b7641cf9210c..008bccffab8ae 100644 --- a/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Wysiwyg/Files/PreviewImage.php +++ b/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Wysiwyg/Files/PreviewImage.php @@ -6,10 +6,14 @@ */ namespace Magento\Theme\Controller\Adminhtml\System\Design\Wysiwyg\Files; +use Exception; use Magento\Framework\App\ResponseInterface; use Magento\Framework\App\Filesystem\DirectoryList; +use Magento\Theme\Controller\Adminhtml\System\Design\Wysiwyg\Files; +use Magento\Theme\Helper\Storage as ThemeStorageHelper; +use Psr\Log\LoggerInterface; -class PreviewImage extends \Magento\Theme\Controller\Adminhtml\System\Design\Wysiwyg\Files +class PreviewImage extends Files { /** * Preview image action @@ -19,16 +23,16 @@ class PreviewImage extends \Magento\Theme\Controller\Adminhtml\System\Design\Wys public function execute() { $file = $this->getRequest()->getParam('file'); - /** @var $helper \Magento\Theme\Helper\Storage */ - $helper = $this->_objectManager->get(\Magento\Theme\Helper\Storage::class); + /** @var ThemeStorageHelper $helper */ + $helper = $this->_objectManager->get(ThemeStorageHelper::class); try { return $this->_fileFactory->create( $file, ['type' => 'filename', 'value' => $helper->getThumbnailPath($file)], DirectoryList::MEDIA ); - } catch (\Exception $e) { - $this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e); + } catch (Exception $e) { + $this->_objectManager->get(LoggerInterface::class)->critical($e); $this->_redirect('core/index/notFound'); } } diff --git a/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Wysiwyg/Files/TreeJson.php b/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Wysiwyg/Files/TreeJson.php index 8bab562898311..2ff5064a0f824 100644 --- a/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Wysiwyg/Files/TreeJson.php +++ b/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Wysiwyg/Files/TreeJson.php @@ -6,7 +6,13 @@ */ namespace Magento\Theme\Controller\Adminhtml\System\Design\Wysiwyg\Files; -class TreeJson extends \Magento\Theme\Controller\Adminhtml\System\Design\Wysiwyg\Files +use Exception; +use Magento\Framework\Json\Helper\Data as JsonHelper; +use Magento\Theme\Block\Adminhtml\Wysiwyg\Files\Tree; +use Magento\Theme\Controller\Adminhtml\System\Design\Wysiwyg\Files; +use Psr\Log\LoggerInterface; + +class TreeJson extends Files { /** * Tree json action @@ -18,15 +24,15 @@ public function execute() try { $this->getResponse()->representJson( $this->_view->getLayout()->createBlock( - \Magento\Theme\Block\Adminhtml\Wysiwyg\Files\Tree::class + Tree::class )->getTreeJson( $this->_getStorage()->getTreeArray() ) ); - } catch (\Exception $e) { - $this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e); + } catch (Exception $e) { + $this->_objectManager->get(LoggerInterface::class)->critical($e); $this->getResponse()->representJson( - $this->_objectManager->get(\Magento\Framework\Json\Helper\Data::class)->jsonEncode([]) + $this->_objectManager->get(JsonHelper::class)->jsonEncode([]) ); } } diff --git a/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Wysiwyg/Files/Upload.php b/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Wysiwyg/Files/Upload.php index 5298f087e7f22..a44db2c8efefb 100644 --- a/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Wysiwyg/Files/Upload.php +++ b/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Wysiwyg/Files/Upload.php @@ -6,7 +6,11 @@ */ namespace Magento\Theme\Controller\Adminhtml\System\Design\Wysiwyg\Files; -class Upload extends \Magento\Theme\Controller\Adminhtml\System\Design\Wysiwyg\Files +use Exception; +use Magento\Framework\Json\Helper\Data as JsonHelper; +use Magento\Theme\Controller\Adminhtml\System\Design\Wysiwyg\Files; + +class Upload extends Files { /** * Files upload action @@ -18,11 +22,11 @@ public function execute() try { $path = $this->storage->getCurrentPath(); $result = $this->_getStorage()->uploadFile($path); - } catch (\Exception $e) { + } catch (Exception $e) { $result = ['error' => $e->getMessage(), 'errorcode' => $e->getCode()]; } $this->getResponse()->representJson( - $this->_objectManager->get(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($result) + $this->_objectManager->get(JsonHelper::class)->jsonEncode($result) ); } } diff --git a/app/code/Magento/Theme/Controller/Result/AsyncCssPlugin.php b/app/code/Magento/Theme/Controller/Result/AsyncCssPlugin.php index dfa83f1765041..8f0001a0b0e08 100644 --- a/app/code/Magento/Theme/Controller/Result/AsyncCssPlugin.php +++ b/app/code/Magento/Theme/Controller/Result/AsyncCssPlugin.php @@ -13,6 +13,7 @@ use Magento\Framework\App\Response\HttpInterface as HttpResponseInterface; use Magento\Framework\App\ResponseInterface; use Magento\Framework\View\Result\Layout; +use RuntimeException; /** * Plugin for asynchronous CSS loading. @@ -21,17 +22,12 @@ class AsyncCssPlugin { private const XML_PATH_USE_CSS_CRITICAL_PATH = 'dev/css/use_css_critical_path'; - /** - * @var ScopeConfigInterface - */ - private $scopeConfig; - /** * @param ScopeConfigInterface $scopeConfig */ - public function __construct(ScopeConfigInterface $scopeConfig) - { - $this->scopeConfig = $scopeConfig; + public function __construct( + private ScopeConfigInterface $scopeConfig + ) { } /** @@ -91,7 +87,7 @@ private function extractLinkTags(string &$content): string $content = str_replace($style, '', $content); if (!preg_match('@href=("|\')(.*?)\1@', $style, $hrefAttribute)) { - throw new \RuntimeException("Invalid link {$style} syntax provided"); + throw new RuntimeException("Invalid link {$style} syntax provided"); } $href = $hrefAttribute[2]; diff --git a/app/code/Magento/Theme/Controller/Result/JsFooterPlugin.php b/app/code/Magento/Theme/Controller/Result/JsFooterPlugin.php index dd490cd02b61c..96b93562a89a8 100644 --- a/app/code/Magento/Theme/Controller/Result/JsFooterPlugin.php +++ b/app/code/Magento/Theme/Controller/Result/JsFooterPlugin.php @@ -20,17 +20,12 @@ class JsFooterPlugin { private const XML_PATH_DEV_MOVE_JS_TO_BOTTOM = 'dev/js/move_script_to_bottom'; - /** - * @var ScopeConfigInterface - */ - private $scopeConfig; - /** * @param ScopeConfigInterface $scopeConfig */ - public function __construct(ScopeConfigInterface $scopeConfig) - { - $this->scopeConfig = $scopeConfig; + public function __construct( + private readonly ScopeConfigInterface $scopeConfig + ) { } /** diff --git a/app/code/Magento/Theme/Controller/Result/MessagePlugin.php b/app/code/Magento/Theme/Controller/Result/MessagePlugin.php index 056f1b21a9be8..2e8c70131055c 100644 --- a/app/code/Magento/Theme/Controller/Result/MessagePlugin.php +++ b/app/code/Magento/Theme/Controller/Result/MessagePlugin.php @@ -7,10 +7,15 @@ use Magento\Framework\Controller\Result\Json; use Magento\Framework\Controller\ResultInterface; +use Magento\Framework\Message\ManagerInterface; +use Magento\Framework\Serialize\Serializer\Json as SerializerJson; +use Magento\Framework\Stdlib\Cookie\CookieMetadataFactory; use Magento\Framework\Stdlib\Cookie\CookieSizeLimitReachedException; +use Magento\Framework\Stdlib\CookieManagerInterface; use Magento\Framework\Translate\Inline\ParserInterface; use Magento\Framework\Translate\InlineInterface; use Magento\Framework\Session\Config\ConfigInterface; +use Magento\Framework\View\Element\Message\InterpretationStrategyInterface; /** * Plugin for putting messages to cookies @@ -25,65 +30,23 @@ class MessagePlugin public const MESSAGES_COOKIES_NAME = 'mage-messages'; /** - * @var \Magento\Framework\Stdlib\CookieManagerInterface - */ - private $cookieManager; - - /** - * @var \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory - */ - private $cookieMetadataFactory; - - /** - * @var \Magento\Framework\Message\ManagerInterface - */ - private $messageManager; - - /** - * @var \Magento\Framework\View\Element\Message\InterpretationStrategyInterface - */ - private $interpretationStrategy; - - /** - * @var \Magento\Framework\Serialize\Serializer\Json - */ - private $serializer; - - /** - * @var InlineInterface - */ - private $inlineTranslate; - - /** - * @var ConfigInterface - */ - protected $sessionConfig; - - /** - * @param \Magento\Framework\Stdlib\CookieManagerInterface $cookieManager - * @param \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory $cookieMetadataFactory - * @param \Magento\Framework\Message\ManagerInterface $messageManager - * @param \Magento\Framework\View\Element\Message\InterpretationStrategyInterface $interpretationStrategy - * @param \Magento\Framework\Serialize\Serializer\Json $serializer + * @param CookieManagerInterface $cookieManager + * @param CookieMetadataFactory $cookieMetadataFactory + * @param ManagerInterface $messageManager + * @param InterpretationStrategyInterface $interpretationStrategy + * @param SerializerJson $serializer * @param InlineInterface $inlineTranslate * @param ConfigInterface $sessionConfig */ public function __construct( - \Magento\Framework\Stdlib\CookieManagerInterface $cookieManager, - \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory $cookieMetadataFactory, - \Magento\Framework\Message\ManagerInterface $messageManager, - \Magento\Framework\View\Element\Message\InterpretationStrategyInterface $interpretationStrategy, - \Magento\Framework\Serialize\Serializer\Json $serializer, - InlineInterface $inlineTranslate, - ConfigInterface $sessionConfig + private readonly CookieManagerInterface $cookieManager, + private readonly CookieMetadataFactory $cookieMetadataFactory, + private readonly ManagerInterface $messageManager, + private readonly InterpretationStrategyInterface $interpretationStrategy, + private readonly SerializerJson $serializer, + private readonly InlineInterface $inlineTranslate, + protected readonly ConfigInterface $sessionConfig ) { - $this->cookieManager = $cookieManager; - $this->cookieMetadataFactory = $cookieMetadataFactory; - $this->messageManager = $messageManager; - $this->serializer = $serializer; - $this->interpretationStrategy = $interpretationStrategy; - $this->inlineTranslate = $inlineTranslate; - $this->sessionConfig = $sessionConfig; } /** diff --git a/app/code/Magento/Theme/CustomerData/Messages.php b/app/code/Magento/Theme/CustomerData/Messages.php index 15575b1c1c7e0..2b356123f6da8 100644 --- a/app/code/Magento/Theme/CustomerData/Messages.php +++ b/app/code/Magento/Theme/CustomerData/Messages.php @@ -17,37 +17,18 @@ */ class Messages implements SectionSourceInterface { - /** - * Manager messages - * - * @var MessageManager - */ - protected $messageManager; - - /** - * @var InterpretationStrategyInterface - */ - private $interpretationStrategy; - - /** - * @var MessagesProviderInterface - */ - private $messageProvider; - /** * Constructor * - * @param MessageManager $messageManager + * @param MessageManager $messageManager Manager messages * @param InterpretationStrategyInterface $interpretationStrategy * @param MessagesProviderInterface|null $messageProvider */ public function __construct( - MessageManager $messageManager, - InterpretationStrategyInterface $interpretationStrategy, - ?MessagesProviderInterface $messageProvider = null + protected readonly MessageManager $messageManager, + private readonly InterpretationStrategyInterface $interpretationStrategy, + private ?MessagesProviderInterface $messageProvider = null ) { - $this->messageManager = $messageManager; - $this->interpretationStrategy = $interpretationStrategy; $this->messageProvider = $messageProvider ?? ObjectManager::getInstance()->get(MessagesProviderInterface::class); } diff --git a/app/code/Magento/Theme/CustomerData/MessagesProvider.php b/app/code/Magento/Theme/CustomerData/MessagesProvider.php index 360f348cb2a45..9cefb6a3979ee 100644 --- a/app/code/Magento/Theme/CustomerData/MessagesProvider.php +++ b/app/code/Magento/Theme/CustomerData/MessagesProvider.php @@ -12,22 +12,14 @@ class MessagesProvider implements MessagesProviderInterface { - /** - * Manager messages - * - * @var MessageManager - */ - private $messageManager; - /** * Constructor * * @param MessageManager $messageManager */ public function __construct( - MessageManager $messageManager + private readonly MessageManager $messageManager ) { - $this->messageManager = $messageManager; } /** @@ -35,7 +27,7 @@ public function __construct( * * @return Collection */ - public function getMessages() : Collection + public function getMessages(): Collection { return $this->messageManager->getMessages(true); } diff --git a/app/code/Magento/Theme/Helper/Storage.php b/app/code/Magento/Theme/Helper/Storage.php index a01011bd0a811..b539cd654a0b0 100644 --- a/app/code/Magento/Theme/Helper/Storage.php +++ b/app/code/Magento/Theme/Helper/Storage.php @@ -9,9 +9,21 @@ */ namespace Magento\Theme\Helper; +use InvalidArgumentException; +use Magento\Backend\Model\Session; use Magento\Framework\App\Filesystem\DirectoryList; +use Magento\Framework\App\Helper\AbstractHelper; +use Magento\Framework\App\Helper\Context; use Magento\Framework\App\ObjectManager; +use Magento\Framework\Exception\FileSystemException; +use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Exception\ValidatorException; +use Magento\Framework\Filesystem; use Magento\Framework\Filesystem\DriverInterface; +use Magento\Framework\Filesystem\Io\File as IoFile; +use Magento\Framework\View\Design\Theme\FlyweightFactory; +use Magento\Theme\Model\Theme as ModelTheme; +use Magento\Theme\Model\Wysiwyg\Storage as WysiwygStorage; /** * Handles the storage of media files like images and fonts. @@ -21,7 +33,7 @@ * @SuppressWarnings(PHPMD.CookieAndSessionMisuse) * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class Storage extends \Magento\Framework\App\Helper\AbstractHelper +class Storage extends AbstractHelper { /** * Parameter name of node @@ -73,19 +85,12 @@ class Storage extends \Magento\Framework\App\Helper\AbstractHelper protected $_storageRoot; /** - * Magento filesystem - * - * @var \Magento\Framework\Filesystem - */ - protected $filesystem; - - /** - * @var \Magento\Backend\Model\Session + * @var Session */ protected $_session; /** - * @var \Magento\Framework\View\Design\Theme\FlyweightFactory + * @var FlyweightFactory */ protected $_themeFactory; @@ -95,41 +100,30 @@ class Storage extends \Magento\Framework\App\Helper\AbstractHelper protected $mediaDirectoryWrite; /** - * @var \Magento\Framework\Filesystem\Io\File - */ - private $file; - /** - * @var DriverInterface - */ - private $filesystemDriver; - - /** - * @param \Magento\Framework\App\Helper\Context $context - * @param \Magento\Framework\Filesystem $filesystem - * @param \Magento\Backend\Model\Session $session - * @param \Magento\Framework\View\Design\Theme\FlyweightFactory $themeFactory - * @param \Magento\Framework\Filesystem\Io\File|null $file - * + * @param Context $context + * @param Filesystem $filesystem Magento filesystem + * @param Session $session + * @param FlyweightFactory $themeFactory + * @param IoFile|null $file * @param DriverInterface|null $filesystemDriver - * @throws \Magento\Framework\Exception\FileSystemException - * @throws \Magento\Framework\Exception\ValidatorException + * @throws FileSystemException + * @throws ValidatorException */ public function __construct( - \Magento\Framework\App\Helper\Context $context, - \Magento\Framework\Filesystem $filesystem, - \Magento\Backend\Model\Session $session, - \Magento\Framework\View\Design\Theme\FlyweightFactory $themeFactory, - \Magento\Framework\Filesystem\Io\File $file = null, - DriverInterface $filesystemDriver = null + Context $context, + protected readonly Filesystem $filesystem, + Session $session, + FlyweightFactory $themeFactory, + private ?IoFile $file = null, + private ?DriverInterface $filesystemDriver = null ) { parent::__construct($context); - $this->filesystem = $filesystem; $this->_session = $session; $this->_themeFactory = $themeFactory; $this->mediaDirectoryWrite = $this->filesystem->getDirectoryWrite(DirectoryList::MEDIA); $this->mediaDirectoryWrite->create($this->mediaDirectoryWrite->getRelativePath($this->getStorageRoot())); $this->file = $file ?: ObjectManager::getInstance()->get( - \Magento\Framework\Filesystem\Io\File::class + IoFile::class ); $this->filesystemDriver = $filesystemDriver ?: ObjectManager::getInstance()->get(DriverInterface::class); } @@ -192,15 +186,15 @@ public function getStorageRoot() /** * Get theme module for custom static files * - * @return \Magento\Theme\Model\Theme - * @throws \InvalidArgumentException + * @return ModelTheme + * @throws InvalidArgumentException */ protected function _getTheme() { $themeId = $this->_getRequest()->getParam(self::PARAM_THEME_ID); $theme = $this->_themeFactory->create($themeId); if (!$themeId || !$theme) { - throw new \InvalidArgumentException('Theme was not found.'); + throw new InvalidArgumentException('Theme was not found.'); } return $theme; } @@ -209,17 +203,17 @@ protected function _getTheme() * Get storage type * * @return string - * @throws \Magento\Framework\Exception\LocalizedException + * @throws LocalizedException */ public function getStorageType() { $allowedTypes = [ - \Magento\Theme\Model\Wysiwyg\Storage::TYPE_FONT, - \Magento\Theme\Model\Wysiwyg\Storage::TYPE_IMAGE, + WysiwygStorage::TYPE_FONT, + WysiwygStorage::TYPE_IMAGE, ]; $type = (string)$this->_getRequest()->getParam(self::PARAM_CONTENT_TYPE); if (!in_array($type, $allowedTypes)) { - throw new \Magento\Framework\Exception\LocalizedException(__('Invalid type')); + throw new LocalizedException(__('Invalid type')); } return $type; } @@ -284,7 +278,7 @@ public function getThumbnailDirectory($path) return sprintf( "%s/%s", $this->file->getPathInfo($path)['dirname'], - \Magento\Theme\Model\Wysiwyg\Storage::THUMBNAIL_DIRECTORY + WysiwygStorage::THUMBNAIL_DIRECTORY ); } @@ -293,7 +287,7 @@ public function getThumbnailDirectory($path) * * @param string $imageName * @return string - * @throws \InvalidArgumentException + * @throws InvalidArgumentException */ public function getThumbnailPath($imageName) { @@ -301,7 +295,7 @@ public function getThumbnailPath($imageName) if (!$this->mediaDirectoryWrite->isExist($imagePath) || 0 !== strpos($imagePath, (string) $this->getStorageRoot()) ) { - throw new \InvalidArgumentException('The image not found.'); + throw new InvalidArgumentException('The image not found.'); } return sprintf( "%s/%s", @@ -331,11 +325,11 @@ public function getRequestParams() * Get allowed extensions by type * * @return string[] - * @throws \Magento\Framework\Exception\LocalizedException + * @throws LocalizedException */ public function getAllowedExtensionsByType() { - return $this->getStorageType() == \Magento\Theme\Model\Wysiwyg\Storage::TYPE_FONT + return $this->getStorageType() == WysiwygStorage::TYPE_FONT ? ['ttf', 'otf', 'eot', 'svg', 'woff'] : ['jpg', 'jpeg', 'gif', 'png', 'xbm', 'wbmp']; } @@ -344,11 +338,11 @@ public function getAllowedExtensionsByType() * Get storage type name for display. * * @return string - * @throws \Magento\Framework\Exception\LocalizedException + * @throws LocalizedException */ public function getStorageTypeName() { - return $this->getStorageType() == \Magento\Theme\Model\Wysiwyg\Storage::TYPE_FONT + return $this->getStorageType() == WysiwygStorage::TYPE_FONT ? self::FONTS : self::IMAGES; } @@ -356,7 +350,7 @@ public function getStorageTypeName() /** * Get session model * - * @return \Magento\Backend\Model\Session + * @return Session */ public function getSession() { diff --git a/app/code/Magento/Theme/Helper/Theme.php b/app/code/Magento/Theme/Helper/Theme.php index 786f029cb4764..5be4cf9f14c9c 100644 --- a/app/code/Magento/Theme/Helper/Theme.php +++ b/app/code/Magento/Theme/Helper/Theme.php @@ -9,29 +9,37 @@ */ namespace Magento\Theme\Helper; -class Theme extends \Magento\Framework\App\Helper\AbstractHelper +use Magento\Framework\App\Helper\AbstractHelper; +use Magento\Framework\App\Helper\Context; +use Magento\Framework\View\Asset\LocalInterface; +use Magento\Framework\View\Asset\Repository; +use Magento\Framework\View\Design\ThemeInterface; +use Magento\Framework\View\Layout\ProcessorFactory; +use Magento\Framework\View\Layout\ProcessorInterface; + +class Theme extends AbstractHelper { /** * Layout merge factory * - * @var \Magento\Framework\View\Layout\ProcessorFactory + * @var ProcessorFactory */ protected $_layoutProcessorFactory; /** - * @var \Magento\Framework\View\Asset\Repository + * @var Repository */ protected $_assetRepo; /** - * @param \Magento\Framework\App\Helper\Context $context - * @param \Magento\Framework\View\Layout\ProcessorFactory $layoutProcessorFactory - * @param \Magento\Framework\View\Asset\Repository $assetRepo + * @param Context $context + * @param ProcessorFactory $layoutProcessorFactory + * @param Repository $assetRepo */ public function __construct( - \Magento\Framework\App\Helper\Context $context, - \Magento\Framework\View\Layout\ProcessorFactory $layoutProcessorFactory, - \Magento\Framework\View\Asset\Repository $assetRepo + Context $context, + ProcessorFactory $layoutProcessorFactory, + Repository $assetRepo ) { $this->_layoutProcessorFactory = $layoutProcessorFactory; $this->_assetRepo = $assetRepo; @@ -45,12 +53,12 @@ public function __construct( * array('Magento_Catalog::widgets.css' => \Magento\Framework\View\Asset\LocalInterface) * The array will be sorted by keys * - * @param \Magento\Framework\View\Design\ThemeInterface $theme - * @return \Magento\Framework\View\Asset\LocalInterface[] + * @param ThemeInterface $theme + * @return LocalInterface[] */ public function getCssAssets($theme) { - /** @var $layoutProcessor \Magento\Framework\View\Layout\ProcessorInterface */ + /** @var ProcessorInterface $layoutProcessor */ $layoutProcessor = $this->_layoutProcessorFactory->create(['theme' => $theme]); $layoutElement = $layoutProcessor->getFileLayoutUpdatesXml(); diff --git a/app/code/Magento/Theme/Model/Config.php b/app/code/Magento/Theme/Model/Config.php index 57efe43db3d7c..6c93d2a5ffa38 100644 --- a/app/code/Magento/Theme/Model/Config.php +++ b/app/code/Magento/Theme/Model/Config.php @@ -9,57 +9,66 @@ */ namespace Magento\Theme\Model; +use Magento\Config\Model\ResourceModel\Config\Data\Collection as ResourceConfigDataCollection; use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\App\Config\Storage\WriterInterface; +use Magento\Framework\App\Config\ValueInterface; +use Magento\Framework\Cache\FrontendInterface; +use Magento\Framework\Event\ManagerInterface; +use Magento\Framework\View\Design\ThemeInterface; +use Magento\Framework\View\DesignInterface; +use Magento\Store\Model\ScopeInterface; +use Magento\Store\Model\StoreManagerInterface; class Config { /** - * @var \Magento\Framework\App\Config\Storage\WriterInterface + * @var WriterInterface */ protected $_configWriter; /** - * @var \Magento\Framework\App\Config\ValueInterface + * @var ValueInterface */ protected $_configData; /** - * @var \Magento\Store\Model\StoreManagerInterface + * @var StoreManagerInterface */ protected $_storeManager; /** * Application event manager * - * @var \Magento\Framework\Event\ManagerInterface + * @var ManagerInterface */ protected $_eventManager; /** - * @var \Magento\Framework\Cache\FrontendInterface + * @var FrontendInterface */ protected $_configCache; /** - * @var \Magento\Framework\Cache\FrontendInterface + * @var FrontendInterface */ protected $_layoutCache; /** - * @param \Magento\Framework\App\Config\ValueInterface $configData - * @param \Magento\Framework\App\Config\Storage\WriterInterface $configWriter - * @param \Magento\Store\Model\StoreManagerInterface $storeManager - * @param \Magento\Framework\Event\ManagerInterface $eventManager - * @param \Magento\Framework\Cache\FrontendInterface $configCache - * @param \Magento\Framework\Cache\FrontendInterface $layoutCache + * @param ValueInterface $configData + * @param WriterInterface $configWriter + * @param StoreManagerInterface $storeManager + * @param ManagerInterface $eventManager + * @param FrontendInterface $configCache + * @param FrontendInterface $layoutCache */ public function __construct( - \Magento\Framework\App\Config\ValueInterface $configData, - \Magento\Framework\App\Config\Storage\WriterInterface $configWriter, - \Magento\Store\Model\StoreManagerInterface $storeManager, - \Magento\Framework\Event\ManagerInterface $eventManager, - \Magento\Framework\Cache\FrontendInterface $configCache, - \Magento\Framework\Cache\FrontendInterface $layoutCache + ValueInterface $configData, + WriterInterface $configWriter, + StoreManagerInterface $storeManager, + ManagerInterface $eventManager, + FrontendInterface $configCache, + FrontendInterface $layoutCache ) { $this->_configData = $configData; $this->_configWriter = $configWriter; @@ -72,7 +81,7 @@ public function __construct( /** * Assign theme to the stores * - * @param \Magento\Framework\View\Design\ThemeInterface $theme + * @param ThemeInterface $theme * @param array $stores * @param string $scope * @return $this @@ -80,7 +89,7 @@ public function __construct( public function assignToStore( $theme, array $stores = [], - $scope = \Magento\Store\Model\ScopeInterface::SCOPE_STORES + $scope = ScopeInterface::SCOPE_STORES ) { $isReassigned = false; @@ -110,7 +119,7 @@ public function assignToStore( * * @param string $scope * @param string $configPath - * @return \Magento\Config\Model\ResourceModel\Config\Data\Collection + * @return ResourceConfigDataCollection */ protected function _getAssignedScopesCollection($scope, $configPath) { @@ -134,7 +143,7 @@ protected function _getAssignedScopesCollection($scope, $configPath) */ protected function _unassignThemeFromStores($themeId, $stores, $scope, &$isReassigned) { - $configPath = \Magento\Framework\View\DesignInterface::XML_PATH_THEME_ID; + $configPath = DesignInterface::XML_PATH_THEME_ID; foreach ($this->_getAssignedScopesCollection($scope, $configPath) as $config) { if ($config->getValue() == $themeId && !in_array($config->getScopeId(), $stores)) { $this->_configWriter->delete($configPath, $scope, $config->getScopeId()); @@ -155,7 +164,7 @@ protected function _unassignThemeFromStores($themeId, $stores, $scope, &$isReass */ protected function _assignThemeToStores($themeId, $stores, $scope, &$isReassigned) { - $configPath = \Magento\Framework\View\DesignInterface::XML_PATH_THEME_ID; + $configPath = DesignInterface::XML_PATH_THEME_ID; if (count($stores) > 0) { foreach ($stores as $storeId) { $this->_configWriter->save($configPath, $themeId, $scope, $storeId); @@ -174,7 +183,7 @@ protected function _assignThemeToStores($themeId, $stores, $scope, &$isReassigne */ protected function _assignThemeToDefaultScope($themeId, &$isReassigned) { - $configPath = \Magento\Framework\View\DesignInterface::XML_PATH_THEME_ID; + $configPath = DesignInterface::XML_PATH_THEME_ID; $this->_configWriter->save($configPath, $themeId, ScopeConfigInterface::SCOPE_TYPE_DEFAULT); $isReassigned = true; return $this; diff --git a/app/code/Magento/Theme/Model/Config/Customization.php b/app/code/Magento/Theme/Model/Config/Customization.php index 7430730451110..a9952488eb678 100644 --- a/app/code/Magento/Theme/Model/Config/Customization.php +++ b/app/code/Magento/Theme/Model/Config/Customization.php @@ -31,11 +31,6 @@ class Customization */ protected $_design; - /** - * @var ThemeProviderInterface - */ - protected $themeProvider; - /** * Theme customizations which are assigned to store views or as default * @@ -51,10 +46,6 @@ class Customization * @see self::_prepareThemeCustomizations() */ protected $_unassignedTheme; - /** - * @var StoreUserAgentThemeResolver|mixed|null - */ - private $storeThemesResolver; /** * @param StoreManagerInterface $storeManager @@ -65,12 +56,11 @@ class Customization public function __construct( StoreManagerInterface $storeManager, DesignInterface $design, - ThemeProviderInterface $themeProvider, - ?StoreThemesResolverInterface $storeThemesResolver = null + protected readonly ThemeProviderInterface $themeProvider, + private ?StoreThemesResolverInterface $storeThemesResolver = null ) { $this->_storeManager = $storeManager; $this->_design = $design; - $this->themeProvider = $themeProvider; $this->storeThemesResolver = $storeThemesResolver ?? ObjectManager::getInstance()->get(StoreThemesResolverInterface::class); } @@ -195,7 +185,7 @@ protected function _prepareThemeCustomizations() $this->_assignedTheme = []; $this->_unassignedTheme = []; - /** @var $theme ThemeInterface */ + /** @var ThemeInterface $theme */ foreach ($themeCollection as $theme) { if (isset($assignedThemes[$theme->getId()])) { $theme->setAssignedStores($assignedThemes[$theme->getId()]); diff --git a/app/code/Magento/Theme/Model/Config/Importer.php b/app/code/Magento/Theme/Model/Config/Importer.php index dc1808f71ae4a..138c1bb59beaf 100644 --- a/app/code/Magento/Theme/Model/Config/Importer.php +++ b/app/code/Magento/Theme/Model/Config/Importer.php @@ -5,6 +5,7 @@ */ namespace Magento\Theme\Model\Config; +use Exception; use Magento\Framework\App\DeploymentConfig\ImporterInterface; use Magento\Framework\Exception\State\InvalidTransitionException; use Magento\Theme\Model\ResourceModel\Theme as ThemeResourceModel; @@ -27,13 +28,6 @@ */ class Importer implements ImporterInterface { - /** - * Collection of themes from the filesystem. - * - * @var ThemeFilesystemCollection - */ - private $themeFilesystemCollection; - /** * Factory of themes collection from the DB. * @@ -48,13 +42,6 @@ class Importer implements ImporterInterface */ private $themeRegistration; - /** - * Resource model of theme. - * - * @var ThemeResourceModel - */ - private $themeResourceModel; - /** * @param ThemeFilesystemCollection $themeFilesystemCollection The collection of themes from the filesystem * @param CollectionFactory $collectionFactory The factory of themes collection from the DB @@ -62,15 +49,13 @@ class Importer implements ImporterInterface * @param ThemeResourceModel $themeResourceModel The resource model of theme */ public function __construct( - ThemeFilesystemCollection $themeFilesystemCollection, + private readonly ThemeFilesystemCollection $themeFilesystemCollection, CollectionFactory $collectionFactory, Registration $registration, - ThemeResourceModel $themeResourceModel + private readonly ThemeResourceModel $themeResourceModel ) { - $this->themeFilesystemCollection = $themeFilesystemCollection; $this->themeCollectionFactory = $collectionFactory; $this->themeRegistration = $registration; - $this->themeResourceModel = $themeResourceModel; } /** @@ -100,7 +85,7 @@ public function import(array $data) $this->themeResourceModel->delete($theme); } } - } catch (\Exception $exception) { + } catch (Exception $exception) { throw new InvalidTransitionException(__('%1', $exception->getMessage()), $exception); } diff --git a/app/code/Magento/Theme/Model/Config/Processor/DesignTheme.php b/app/code/Magento/Theme/Model/Config/Processor/DesignTheme.php index d9d2c0e041e99..efc467835c668 100644 --- a/app/code/Magento/Theme/Model/Config/Processor/DesignTheme.php +++ b/app/code/Magento/Theme/Model/Config/Processor/DesignTheme.php @@ -5,6 +5,8 @@ */ namespace Magento\Theme\Model\Config\Processor; +use DomainException; +use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\App\Config\Spi\PreProcessorInterface; use Magento\Framework\Stdlib\ArrayManager; use Magento\Framework\View\Design\Theme\ListInterface; @@ -18,26 +20,14 @@ */ class DesignTheme implements PreProcessorInterface { - /** - * @var ArrayManager - */ - private $arrayManager; - - /** - * @var ListInterface - */ - private $themeList; - /** * @param ArrayManager $arrayManager * @param ListInterface $themeList */ public function __construct( - ArrayManager $arrayManager, - ListInterface $themeList + private readonly ArrayManager $arrayManager, + private readonly ListInterface $themeList ) { - $this->arrayManager = $arrayManager; - $this->themeList = $themeList; } /** @@ -50,7 +40,7 @@ public function __construct( public function process(array $config) { foreach ($config as $scope => &$item) { - if ($scope === \Magento\Framework\App\Config\ScopeConfigInterface::SCOPE_TYPE_DEFAULT) { + if ($scope === ScopeConfigInterface::SCOPE_TYPE_DEFAULT) { $item = $this->changeThemeFullPathToIdentifier($item); } else { foreach ($item as &$scopeItems) { @@ -78,7 +68,7 @@ private function changeThemeFullPathToIdentifier($configItems) // workaround for case when db is not available try { $theme = $this->themeList->getThemeByFullPath($themeIdentifier); - } catch (\DomainException $domainException) { + } catch (DomainException $domainException) { $theme = null; } } diff --git a/app/code/Magento/Theme/Model/CopyService.php b/app/code/Magento/Theme/Model/CopyService.php index a6ef782b9be6b..9eca9225d1c08 100644 --- a/app/code/Magento/Theme/Model/CopyService.php +++ b/app/code/Magento/Theme/Model/CopyService.php @@ -10,7 +10,18 @@ namespace Magento\Theme\Model; use Magento\Framework\App\Filesystem\DirectoryList; +use Magento\Framework\Event\ManagerInterface; +use Magento\Framework\Exception\FileSystemException; +use Magento\Framework\Filesystem; +use Magento\Framework\View\Design\Theme\Customization\Path; +use Magento\Framework\View\Design\Theme\FileFactory; use Magento\Framework\View\Design\ThemeInterface; +use Magento\Theme\Model\Theme\File; +use Magento\Widget\Model\Layout\Link; +use Magento\Widget\Model\Layout\Update as ModelLayoutUpdate; +use Magento\Widget\Model\Layout\UpdateFactory; +use Magento\Widget\Model\ResourceModel\Layout\Link\Collection as ResourceLayoutLinkCollection; +use Magento\Widget\Model\ResourceModel\Layout\Update\Collection as ResourceLayoutUpdateCollection; class CopyService { @@ -20,45 +31,45 @@ class CopyService protected $_directory; /** - * @var \Magento\Framework\View\Design\Theme\FileFactory + * @var FileFactory */ protected $_fileFactory; /** - * @var \Magento\Widget\Model\Layout\Link + * @var Link */ protected $_link; /** - * @var \Magento\Widget\Model\Layout\UpdateFactory + * @var UpdateFactory */ protected $_updateFactory; /** - * @var \Magento\Framework\Event\ManagerInterface + * @var ManagerInterface */ protected $_eventManager; /** - * @var \Magento\Framework\View\Design\Theme\Customization\Path + * @var Path */ protected $_customizationPath; /** - * @param \Magento\Framework\Filesystem $filesystem - * @param \Magento\Framework\View\Design\Theme\FileFactory $fileFactory - * @param \Magento\Widget\Model\Layout\Link $link - * @param \Magento\Widget\Model\Layout\UpdateFactory $updateFactory - * @param \Magento\Framework\Event\ManagerInterface $eventManager - * @param \Magento\Framework\View\Design\Theme\Customization\Path $customization + * @param Filesystem $filesystem + * @param FileFactory $fileFactory + * @param Link $link + * @param UpdateFactory $updateFactory + * @param ManagerInterface $eventManager + * @param Path $customization */ public function __construct( - \Magento\Framework\Filesystem $filesystem, - \Magento\Framework\View\Design\Theme\FileFactory $fileFactory, - \Magento\Widget\Model\Layout\Link $link, - \Magento\Widget\Model\Layout\UpdateFactory $updateFactory, - \Magento\Framework\Event\ManagerInterface $eventManager, - \Magento\Framework\View\Design\Theme\Customization\Path $customization + Filesystem $filesystem, + FileFactory $fileFactory, + Link $link, + UpdateFactory $updateFactory, + ManagerInterface $eventManager, + Path $customization ) { $this->_directory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA); $this->_fileFactory = $fileFactory; @@ -91,13 +102,13 @@ public function copy(ThemeInterface $source, ThemeInterface $target) */ protected function _copyDatabaseCustomization(ThemeInterface $source, ThemeInterface $target) { - /** @var $themeFile \Magento\Theme\Model\Theme\File */ + /** @var File $themeFile */ foreach ($target->getCustomization()->getFiles() as $themeFile) { $themeFile->delete(); } - /** @var $newFile \Magento\Theme\Model\Theme\File */ + /** @var File $newFile */ foreach ($source->getCustomization()->getFiles() as $themeFile) { - /** @var $newThemeFile \Magento\Theme\Model\Theme\File */ + /** @var File $newThemeFile */ $newThemeFile = $this->_fileFactory->create(); $newThemeFile->setData( [ @@ -122,17 +133,17 @@ protected function _copyDatabaseCustomization(ThemeInterface $source, ThemeInter protected function _copyLayoutCustomization(ThemeInterface $source, ThemeInterface $target) { $update = $this->_updateFactory->create(); - /** @var $targetUpdates \Magento\Widget\Model\ResourceModel\Layout\Update\Collection */ + /** @var ResourceLayoutUpdateCollection $targetUpdates */ $targetUpdates = $update->getCollection(); $targetUpdates->addThemeFilter($target->getId()); $targetUpdates->delete(); - /** @var $sourceCollection \Magento\Widget\Model\ResourceModel\Layout\Link\Collection */ + /** @var ResourceLayoutLinkCollection $sourceCollection */ $sourceCollection = $this->_link->getCollection(); $sourceCollection->addThemeFilter($source->getId()); - /** @var $layoutLink \Magento\Widget\Model\Layout\Link */ + /** @var $layoutLink Link */ foreach ($sourceCollection as $layoutLink) { - /** @var $update \Magento\Widget\Model\Layout\Update */ + /** @var ModelLayoutUpdate $update */ $update = $this->_updateFactory->create(); $update->load($layoutLink->getLayoutUpdateId()); if ($update->getId()) { diff --git a/app/code/Magento/Theme/Model/Data/Design/Config.php b/app/code/Magento/Theme/Model/Data/Design/Config.php index 6a34ef6753c8f..f353ec64e29b6 100644 --- a/app/code/Magento/Theme/Model/Data/Design/Config.php +++ b/app/code/Magento/Theme/Model/Data/Design/Config.php @@ -6,6 +6,7 @@ namespace Magento\Theme\Model\Data\Design; use Magento\Framework\Api\AbstractExtensibleObject; +use Magento\Theme\Api\Data\DesignConfigExtensionInterface; use Magento\Theme\Api\Data\DesignConfigInterface; class Config extends AbstractExtensibleObject implements DesignConfigInterface @@ -58,7 +59,7 @@ public function getExtensionAttributes() /** * @inheritDoc */ - public function setExtensionAttributes(\Magento\Theme\Api\Data\DesignConfigExtensionInterface $extensionAttributes) + public function setExtensionAttributes(DesignConfigExtensionInterface $extensionAttributes) { return $this->_setExtensionAttributes($extensionAttributes); } diff --git a/app/code/Magento/Theme/Model/Data/Design/ConfigFactory.php b/app/code/Magento/Theme/Model/Data/Design/ConfigFactory.php index e0b77a1657447..6ffe4720f49f3 100644 --- a/app/code/Magento/Theme/Model/Data/Design/ConfigFactory.php +++ b/app/code/Magento/Theme/Model/Data/Design/ConfigFactory.php @@ -23,36 +23,6 @@ */ class ConfigFactory { - /** - * @var DesignConfigInterfaceFactory - */ - protected $designConfigFactory; - - /** - * @var MetadataProviderInterface - */ - protected $metadataProvider; - - /** - * @var DesignConfigDataInterfaceFactory - */ - protected $designConfigDataFactory; - - /** - * @var DesignConfigExtensionFactory - */ - protected $configExtensionFactory; - - /** - * @var ScopeValidatorInterface - */ - protected $scopeValidator; - - /** - * @var StoreManagerInterface - */ - protected $storeManager; - /** * @param DesignConfigInterfaceFactory $designConfigFactory * @param MetadataProviderInterface $metadataProvider @@ -62,19 +32,13 @@ class ConfigFactory * @param StoreManagerInterface $storeManager */ public function __construct( - DesignConfigInterfaceFactory $designConfigFactory, - MetadataProviderInterface $metadataProvider, - DesignConfigDataInterfaceFactory $designConfigDataFactory, - DesignConfigExtensionFactory $configExtensionFactory, - ScopeValidatorInterface $scopeValidator, - StoreManagerInterface $storeManager + protected readonly DesignConfigInterfaceFactory $designConfigFactory, + protected readonly MetadataProviderInterface $metadataProvider, + protected readonly DesignConfigDataInterfaceFactory $designConfigDataFactory, + protected readonly DesignConfigExtensionFactory $configExtensionFactory, + protected readonly ScopeValidatorInterface $scopeValidator, + protected readonly StoreManagerInterface $storeManager ) { - $this->designConfigFactory = $designConfigFactory; - $this->metadataProvider = $metadataProvider; - $this->designConfigDataFactory = $designConfigDataFactory; - $this->configExtensionFactory = $configExtensionFactory; - $this->scopeValidator = $scopeValidator; - $this->storeManager = $storeManager; } /** diff --git a/app/code/Magento/Theme/Model/Design.php b/app/code/Magento/Theme/Model/Design.php index 11cef8a3938e0..d2e995f18d4f9 100644 --- a/app/code/Magento/Theme/Model/Design.php +++ b/app/code/Magento/Theme/Model/Design.php @@ -7,22 +7,29 @@ use Magento\Framework\App\DesignInterface; use Magento\Framework\App\ObjectManager; +use Magento\Framework\Data\Collection\AbstractDb; use Magento\Framework\Model\AbstractModel; +use Magento\Framework\Model\Context; use Magento\Framework\Model\ResourceModel\AbstractResource; use Magento\Framework\DataObject\IdentityInterface; +use Magento\Framework\Registry; use Magento\Framework\Serialize\SerializerInterface; +use Magento\Framework\Stdlib\DateTime; +use Magento\Framework\Stdlib\DateTime\TimezoneInterface; +use Magento\Framework\View\DesignInterface as ViewDesignInterface; +use Magento\Theme\Model\ResourceModel\Design as ResourceDesign; /** * Design settings change model * * @method int getStoreId() - * @method \Magento\Theme\Model\Design setStoreId(int $value) + * @method Design setStoreId(int $value) * @method string getDesign() - * @method \Magento\Theme\Model\Design setDesign(string $value) + * @method Design setDesign(string $value) * @method string getDateFrom() - * @method \Magento\Theme\Model\Design setDateFrom(string $value) + * @method Design setDateFrom(string $value) * @method string getDateTo() - * @method \Magento\Theme\Model\Design setDateTo(string $value) + * @method Design setDateTo(string $value) */ class Design extends AbstractModel implements IdentityInterface, DesignInterface { @@ -48,39 +55,34 @@ class Design extends AbstractModel implements IdentityInterface, DesignInterface protected $_cacheTag = self::CACHE_TAG; /** - * @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface + * @var TimezoneInterface */ protected $_localeDate; /** - * @var \Magento\Framework\Stdlib\DateTime + * @var DateTime */ protected $_dateTime; /** - * @var SerializerInterface - */ - private $serializer; - - /** - * @param \Magento\Framework\Model\Context $context - * @param \Magento\Framework\Registry $registry - * @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate - * @param \Magento\Framework\Stdlib\DateTime $dateTime + * @param Context $context + * @param Registry $registry + * @param TimezoneInterface $localeDate + * @param DateTime $dateTime * @param AbstractResource $resource - * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection + * @param AbstractDb $resourceCollection * @param array $data * @param SerializerInterface $serializer */ public function __construct( - \Magento\Framework\Model\Context $context, - \Magento\Framework\Registry $registry, - \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate, - \Magento\Framework\Stdlib\DateTime $dateTime, + Context $context, + Registry $registry, + TimezoneInterface $localeDate, + DateTime $dateTime, AbstractResource $resource = null, - \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, + AbstractDb $resourceCollection = null, array $data = [], - SerializerInterface $serializer = null + private ?SerializerInterface $serializer = null ) { $this->_localeDate = $localeDate; $this->_dateTime = $dateTime; @@ -95,7 +97,7 @@ public function __construct( */ protected function _construct() { - $this->_init(\Magento\Theme\Model\ResourceModel\Design::class); + $this->_init(ResourceDesign::class); } /** @@ -135,10 +137,10 @@ public function loadChange($storeId, $date = null) /** * Apply design change from self data into specified design package instance * - * @param \Magento\Framework\View\DesignInterface $packageInto + * @param ViewDesignInterface $packageInto * @return $this */ - public function changeDesign(\Magento\Framework\View\DesignInterface $packageInto) + public function changeDesign(ViewDesignInterface $packageInto) { $design = $this->getDesign(); if ($design) { diff --git a/app/code/Magento/Theme/Model/Design/Backend/Exceptions.php b/app/code/Magento/Theme/Model/Design/Backend/Exceptions.php index e381bfc3513f5..6bf3a868d3eb7 100644 --- a/app/code/Magento/Theme/Model/Design/Backend/Exceptions.php +++ b/app/code/Magento/Theme/Model/Design/Backend/Exceptions.php @@ -6,7 +6,16 @@ namespace Magento\Theme\Model\Design\Backend; use Magento\Config\Model\Config\Backend\Serialized\ArraySerialized; +use Magento\Framework\App\Area; +use Magento\Framework\App\Cache\TypeListInterface; +use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\Data\Collection\AbstractDb; +use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Model\Context; +use Magento\Framework\Model\ResourceModel\AbstractResource; +use Magento\Framework\Registry; use Magento\Framework\Serialize\Serializer\Json; +use Magento\Framework\View\DesignInterface; /** * Validate Eav Model before save. @@ -16,31 +25,31 @@ class Exceptions extends ArraySerialized /** * Design package instance * - * @var \Magento\Framework\View\DesignInterface + * @var DesignInterface */ protected $_design = null; /** * Initialize dependencies * - * @param \Magento\Framework\Model\Context $context - * @param \Magento\Framework\Registry $registry - * @param \Magento\Framework\App\Config\ScopeConfigInterface $config - * @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList - * @param \Magento\Framework\View\DesignInterface $design - * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource - * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection + * @param Context $context + * @param Registry $registry + * @param ScopeConfigInterface $config + * @param TypeListInterface $cacheTypeList + * @param DesignInterface $design + * @param AbstractResource $resource + * @param AbstractDb $resourceCollection * @param array $data * @param Json|null $serializer */ public function __construct( - \Magento\Framework\Model\Context $context, - \Magento\Framework\Registry $registry, - \Magento\Framework\App\Config\ScopeConfigInterface $config, - \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList, - \Magento\Framework\View\DesignInterface $design, - \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, - \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, + Context $context, + Registry $registry, + ScopeConfigInterface $config, + TypeListInterface $cacheTypeList, + DesignInterface $design, + AbstractResource $resource = null, + AbstractDb $resourceCollection = null, array $data = [], Json $serializer = null ) { @@ -61,7 +70,7 @@ public function __construct( * Validate value * * @return $this - * @throws \Magento\Framework\Exception\LocalizedException + * @throws LocalizedException * if there is no field value, search value is empty or regular expression is not valid */ public function beforeSave() @@ -75,7 +84,7 @@ public function beforeSave() // Validate that all values have come foreach (['search', 'value'] as $fieldName) { if (!isset($row[$fieldName])) { - throw new \Magento\Framework\Exception\LocalizedException( + throw new LocalizedException( __('%1 does not contain field \'%2\'', $this->getData('field_config/fieldset'), $fieldName) ); } @@ -88,7 +97,7 @@ public function beforeSave() } // Validate the theme value - $design->setDesignTheme($row['value'], \Magento\Framework\App\Area::AREA_FRONTEND); + $design->setDesignTheme($row['value'], Area::AREA_FRONTEND); // Compose regular exception pattern $exceptions[$rowKey]['regexp'] = $this->_composeRegexp($row['search']); @@ -104,7 +113,7 @@ public function beforeSave() * @param string $search * @return string * - * @throws \Magento\Framework\Exception\LocalizedException on invalid regular expression + * @throws LocalizedException on invalid regular expression */ protected function _composeRegexp($search) { @@ -117,7 +126,7 @@ protected function _composeRegexp($search) // Find out - whether user wanted to enter regexp or normal string. if ($this->_isRegexp($search)) { - throw new \Magento\Framework\Exception\LocalizedException(__('Invalid regular expression: "%1".', $search)); + throw new LocalizedException(__('Invalid regular expression: "%1".', $search)); } return '/' . preg_quote($search, '/') . '/i'; diff --git a/app/code/Magento/Theme/Model/Design/Backend/Favicon.php b/app/code/Magento/Theme/Model/Design/Backend/Favicon.php index 2d53b11eea6cb..5199338e89b90 100644 --- a/app/code/Magento/Theme/Model/Design/Backend/Favicon.php +++ b/app/code/Magento/Theme/Model/Design/Backend/Favicon.php @@ -5,6 +5,7 @@ */ namespace Magento\Theme\Model\Design\Backend; +use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Filesystem; class Favicon extends Image @@ -19,7 +20,7 @@ class Favicon extends Image * Return path to directory for upload file * * @return string - * @throw \Magento\Framework\Exception\LocalizedException + * @throws LocalizedException */ protected function _getUploadDir() { diff --git a/app/code/Magento/Theme/Model/Design/Backend/File.php b/app/code/Magento/Theme/Model/Design/Backend/File.php index 143889364781f..870e9e4d76607 100644 --- a/app/code/Magento/Theme/Model/Design/Backend/File.php +++ b/app/code/Magento/Theme/Model/Design/Backend/File.php @@ -33,26 +33,11 @@ */ class File extends BackendFile { - /** - * @var UrlInterface - */ - protected $urlBuilder; - /** * @var Mime */ private $mime; - /** - * @var IoFileSystem - */ - private $ioFileSystem; - - /** - * @var Database - */ - private $databaseHelper; - /** * @param Context $context * @param Registry $registry @@ -77,12 +62,12 @@ public function __construct( UploaderFactory $uploaderFactory, RequestDataInterface $requestData, Filesystem $filesystem, - UrlInterface $urlBuilder, + protected readonly UrlInterface $urlBuilder, AbstractResource $resource = null, AbstractDb $resourceCollection = null, array $data = [], - Database $databaseHelper = null, - IoFileSystem $ioFileSystem = null + private ?Database $databaseHelper = null, + private ?IoFileSystem $ioFileSystem = null ) { parent::__construct( $context, @@ -96,7 +81,6 @@ public function __construct( $resourceCollection, $data ); - $this->urlBuilder = $urlBuilder; $this->databaseHelper = $databaseHelper ?: ObjectManager::getInstance()->get(Database::class); $this->ioFileSystem = $ioFileSystem ?: ObjectManager::getInstance()->get(IoFileSystem::class); } diff --git a/app/code/Magento/Theme/Model/Design/Backend/Theme.php b/app/code/Magento/Theme/Model/Design/Backend/Theme.php index fd7ab88430257..8ae504ba41105 100644 --- a/app/code/Magento/Theme/Model/Design/Backend/Theme.php +++ b/app/code/Magento/Theme/Model/Design/Backend/Theme.php @@ -5,14 +5,23 @@ */ namespace Magento\Theme\Model\Design\Backend; +use Magento\Framework\App\Area; +use Magento\Framework\App\Cache\TypeListInterface; +use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\App\Config\Value; +use Magento\Framework\Data\Collection\AbstractDb; +use Magento\Framework\Model\Context; +use Magento\Framework\Model\ResourceModel\AbstractResource; +use Magento\Framework\Registry; +use Magento\Framework\View\DesignInterface; +use Magento\Store\Model\ScopeInterface; class Theme extends Value { /** * Design package instance * - * @var \Magento\Framework\View\DesignInterface + * @var DesignInterface */ protected $_design = null; @@ -26,23 +35,23 @@ class Theme extends Value /** * Initialize dependencies * - * @param \Magento\Framework\Model\Context $context - * @param \Magento\Framework\Registry $registry - * @param \Magento\Framework\App\Config\ScopeConfigInterface $config - * @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList - * @param \Magento\Framework\View\DesignInterface $design - * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource - * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection + * @param Context $context + * @param Registry $registry + * @param ScopeConfigInterface $config + * @param TypeListInterface $cacheTypeList + * @param DesignInterface $design + * @param AbstractResource $resource + * @param AbstractDb $resourceCollection * @param array $data */ public function __construct( - \Magento\Framework\Model\Context $context, - \Magento\Framework\Registry $registry, - \Magento\Framework\App\Config\ScopeConfigInterface $config, - \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList, - \Magento\Framework\View\DesignInterface $design, - \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, - \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, + Context $context, + Registry $registry, + ScopeConfigInterface $config, + TypeListInterface $cacheTypeList, + DesignInterface $design, + AbstractResource $resource = null, + AbstractDb $resourceCollection = null, array $data = [] ) { $this->_design = $design; @@ -58,7 +67,7 @@ public function beforeSave() { if ('' != $this->getValue()) { $design = clone $this->_design; - $design->setDesignTheme($this->getValue(), \Magento\Framework\App\Area::AREA_FRONTEND); + $design->setDesignTheme($this->getValue(), Area::AREA_FRONTEND); } return parent::beforeSave(); } @@ -74,7 +83,7 @@ protected function invalidateCache($forceInvalidate = false) $types = array_keys( $this->_config->getValue( self::XML_PATH_INVALID_CACHES, - \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ScopeInterface::SCOPE_STORE ) ); if ($forceInvalidate || $this->isValueChanged()) { diff --git a/app/code/Magento/Theme/Model/Design/BackendModelFactory.php b/app/code/Magento/Theme/Model/Design/BackendModelFactory.php index df4ad381ca0d8..d6ec5ab8f5a4c 100644 --- a/app/code/Magento/Theme/Model/Design/BackendModelFactory.php +++ b/app/code/Magento/Theme/Model/Design/BackendModelFactory.php @@ -29,16 +29,6 @@ class BackendModelFactory extends ValueFactory */ protected $metadata = []; - /** - * @var MetadataProvider - */ - protected $metadataProvider; - - /** - * @var CollectionFactory - */ - protected $collectionFactory; - /** * @var array */ @@ -51,11 +41,9 @@ class BackendModelFactory extends ValueFactory */ public function __construct( ObjectManagerInterface $objectManager, - MetadataProvider $metadataProvider, - CollectionFactory $collectionFactory + protected readonly MetadataProvider $metadataProvider, + protected readonly CollectionFactory $collectionFactory ) { - $this->metadataProvider = $metadataProvider; - $this->collectionFactory = $collectionFactory; parent::__construct($objectManager); } diff --git a/app/code/Magento/Theme/Model/Design/Config/DataProvider.php b/app/code/Magento/Theme/Model/Design/Config/DataProvider.php index 4cc6e81c3b84f..808de35427958 100644 --- a/app/code/Magento/Theme/Model/Design/Config/DataProvider.php +++ b/app/code/Magento/Theme/Model/Design/Config/DataProvider.php @@ -7,6 +7,7 @@ use Magento\Framework\App\Config\ScopeCodeResolver; use Magento\Framework\App\ObjectManager; +use Magento\Store\Model\ScopeInterface; use Magento\Theme\Model\ResourceModel\Design\Config\Collection; use Magento\Theme\Model\ResourceModel\Design\Config\CollectionFactory; use Magento\Ui\DataProvider\AbstractDataProvider; @@ -25,16 +26,6 @@ class DataProvider extends AbstractDataProvider */ protected $collection; - /** - * @var DataProvider\DataLoader - */ - protected $dataLoader; - - /** - * @var DataProvider\MetadataLoader - */ - private $metadataLoader; - /** * @var SettingChecker */ @@ -64,8 +55,8 @@ public function __construct( $name, $primaryFieldName, $requestFieldName, - DataProvider\DataLoader $dataLoader, - DataProvider\MetadataLoader $metadataLoader, + protected readonly DataProvider\DataLoader $dataLoader, + private readonly DataProvider\MetadataLoader $metadataLoader, CollectionFactory $configCollectionFactory, array $meta = [], array $data = [] @@ -77,11 +68,8 @@ public function __construct( $meta, $data ); - $this->dataLoader = $dataLoader; - $this->metadataLoader = $metadataLoader; $this->collection = $configCollectionFactory->create(); - $this->meta = array_merge($this->meta, $this->metadataLoader->getData()); } @@ -163,7 +151,7 @@ public function getMeta() */ private function getSearchEngineRobotsMetadata($scope, array $fields = []) { - if ($scope == \Magento\Store\Model\ScopeInterface::SCOPE_STORES) { + if ($scope == ScopeInterface::SCOPE_STORES) { $resetToDefaultsData = [ 'arguments' => [ 'data' => [ diff --git a/app/code/Magento/Theme/Model/Design/Config/DataProvider/DataLoader.php b/app/code/Magento/Theme/Model/Design/Config/DataProvider/DataLoader.php index bdb1ba06655a8..bec66b87cb64c 100644 --- a/app/code/Magento/Theme/Model/Design/Config/DataProvider/DataLoader.php +++ b/app/code/Magento/Theme/Model/Design/Config/DataProvider/DataLoader.php @@ -11,34 +11,16 @@ class DataLoader { - /** - * @var RequestInterface - */ - protected $request; - - /** - * @var DesignConfigRepositoryInterface - */ - protected $designConfigRepository; - - /** - * @var DataPersistorInterface - */ - protected $dataPersistor; - /** * @param RequestInterface $request * @param DesignConfigRepositoryInterface $designConfigRepository * @param DataPersistorInterface $dataPersistor */ public function __construct( - RequestInterface $request, - DesignConfigRepositoryInterface $designConfigRepository, - DataPersistorInterface $dataPersistor + protected readonly RequestInterface $request, + protected readonly DesignConfigRepositoryInterface $designConfigRepository, + protected readonly DataPersistorInterface $dataPersistor ) { - $this->request = $request; - $this->designConfigRepository = $designConfigRepository; - $this->dataPersistor = $dataPersistor; } /** diff --git a/app/code/Magento/Theme/Model/Design/Config/DataProvider/MetadataLoader.php b/app/code/Magento/Theme/Model/Design/Config/DataProvider/MetadataLoader.php index 4af1d5bc56506..b4490975ff065 100644 --- a/app/code/Magento/Theme/Model/Design/Config/DataProvider/MetadataLoader.php +++ b/app/code/Magento/Theme/Model/Design/Config/DataProvider/MetadataLoader.php @@ -12,26 +12,6 @@ class MetadataLoader { - /** - * @var RequestInterface - */ - protected $request; - - /** - * @var ScopeFallbackResolverInterface - */ - protected $scopeFallbackResolver; - - /** - * @var DesignConfigRepositoryInterface - */ - protected $designConfigRepository; - - /** - * @var StoreManagerInterface - */ - protected $storeManager; - /** * @param RequestInterface $request * @param ScopeFallbackResolverInterface $scopeFallbackResolver @@ -39,15 +19,11 @@ class MetadataLoader * @param StoreManagerInterface $storeManager */ public function __construct( - RequestInterface $request, - ScopeFallbackResolverInterface $scopeFallbackResolver, - DesignConfigRepositoryInterface $designConfigRepository, - StoreManagerInterface $storeManager + protected readonly RequestInterface $request, + protected readonly ScopeFallbackResolverInterface $scopeFallbackResolver, + protected readonly DesignConfigRepositoryInterface $designConfigRepository, + protected readonly StoreManagerInterface $storeManager ) { - $this->request = $request; - $this->scopeFallbackResolver = $scopeFallbackResolver; - $this->designConfigRepository = $designConfigRepository; - $this->storeManager = $storeManager; } /** diff --git a/app/code/Magento/Theme/Model/Design/Config/FileUploader/FileProcessor.php b/app/code/Magento/Theme/Model/Design/Config/FileUploader/FileProcessor.php index c60e48e9673a2..13bb378554a84 100644 --- a/app/code/Magento/Theme/Model/Design/Config/FileUploader/FileProcessor.php +++ b/app/code/Magento/Theme/Model/Design/Config/FileUploader/FileProcessor.php @@ -6,6 +6,7 @@ namespace Magento\Theme\Model\Design\Config\FileUploader; +use Exception; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Filesystem; use Magento\MediaStorage\Model\File\UploaderFactory; @@ -24,21 +25,6 @@ */ class FileProcessor { - /** - * @var UploaderFactory - */ - protected $uploaderFactory; - - /** - * @var BackendModelFactory - */ - protected $backendModelFactory; - - /** - * @var MetadataProvider - */ - protected $metadataProvider; - /** * Media Directory object (writable). * @@ -46,11 +32,6 @@ class FileProcessor */ protected $mediaDirectory; - /** - * @var StoreManagerInterface - */ - protected $storeManager; - /** * @var string */ @@ -64,23 +45,19 @@ class FileProcessor * @param StoreManagerInterface $storeManager */ public function __construct( - UploaderFactory $uploaderFactory, - BackendModelFactory $backendModelFactory, - MetadataProvider $metadataProvider, + protected readonly UploaderFactory $uploaderFactory, + protected readonly BackendModelFactory $backendModelFactory, + protected readonly MetadataProvider $metadataProvider, Filesystem $filesystem, - StoreManagerInterface $storeManager + protected readonly StoreManagerInterface $storeManager ) { - $this->uploaderFactory = $uploaderFactory; - $this->backendModelFactory = $backendModelFactory; - $this->metadataProvider = $metadataProvider; - $this->storeManager = $storeManager; $this->mediaDirectory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA); } /** * Save file to temp media directory * - * @param string $fileId + * @param string $fileId * * @return array */ @@ -89,7 +66,7 @@ public function saveToTmp($fileId) try { $result = $this->save($fileId, $this->getAbsoluteTmpMediaPath()); $result['url'] = $this->getTmpMediaUrl($result['file']); - } catch (\Exception $e) { + } catch (Exception $e) { $result = ['error' => $e->getMessage(), 'errorcode' => $e->getCode()]; } return $result; diff --git a/app/code/Magento/Theme/Model/Design/Config/MetadataProvider.php b/app/code/Magento/Theme/Model/Design/Config/MetadataProvider.php index 2ef1c906e2111..bcce296eaa0b8 100644 --- a/app/code/Magento/Theme/Model/Design/Config/MetadataProvider.php +++ b/app/code/Magento/Theme/Model/Design/Config/MetadataProvider.php @@ -7,17 +7,12 @@ class MetadataProvider implements MetadataProviderInterface { - /** - * @var array - */ - protected $metadata; - /** * @param array $metadata */ - public function __construct(array $metadata) - { - $this->metadata = $metadata; + public function __construct( + protected readonly array $metadata + ) { } /** diff --git a/app/code/Magento/Theme/Model/Design/Config/Plugin.php b/app/code/Magento/Theme/Model/Design/Config/Plugin.php index de6b2027ccb88..3a2252e7c6343 100644 --- a/app/code/Magento/Theme/Model/Design/Config/Plugin.php +++ b/app/code/Magento/Theme/Model/Design/Config/Plugin.php @@ -13,26 +13,14 @@ class Plugin { - /** - * @var \Magento\Framework\Event\ManagerInterface - */ - protected $eventManager; - - /** - * @var \Magento\Store\Model\StoreManagerInterface - */ - protected $storeManager; - /** * @param EventManager $eventManager * @param StoreManager $storeManager */ public function __construct( - EventManager $eventManager, - StoreManager $storeManager + protected readonly EventManager $eventManager, + protected readonly StoreManager $storeManager ) { - $this->eventManager = $eventManager; - $this->storeManager = $storeManager; } /** diff --git a/app/code/Magento/Theme/Model/Design/Config/Plugin/Dump.php b/app/code/Magento/Theme/Model/Design/Config/Plugin/Dump.php index 98ac82c2a42c1..e9ec3e34633e4 100644 --- a/app/code/Magento/Theme/Model/Design/Config/Plugin/Dump.php +++ b/app/code/Magento/Theme/Model/Design/Config/Plugin/Dump.php @@ -6,6 +6,7 @@ namespace Magento\Theme\Model\Design\Config\Plugin; use Magento\Config\App\Config\Source\DumpConfigSourceAggregated; +use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\Stdlib\ArrayManager; use Magento\Framework\View\Design\Theme\ListInterface; use Magento\Framework\View\DesignInterface; @@ -18,30 +19,18 @@ * As a result of Magento\Config\App\Config\Source\DumpConfigSourceAggregated expected * to be shared between environments where IDs can not be used, we need * to change theme id to full path value what can be used as an identifier. - * @see \Magento\Config\App\Config\Source\DumpConfigSourceAggregated + * @see DumpConfigSourceAggregated */ class Dump { - /** - * @var ListInterface - */ - private $themeList; - - /** - * @var ArrayManager - */ - private $arrayManager; - /** * @param ListInterface $themeList * @param ArrayManager $arrayManager */ public function __construct( - ListInterface $themeList, - ArrayManager $arrayManager + private readonly ListInterface $themeList, + private readonly ArrayManager $arrayManager ) { - $this->themeList = $themeList; - $this->arrayManager = $arrayManager; } /** @@ -56,7 +45,7 @@ public function __construct( public function afterGet(DumpConfigSourceAggregated $subject, $result) { foreach ($result as $scope => &$item) { - if ($scope === \Magento\Framework\App\Config\ScopeConfigInterface::SCOPE_TYPE_DEFAULT) { + if ($scope === ScopeConfigInterface::SCOPE_TYPE_DEFAULT) { $item = $this->changeThemeIdToFullPath($item); } else { foreach ($item as &$scopeItems) { diff --git a/app/code/Magento/Theme/Model/Design/Config/Storage.php b/app/code/Magento/Theme/Model/Design/Config/Storage.php index c97114f963a09..184ef00ca089c 100644 --- a/app/code/Magento/Theme/Model/Design/Config/Storage.php +++ b/app/code/Magento/Theme/Model/Design/Config/Storage.php @@ -7,6 +7,7 @@ use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\App\Config\Value; +use Magento\Framework\DB\Transaction; use Magento\Theme\Api\Data\DesignConfigInterface; use Magento\Framework\DB\TransactionFactory; use Magento\Framework\App\Config\ValueInterface; @@ -15,36 +16,6 @@ class Storage { - /** - * @var \Magento\Framework\DB\TransactionFactory - */ - protected $transactionFactory; - - /** - * @var \Magento\Theme\Model\Design\BackendModelFactory - */ - protected $backendModelFactory; - - /** - * @var \Magento\Theme\Model\Design\Config\ValueChecker - */ - protected $valueChecker; - - /** - * @var ConfigFactory - */ - protected $configFactory; - - /** - * @var ScopeConfigInterface - */ - protected $scopeConfig; - - /** - * @var ValueProcessor - */ - protected $valueProcessor; - /** * @param TransactionFactory $transactionFactory * @param BackendModelFactory $backendModelFactory @@ -54,19 +25,13 @@ class Storage * @param ValueProcessor $valueProcessor */ public function __construct( - TransactionFactory $transactionFactory, - BackendModelFactory $backendModelFactory, - ValueChecker $valueChecker, - ConfigFactory $configFactory, - ScopeConfigInterface $scopeConfig, - ValueProcessor $valueProcessor + protected readonly TransactionFactory $transactionFactory, + protected readonly BackendModelFactory $backendModelFactory, + protected readonly ValueChecker $valueChecker, + protected readonly ConfigFactory $configFactory, + protected readonly ScopeConfigInterface $scopeConfig, + protected readonly ValueProcessor $valueProcessor ) { - $this->transactionFactory = $transactionFactory; - $this->backendModelFactory = $backendModelFactory; - $this->valueChecker = $valueChecker; - $this->configFactory = $configFactory; - $this->scopeConfig = $scopeConfig; - $this->valueProcessor = $valueProcessor; } /** @@ -106,9 +71,9 @@ public function load($scope, $scopeId) public function save(DesignConfigInterface $designConfig) { $fieldsData = $designConfig->getExtensionAttributes()->getDesignConfigData(); - /* @var $saveTransaction \Magento\Framework\DB\Transaction */ + /* @var Transaction $saveTransaction */ $saveTransaction = $this->transactionFactory->create(); - /* @var $deleteTransaction \Magento\Framework\DB\Transaction */ + /* @var Transaction $deleteTransaction */ $deleteTransaction = $this->transactionFactory->create(); foreach ($fieldsData as $fieldData) { /** @var ValueInterface|Value $backendModel */ @@ -145,7 +110,7 @@ public function save(DesignConfigInterface $designConfig) public function delete(DesignConfigInterface $designConfig) { $fieldsData = $designConfig->getExtensionAttributes()->getDesignConfigData(); - /* @var $deleteTransaction \Magento\Framework\DB\Transaction */ + /* @var $deleteTransaction Transaction */ $deleteTransaction = $this->transactionFactory->create(); foreach ($fieldsData as $fieldData) { /** @var ValueInterface|Value $backendModel */ diff --git a/app/code/Magento/Theme/Model/Design/Config/Validator.php b/app/code/Magento/Theme/Model/Design/Config/Validator.php index 1279d9d9ccd20..9560160d5d23f 100644 --- a/app/code/Magento/Theme/Model/Design/Config/Validator.php +++ b/app/code/Magento/Theme/Model/Design/Config/Validator.php @@ -18,26 +18,16 @@ */ class Validator { - /** - * @var string[] - */ - private $fields = []; - - /** - * @var TemplateFactory - */ - private $templateFactory; - /** * Initialize dependencies. * * @param TemplateFactory $templateFactory * @param string[] $fields */ - public function __construct(TemplateFactory $templateFactory, $fields = []) - { - $this->templateFactory = $templateFactory; - $this->fields = $fields; + public function __construct( + private readonly TemplateFactory $templateFactory, + private $fields = [] + ) { } /** diff --git a/app/code/Magento/Theme/Model/Design/Config/ValueChecker.php b/app/code/Magento/Theme/Model/Design/Config/ValueChecker.php index 11d45616e387d..0433e2d3c4a95 100644 --- a/app/code/Magento/Theme/Model/Design/Config/ValueChecker.php +++ b/app/code/Magento/Theme/Model/Design/Config/ValueChecker.php @@ -13,34 +13,16 @@ */ class ValueChecker { - /** - * @var ScopeFallbackResolverInterface - */ - protected $fallbackResolver; - - /** - * @var AppConfig - */ - protected $appConfig; - - /** - * @var ValueProcessor - */ - protected $valueProcessor; - /** * @param ScopeFallbackResolverInterface $fallbackResolver * @param AppConfig $appConfig - * @param \Magento\Theme\Model\Design\Config\ValueProcessor $valueProcessor + * @param ValueProcessor $valueProcessor */ public function __construct( - ScopeFallbackResolverInterface $fallbackResolver, - AppConfig $appConfig, - ValueProcessor $valueProcessor + protected readonly ScopeFallbackResolverInterface $fallbackResolver, + protected readonly AppConfig $appConfig, + protected readonly ValueProcessor $valueProcessor ) { - $this->fallbackResolver = $fallbackResolver; - $this->appConfig = $appConfig; - $this->valueProcessor = $valueProcessor; } /** diff --git a/app/code/Magento/Theme/Model/Design/Config/ValueProcessor.php b/app/code/Magento/Theme/Model/Design/Config/ValueProcessor.php index 63dc75a9baa54..2d76526b0e557 100644 --- a/app/code/Magento/Theme/Model/Design/Config/ValueProcessor.php +++ b/app/code/Magento/Theme/Model/Design/Config/ValueProcessor.php @@ -9,18 +9,12 @@ class ValueProcessor { - /** - * @var BackendModelFactory - */ - protected $backendModelFactory; - /** * @param BackendModelFactory $backendModelFactory */ public function __construct( - BackendModelFactory $backendModelFactory + protected readonly BackendModelFactory $backendModelFactory ) { - $this->backendModelFactory = $backendModelFactory; } /** diff --git a/app/code/Magento/Theme/Model/Design/Theme/Label.php b/app/code/Magento/Theme/Model/Design/Theme/Label.php index 2f5d0d1cea1ef..acc84a7232e6d 100644 --- a/app/code/Magento/Theme/Model/Design/Theme/Label.php +++ b/app/code/Magento/Theme/Model/Design/Theme/Label.php @@ -5,7 +5,9 @@ */ namespace Magento\Theme\Model\Design\Theme; -class Label extends \Magento\Framework\View\Design\Theme\Label +use Magento\Framework\View\Design\Theme\Label as DesignThemeLabel; + +class Label extends DesignThemeLabel { /** * Return labels collection array diff --git a/app/code/Magento/Theme/Model/DesignConfigRepository.php b/app/code/Magento/Theme/Model/DesignConfigRepository.php index 3a81b8c24b455..057772b07075f 100644 --- a/app/code/Magento/Theme/Model/DesignConfigRepository.php +++ b/app/code/Magento/Theme/Model/DesignConfigRepository.php @@ -6,6 +6,7 @@ namespace Magento\Theme\Model; +use Magento\Framework\App\ObjectManager; use Magento\Framework\Indexer\IndexerRegistry; use Magento\Theme\Api\Data\DesignConfigInterface; use Magento\Theme\Api\DesignConfigRepositoryInterface; @@ -13,28 +14,14 @@ use Magento\Framework\App\Config\ReinitableConfigInterface; use Magento\Theme\Model\Data\Design\Config as DesignConfig; use Magento\Theme\Model\Design\Config\Storage as ConfigStorage; +use Magento\Theme\Model\Design\Config\Validator; class DesignConfigRepository implements DesignConfigRepositoryInterface { - /** - * @var \Magento\Framework\App\Config\ReinitableConfigInterface - */ - protected $reinitableConfig; - - /** - * @var \Magento\Framework\Indexer\IndexerRegistry - */ - protected $indexerRegistry; - - /** - * @var \Magento\Theme\Model\Design\Config\Storage - */ - protected $configStorage; - /** * Design config validator * - * @var \Magento\Theme\Model\Design\Config\Validator + * @var Validator */ private $validator; @@ -44,13 +31,10 @@ class DesignConfigRepository implements DesignConfigRepositoryInterface * @param IndexerRegistry $indexerRegistry */ public function __construct( - ConfigStorage $configStorage, - ReinitableConfigInterface $reinitableConfig, - IndexerRegistry $indexerRegistry + protected readonly ConfigStorage $configStorage, + protected readonly ReinitableConfigInterface $reinitableConfig, + protected readonly IndexerRegistry $indexerRegistry ) { - $this->reinitableConfig = $reinitableConfig; - $this->indexerRegistry = $indexerRegistry; - $this->configStorage = $configStorage; } /** @@ -63,8 +47,8 @@ public function __construct( private function getValidator() { if (null === $this->validator) { - $this->validator =\Magento\Framework\App\ObjectManager::getInstance()->get( - \Magento\Theme\Model\Design\Config\Validator::class + $this->validator = ObjectManager::getInstance()->get( + Validator::class ); } return $this->validator; diff --git a/app/code/Magento/Theme/Model/Favicon/Favicon.php b/app/code/Magento/Theme/Model/Favicon/Favicon.php index e1b9703c9d9cc..afc38016294aa 100644 --- a/app/code/Magento/Theme/Model/Favicon/Favicon.php +++ b/app/code/Magento/Theme/Model/Favicon/Favicon.php @@ -5,12 +5,21 @@ */ namespace Magento\Theme\Model\Favicon; +use Magento\Config\Model\Config\Backend\Image\Favicon as ImageFavicon; +use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\App\Filesystem\DirectoryList; +use Magento\Framework\Filesystem; +use Magento\Framework\Filesystem\Directory\ReadInterface; +use Magento\Framework\UrlInterface; +use Magento\Framework\View\Page\FaviconInterface; +use Magento\MediaStorage\Helper\File\Storage\Database; +use Magento\Store\Model\ScopeInterface; +use Magento\Store\Model\StoreManagerInterface; /** * Favicon implementation */ -class Favicon implements \Magento\Framework\View\Page\FaviconInterface +class Favicon implements FaviconInterface { /** * @var string @@ -18,40 +27,22 @@ class Favicon implements \Magento\Framework\View\Page\FaviconInterface protected $faviconFile; /** - * @var \Magento\Store\Model\StoreManagerInterface - */ - protected $storeManager; - - /** - * @var \Magento\Framework\App\Config\ScopeConfigInterface - */ - protected $scopeConfig; - - /** - * @var \Magento\MediaStorage\Helper\File\Storage\Database - */ - protected $fileStorageDatabase; - - /** - * @var \Magento\Framework\Filesystem\Directory\ReadInterface + * @var ReadInterface */ protected $mediaDirectory; /** - * @param \Magento\Store\Model\StoreManagerInterface $storeManager - * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig - * @param \Magento\MediaStorage\Helper\File\Storage\Database $fileStorageDatabase - * @param \Magento\Framework\Filesystem $filesystem + * @param StoreManagerInterface $storeManager + * @param ScopeConfigInterface $scopeConfig + * @param Database $fileStorageDatabase + * @param Filesystem $filesystem */ public function __construct( - \Magento\Store\Model\StoreManagerInterface $storeManager, - \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, - \Magento\MediaStorage\Helper\File\Storage\Database $fileStorageDatabase, - \Magento\Framework\Filesystem $filesystem + protected readonly StoreManagerInterface $storeManager, + protected readonly ScopeConfigInterface $scopeConfig, + protected readonly Database $fileStorageDatabase, + Filesystem $filesystem ) { - $this->storeManager = $storeManager; - $this->scopeConfig = $scopeConfig; - $this->fileStorageDatabase = $fileStorageDatabase; $this->mediaDirectory = $filesystem->getDirectoryRead(DirectoryList::MEDIA); } @@ -79,14 +70,14 @@ public function getDefaultFavicon() */ protected function prepareFaviconFile() { - $folderName = \Magento\Config\Model\Config\Backend\Image\Favicon::UPLOAD_DIR; + $folderName = ImageFavicon::UPLOAD_DIR; $scopeConfig = $this->scopeConfig->getValue( 'design/head/shortcut_icon', - \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ScopeInterface::SCOPE_STORE ); $path = $folderName . '/' . $scopeConfig; $faviconUrl = $this->storeManager->getStore() - ->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA) . $path; + ->getBaseUrl(UrlInterface::URL_TYPE_MEDIA) . $path; if ($scopeConfig !== null && $this->checkIsFile($path)) { return $faviconUrl; diff --git a/app/code/Magento/Theme/Model/Indexer/Design/Config.php b/app/code/Magento/Theme/Model/Indexer/Design/Config.php index 3422140604bfc..0ffe8ee923ba3 100644 --- a/app/code/Magento/Theme/Model/Indexer/Design/Config.php +++ b/app/code/Magento/Theme/Model/Indexer/Design/Config.php @@ -5,9 +5,11 @@ */ namespace Magento\Theme\Model\Indexer\Design; +use ArrayObject; use Magento\Framework\Indexer\ActionInterface; use Magento\Framework\Indexer\FieldsetPool; use Magento\Framework\Indexer\HandlerPool; +use Magento\Theme\Model\ResourceModel\Design\Config\Scope\Collection as DesignConfigScopeCollection; use Magento\Theme\Model\ResourceModel\Design\Config\Scope\CollectionFactory; use Magento\Framework\Indexer\SaveHandler\IndexerInterface; use Magento\Framework\Indexer\IndexStructureInterface; @@ -16,26 +18,6 @@ class Config implements ActionInterface { - /** - * @var CollectionFactory - */ - protected $collectionFactory; - - /** - * @var SaveHandlerFactory - */ - protected $saveHandlerFactory; - - /** - * @var StructureFactory - */ - protected $structureFactory; - - /** - * @var IndexerInterface - */ - protected $saveHandler; - /** * @var array */ @@ -47,19 +29,9 @@ class Config implements ActionInterface protected $searchable = []; /** - * @var FieldsetPool - */ - protected $fieldsetPool; - - /** - * @var HandlerPool - */ - protected $handlerPool; - - /** - * @var array + * @var IndexerInterface */ - private $data = []; + protected $saveHandler; /** * Config constructor @@ -72,19 +44,13 @@ class Config implements ActionInterface * @param array $data */ public function __construct( - StructureFactory $structureFactory, - SaveHandlerFactory $saveHandlerFactory, - FieldsetPool $fieldsetPool, - HandlerPool $handlerPool, - CollectionFactory $collectionFactory, - $data = [] + protected readonly StructureFactory $structureFactory, + protected readonly SaveHandlerFactory $saveHandlerFactory, + protected readonly FieldsetPool $fieldsetPool, + protected readonly HandlerPool $handlerPool, + protected readonly CollectionFactory $collectionFactory, + private $data = [] ) { - $this->structureFactory = $structureFactory; - $this->saveHandlerFactory = $saveHandlerFactory; - $this->fieldsetPool = $fieldsetPool; - $this->handlerPool = $handlerPool; - $this->collectionFactory = $collectionFactory; - $this->data = $data; } /** @@ -95,13 +61,13 @@ public function __construct( */ protected function execute(array $ids = []) { - /** @var \Magento\Theme\Model\ResourceModel\Design\Config\Scope\Collection $collection */ + /** @var DesignConfigScopeCollection $collection */ $collection = $this->collectionFactory->create(); $this->prepareFields(); if (!count($ids)) { $this->getSaveHandler()->cleanIndex([]); } - $this->getSaveHandler()->deleteIndex([], new \ArrayObject($ids)); + $this->getSaveHandler()->deleteIndex([], new ArrayObject($ids)); $this->getSaveHandler()->saveIndex([], $collection); } diff --git a/app/code/Magento/Theme/Model/Indexer/Design/Config/FieldsProvider.php b/app/code/Magento/Theme/Model/Indexer/Design/Config/FieldsProvider.php index 6d28c049f9244..a5ec7d397c934 100644 --- a/app/code/Magento/Theme/Model/Indexer/Design/Config/FieldsProvider.php +++ b/app/code/Magento/Theme/Model/Indexer/Design/Config/FieldsProvider.php @@ -6,22 +6,17 @@ namespace Magento\Theme\Model\Indexer\Design\Config; use Magento\Framework\Indexer\FieldsetInterface; +use Magento\Framework\Indexer\Handler\DefaultHandler; use Magento\Theme\Model\Design\Config\MetadataProviderInterface; class FieldsProvider implements FieldsetInterface { - /** - * @var MetadataProviderInterface - */ - protected $metadataProvider; - /** * @param MetadataProviderInterface $metadataProvider */ public function __construct( - MetadataProviderInterface $metadataProvider + protected readonly MetadataProviderInterface $metadataProvider ) { - $this->metadataProvider = $metadataProvider; } /** @@ -52,7 +47,7 @@ protected function convert(array $metadata) $fields[$itemName] = [ 'name' => $itemName, 'origin' => 'value', - 'handler' => \Magento\Framework\Indexer\Handler\DefaultHandler::class, + 'handler' => DefaultHandler::class, 'type' => 'searchable', ]; } diff --git a/app/code/Magento/Theme/Model/Indexer/Design/Config/Plugin/Store.php b/app/code/Magento/Theme/Model/Indexer/Design/Config/Plugin/Store.php index 18ce1be2e68d1..ab4efda4f631b 100644 --- a/app/code/Magento/Theme/Model/Indexer/Design/Config/Plugin/Store.php +++ b/app/code/Magento/Theme/Model/Indexer/Design/Config/Plugin/Store.php @@ -11,17 +11,12 @@ class Store { - /** - * @var IndexerRegistry - */ - protected $indexerRegistry; - /** * @param IndexerRegistry $indexerRegistry */ - public function __construct(IndexerRegistry $indexerRegistry) - { - $this->indexerRegistry = $indexerRegistry; + public function __construct( + protected readonly IndexerRegistry $indexerRegistry + ) { } /** diff --git a/app/code/Magento/Theme/Model/Indexer/Design/Config/Plugin/StoreGroup.php b/app/code/Magento/Theme/Model/Indexer/Design/Config/Plugin/StoreGroup.php index 96a3c45bff033..3953842245fc5 100644 --- a/app/code/Magento/Theme/Model/Indexer/Design/Config/Plugin/StoreGroup.php +++ b/app/code/Magento/Theme/Model/Indexer/Design/Config/Plugin/StoreGroup.php @@ -11,18 +11,12 @@ class StoreGroup { - /** - * @var IndexerRegistry - */ - protected $indexerRegistry; - /** * @param IndexerRegistry $indexerRegistry */ public function __construct( - IndexerRegistry $indexerRegistry + protected readonly IndexerRegistry $indexerRegistry ) { - $this->indexerRegistry = $indexerRegistry; } /** diff --git a/app/code/Magento/Theme/Model/Indexer/Design/Config/Plugin/Website.php b/app/code/Magento/Theme/Model/Indexer/Design/Config/Plugin/Website.php index 0906b02776c18..2206c504bb707 100644 --- a/app/code/Magento/Theme/Model/Indexer/Design/Config/Plugin/Website.php +++ b/app/code/Magento/Theme/Model/Indexer/Design/Config/Plugin/Website.php @@ -5,35 +5,30 @@ */ namespace Magento\Theme\Model\Indexer\Design\Config\Plugin; +use Closure; use Magento\Framework\Indexer\IndexerRegistry; use Magento\Store\Model\Website as StoreWebsite; use Magento\Theme\Model\Data\Design\Config; class Website { - /** - * @var IndexerRegistry - */ - protected $indexerRegistry; - /** * @param IndexerRegistry $indexerRegistry */ public function __construct( - IndexerRegistry $indexerRegistry + protected readonly IndexerRegistry $indexerRegistry ) { - $this->indexerRegistry = $indexerRegistry; } /** * Invalidate design config grid indexer on website creation * * @param StoreWebsite $subject - * @param \Closure $proceed + * @param Closure $proceed * @return StoreWebsite * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ - public function aroundSave(StoreWebsite $subject, \Closure $proceed) + public function aroundSave(StoreWebsite $subject, Closure $proceed) { $isObjectNew = $subject->getId() == 0; $result = $proceed(); diff --git a/app/code/Magento/Theme/Model/Indexer/Design/IndexerHandler.php b/app/code/Magento/Theme/Model/Indexer/Design/IndexerHandler.php index 1acc75a6c949c..9a797a44d0674 100644 --- a/app/code/Magento/Theme/Model/Indexer/Design/IndexerHandler.php +++ b/app/code/Magento/Theme/Model/Indexer/Design/IndexerHandler.php @@ -19,11 +19,6 @@ class IndexerHandler extends Grid { - /** - * @var FlatScopeResolver - */ - private $flatScopeResolver; - /** * @param IndexStructureInterface $indexStructure * @param ResourceConnection $resource @@ -38,7 +33,7 @@ public function __construct( ResourceConnection $resource, Batch $batch, IndexScopeResolver $indexScopeResolver, - FlatScopeResolver $flatScopeResolver, + private readonly FlatScopeResolver $flatScopeResolver, array $data, $batchSize = 100 ) { @@ -51,8 +46,6 @@ public function __construct( $data, $batchSize ); - - $this->flatScopeResolver = $flatScopeResolver; } /** diff --git a/app/code/Magento/Theme/Model/Layout/Config.php b/app/code/Magento/Theme/Model/Layout/Config.php index 8d5b9ca469994..7319ac925c0e1 100644 --- a/app/code/Magento/Theme/Model/Layout/Config.php +++ b/app/code/Magento/Theme/Model/Layout/Config.php @@ -5,6 +5,9 @@ */ namespace Magento\Theme\Model\Layout; +use Magento\Framework\Config\DataInterface; +use Magento\Framework\DataObject; + /** * Page layout config model */ @@ -18,24 +21,25 @@ class Config protected $_pageLayouts; /** - * @var \Magento\Framework\Config\DataInterface + * @var DataInterface */ protected $_dataStorage; /** * Constructor * - * @param \Magento\Framework\Config\DataInterface $dataStorage + * @param DataInterface $dataStorage */ - public function __construct(\Magento\Framework\Config\DataInterface $dataStorage) - { + public function __construct( + DataInterface $dataStorage + ) { $this->_dataStorage = $dataStorage; } /** * Initialize page layouts list * - * @return \Magento\Theme\Model\Layout\Config + * @return Config */ protected function _initPageLayouts() { @@ -43,7 +47,7 @@ protected function _initPageLayouts() $this->_pageLayouts = []; foreach ($this->_dataStorage->get(null) as $layoutCode => $layoutConfig) { $layoutConfig['label'] = __($layoutConfig['label']); - $this->_pageLayouts[$layoutCode] = new \Magento\Framework\DataObject($layoutConfig); + $this->_pageLayouts[$layoutCode] = new DataObject($layoutConfig); } } return $this; @@ -52,7 +56,7 @@ protected function _initPageLayouts() /** * Retrieve available page layouts * - * @return \Magento\Framework\DataObject[] + * @return DataObject[] */ public function getPageLayouts() { @@ -64,7 +68,7 @@ public function getPageLayouts() * Retrieve page layout by code * * @param string $layoutCode - * @return \Magento\Framework\DataObject|boolean + * @return DataObject|boolean */ public function getPageLayout($layoutCode) { diff --git a/app/code/Magento/Theme/Model/Layout/Config/Converter.php b/app/code/Magento/Theme/Model/Layout/Config/Converter.php index 99b772d155827..99ccf01bcc888 100644 --- a/app/code/Magento/Theme/Model/Layout/Config/Converter.php +++ b/app/code/Magento/Theme/Model/Layout/Config/Converter.php @@ -7,7 +7,9 @@ */ namespace Magento\Theme\Model\Layout\Config; -class Converter implements \Magento\Framework\Config\ConverterInterface +use Magento\Framework\Config\ConverterInterface; + +class Converter implements ConverterInterface { /** * {@inheritdoc} diff --git a/app/code/Magento/Theme/Model/Layout/Config/Reader.php b/app/code/Magento/Theme/Model/Layout/Config/Reader.php index 3af91703ddf0d..1789238d78d16 100644 --- a/app/code/Magento/Theme/Model/Layout/Config/Reader.php +++ b/app/code/Magento/Theme/Model/Layout/Config/Reader.php @@ -5,10 +5,12 @@ */ namespace Magento\Theme\Model\Layout\Config; +use Magento\Framework\Config\Reader\Filesystem; + /** * Page layout config reader */ -class Reader extends \Magento\Framework\Config\Reader\Filesystem +class Reader extends Filesystem { /** * List of identifier attributes for merging diff --git a/app/code/Magento/Theme/Model/Layout/Config/SchemaLocator.php b/app/code/Magento/Theme/Model/Layout/Config/SchemaLocator.php index 0262815bca7ac..59f69940b47a3 100644 --- a/app/code/Magento/Theme/Model/Layout/Config/SchemaLocator.php +++ b/app/code/Magento/Theme/Model/Layout/Config/SchemaLocator.php @@ -8,8 +8,9 @@ namespace Magento\Theme\Model\Layout\Config; use Magento\Framework\Config\Dom\UrnResolver; +use Magento\Framework\Config\SchemaLocatorInterface; -class SchemaLocator implements \Magento\Framework\Config\SchemaLocatorInterface +class SchemaLocator implements SchemaLocatorInterface { /** * Path to corresponding XSD file with validation rules for merged config diff --git a/app/code/Magento/Theme/Model/Layout/Source/Layout.php b/app/code/Magento/Theme/Model/Layout/Source/Layout.php index f39481b824758..73a968ce2bb71 100644 --- a/app/code/Magento/Theme/Model/Layout/Source/Layout.php +++ b/app/code/Magento/Theme/Model/Layout/Source/Layout.php @@ -5,18 +5,22 @@ */ namespace Magento\Theme\Model\Layout\Source; -class Layout implements \Magento\Framework\Option\ArrayInterface +use Magento\Framework\Option\ArrayInterface; +use Magento\Theme\Model\Layout\Config; + +class Layout implements ArrayInterface { /** - * @var \Magento\Theme\Model\Layout\Config + * @var Config */ protected $_config; /** - * @param \Magento\Theme\Model\Layout\Config $config + * @param Config $config */ - public function __construct(\Magento\Theme\Model\Layout\Config $config) - { + public function __construct( + Config $config + ) { $this->_config = $config; } diff --git a/app/code/Magento/Theme/Model/PageLayout/Config/Builder.php b/app/code/Magento/Theme/Model/PageLayout/Config/Builder.php index c998c02d46b3c..45f1a8420a874 100644 --- a/app/code/Magento/Theme/Model/PageLayout/Config/Builder.php +++ b/app/code/Magento/Theme/Model/PageLayout/Config/Builder.php @@ -25,35 +25,11 @@ class Builder implements BuilderInterface { const CACHE_KEY_LAYOUTS = 'THEME_LAYOUTS_FILES_MERGED'; - /** - * @var ConfigFactory - */ - protected $configFactory; - - /** - * @var Aggregated - */ - protected $fileCollector; - - /** - * @var Collection - */ - protected $themeCollection; - /** * @var array */ private $configFiles = []; - /** - * @var Layout|null - */ - private $cacheModel; - /** - * @var SerializerInterface|null - */ - private $serializer; - /** * @param ConfigFactory $configFactory * @param Aggregated $fileCollector @@ -62,15 +38,12 @@ class Builder implements BuilderInterface * @param SerializerInterface|null $serializer */ public function __construct( - ConfigFactory $configFactory, - Aggregated $fileCollector, - Collection $themeCollection, - ?Layout $cacheModel = null, - ?SerializerInterface $serializer = null + protected readonly ConfigFactory $configFactory, + protected readonly Aggregated $fileCollector, + protected readonly Collection $themeCollection, + private ?Layout $cacheModel = null, + private ?SerializerInterface $serializer = null ) { - $this->configFactory = $configFactory; - $this->fileCollector = $fileCollector; - $this->themeCollection = $themeCollection; $this->themeCollection->setItemObjectClass(Data::class); $this->cacheModel = $cacheModel ?? ObjectManager::getInstance()->get(Layout::class); diff --git a/app/code/Magento/Theme/Model/ResourceModel/Design.php b/app/code/Magento/Theme/Model/ResourceModel/Design.php index 6711f4a2117be..49ad6289c101d 100644 --- a/app/code/Magento/Theme/Model/ResourceModel/Design.php +++ b/app/code/Magento/Theme/Model/ResourceModel/Design.php @@ -6,29 +6,29 @@ namespace Magento\Theme\Model\ResourceModel; -use Magento\Framework\Stdlib\DateTime; +use DateTime; +use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Model\AbstractModel; +use Magento\Framework\Model\ResourceModel\Db\AbstractDb; +use Magento\Framework\Model\ResourceModel\Db\Context; +use Magento\Framework\Stdlib\DateTime as FrameworkDateTime; +use Zend_Db_Expr; /** * Design Change Resource Model */ -class Design extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb +class Design extends AbstractDb { /** - * @var DateTime - */ - protected $dateTime; - - /** - * @param \Magento\Framework\Model\ResourceModel\Db\Context $context - * @param DateTime $dateTime + * @param Context $context + * @param FrameworkDateTime $dateTime * @param string $connectionName */ public function __construct( - \Magento\Framework\Model\ResourceModel\Db\Context $context, - DateTime $dateTime, + Context $context, + protected readonly FrameworkDateTime $dateTime, $connectionName = null ) { - $this->dateTime = $dateTime; parent::__construct($context, $connectionName); } @@ -45,11 +45,11 @@ protected function _construct() /** * Perform actions before object save * - * @param \Magento\Framework\Model\AbstractModel $object + * @param AbstractModel $object * @return void - * @throws \Magento\Framework\Exception\LocalizedException + * @throws LocalizedException */ - public function _beforeSave(\Magento\Framework\Model\AbstractModel $object) + public function _beforeSave(AbstractModel $object) { if ($date = $object->getDateFrom()) { $object->setDateFrom($this->dateTime->formatDate($date)); @@ -65,10 +65,10 @@ public function _beforeSave(\Magento\Framework\Model\AbstractModel $object) if ($object->getDateFrom() !== null && $object->getDateTo() !== null - && (new \DateTime($object->getDateFrom()))->getTimestamp() - > (new \DateTime($object->getDateTo()))->getTimestamp() + && (new DateTime($object->getDateFrom()))->getTimestamp() + > (new DateTime($object->getDateTo()))->getTimestamp() ) { - throw new \Magento\Framework\Exception\LocalizedException( + throw new LocalizedException( __('The start date can\'t follow the end date.') ); } @@ -81,16 +81,16 @@ public function _beforeSave(\Magento\Framework\Model\AbstractModel $object) ); if ($check) { - throw new \Magento\Framework\Exception\LocalizedException( + throw new LocalizedException( __('The date range for this design change overlaps another design change for the specified store.') ); } if ($object->getDateFrom() === null) { - $object->setDateFrom(new \Zend_Db_Expr('null')); + $object->setDateFrom(new Zend_Db_Expr('null')); } if ($object->getDateTo() === null) { - $object->setDateTo(new \Zend_Db_Expr('null')); + $object->setDateTo(new Zend_Db_Expr('null')); } parent::_beforeSave($object); diff --git a/app/code/Magento/Theme/Model/ResourceModel/Design/Collection.php b/app/code/Magento/Theme/Model/ResourceModel/Design/Collection.php index 5861d5a1b339d..7abd5656bb405 100644 --- a/app/code/Magento/Theme/Model/ResourceModel/Design/Collection.php +++ b/app/code/Magento/Theme/Model/ResourceModel/Design/Collection.php @@ -5,35 +5,42 @@ */ namespace Magento\Theme\Model\ResourceModel\Design; +use DateTimeInterface; +use Magento\Framework\Data\Collection\Db\FetchStrategyInterface; +use Magento\Framework\Data\Collection\EntityFactory; +use Magento\Framework\DB\Adapter\AdapterInterface; +use Magento\Framework\Event\ManagerInterface; +use Magento\Framework\Model\ResourceModel\Db\AbstractDb; +use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection; +use Magento\Framework\Stdlib\DateTime as FrameworkDateTime; +use Magento\Theme\Model\Design as ModelDesign; +use Magento\Theme\Model\ResourceModel\Design as ResourceDesign; +use Magento\Theme\Model\ResourceModel\Design\Collection as DesignCollection; +use Psr\Log\LoggerInterface; + /** * Core Design resource collection */ -class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection +class Collection extends AbstractCollection { /** - * @var \Magento\Framework\Stdlib\DateTime - */ - protected $dateTime; - - /** - * @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory - * @param \Psr\Log\LoggerInterface $logger - * @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy - * @param \Magento\Framework\Event\ManagerInterface $eventManager - * @param \Magento\Framework\Stdlib\DateTime $dateTime + * @param EntityFactory $entityFactory + * @param LoggerInterface $logger + * @param FetchStrategyInterface $fetchStrategy + * @param ManagerInterface $eventManager + * @param FrameworkDateTime $dateTime * @param mixed $connection - * @param \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource + * @param AbstractDb $resource */ public function __construct( - \Magento\Framework\Data\Collection\EntityFactory $entityFactory, - \Psr\Log\LoggerInterface $logger, - \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy, - \Magento\Framework\Event\ManagerInterface $eventManager, - \Magento\Framework\Stdlib\DateTime $dateTime, - \Magento\Framework\DB\Adapter\AdapterInterface $connection = null, - \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource = null + EntityFactory $entityFactory, + LoggerInterface $logger, + FetchStrategyInterface $fetchStrategy, + ManagerInterface $eventManager, + protected readonly FrameworkDateTime $dateTime, + AdapterInterface $connection = null, + AbstractDb $resource = null ) { - $this->dateTime = $dateTime; parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource); } @@ -44,13 +51,13 @@ public function __construct( */ protected function _construct() { - $this->_init(\Magento\Theme\Model\Design::class, \Magento\Theme\Model\ResourceModel\Design::class); + $this->_init(ModelDesign::class, ResourceDesign::class); } /** * Join store data to collection * - * @return \Magento\Theme\Model\ResourceModel\Design\Collection + * @return DesignCollection */ public function joinStore() { @@ -60,7 +67,7 @@ public function joinStore() /** * Add date filter to collection * - * @param null|int|string|\DateTimeInterface $date + * @param null|int|string|DateTimeInterface $date * @return $this */ public function addDateFilter($date = null) @@ -80,7 +87,7 @@ public function addDateFilter($date = null) * Add store filter to collection * * @param int|array $storeId - * @return \Magento\Theme\Model\ResourceModel\Design\Collection + * @return DesignCollection */ public function addStoreFilter($storeId) { diff --git a/app/code/Magento/Theme/Model/ResourceModel/Design/Config.php b/app/code/Magento/Theme/Model/ResourceModel/Design/Config.php index 9bcd620d86c5d..2984df1c36efa 100644 --- a/app/code/Magento/Theme/Model/ResourceModel/Design/Config.php +++ b/app/code/Magento/Theme/Model/ResourceModel/Design/Config.php @@ -5,10 +5,12 @@ */ namespace Magento\Theme\Model\ResourceModel\Design; +use Magento\Framework\Model\ResourceModel\Db\AbstractDb; + /** * Config Design resource model */ -class Config extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb +class Config extends AbstractDb { /** * Initialize resource model diff --git a/app/code/Magento/Theme/Model/ResourceModel/Design/Config/Collection.php b/app/code/Magento/Theme/Model/ResourceModel/Design/Config/Collection.php index 6db521978cfab..a59bd9c11009e 100644 --- a/app/code/Magento/Theme/Model/ResourceModel/Design/Config/Collection.php +++ b/app/code/Magento/Theme/Model/ResourceModel/Design/Config/Collection.php @@ -16,11 +16,6 @@ class Collection extends ConfigCollection { - /** - * @var \Magento\Theme\Model\Design\Config\ValueProcessor - */ - protected $valueProcessor; - /** * @param EntityFactoryInterface $entityFactory * @param LoggerInterface $logger @@ -35,11 +30,10 @@ public function __construct( LoggerInterface $logger, FetchStrategyInterface $fetchStrategy, ManagerInterface $eventManager, - ValueProcessor $valueProcessor, + protected readonly ValueProcessor $valueProcessor, AdapterInterface $connection = null, AbstractDb $resource = null ) { - $this->valueProcessor = $valueProcessor; parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource); } diff --git a/app/code/Magento/Theme/Model/ResourceModel/Design/Config/Scope/Collection.php b/app/code/Magento/Theme/Model/ResourceModel/Design/Config/Scope/Collection.php index e80cebc40b822..e931a6b11e72b 100644 --- a/app/code/Magento/Theme/Model/ResourceModel/Design/Config/Scope/Collection.php +++ b/app/code/Magento/Theme/Model/ResourceModel/Design/Config/Scope/Collection.php @@ -7,36 +7,19 @@ use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\App\ScopeTreeProviderInterface; +use Magento\Framework\Data\Collection as DataCollection; use Magento\Framework\Data\Collection\EntityFactoryInterface; +use Magento\Framework\DataObject; use Magento\Theme\Model\Design\Config\MetadataProviderInterface; use Magento\Theme\Model\Design\Config\ValueProcessor; +use Magento\Theme\Model\ResourceModel\Design\Config\Scope\Collection as DesignConfigScopeCollection; /** * Data collection * */ -class Collection extends \Magento\Framework\Data\Collection +class Collection extends DataCollection { - /** - * @var ScopeTreeProviderInterface - */ - protected $scopeTree; - - /** - * @var MetadataProviderInterface - */ - protected $metadataProvider; - - /** - * @var ScopeConfigInterface - */ - protected $appConfig; - - /** - * @var ValueProcessor - */ - protected $valueProcessor; - /** * Collection constructor * @@ -48,16 +31,12 @@ class Collection extends \Magento\Framework\Data\Collection */ public function __construct( EntityFactoryInterface $entityFactory, - ScopeTreeProviderInterface $scopeTree, - MetadataProviderInterface $metadataProvider, - ScopeConfigInterface $appConfig, - ValueProcessor $valueProcessor + protected readonly ScopeTreeProviderInterface $scopeTree, + protected readonly MetadataProviderInterface $metadataProvider, + protected readonly ScopeConfigInterface $appConfig, + protected readonly ValueProcessor $valueProcessor ) { parent::__construct($entityFactory); - $this->scopeTree = $scopeTree; - $this->metadataProvider = $metadataProvider; - $this->appConfig = $appConfig; - $this->valueProcessor = $valueProcessor; } /** @@ -65,7 +44,7 @@ public function __construct( * * @param bool $printQuery * @param bool $logQuery - * @return \Magento\Theme\Model\ResourceModel\Design\Config\Scope\Collection + * @return DesignConfigScopeCollection * * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ @@ -130,7 +109,7 @@ protected function prepareItemData(array $websiteScope = [], array $groupScope = $result = array_merge($result, $this->getScopeData($websiteScope, $groupScope, $storeScope)); - $this->_addItem(new \Magento\Framework\DataObject($result)); + $this->_addItem(new DataObject($result)); } /** diff --git a/app/code/Magento/Theme/Model/ResourceModel/Theme.php b/app/code/Magento/Theme/Model/ResourceModel/Theme.php index 9b3a13d7a4220..4f2de0587d252 100644 --- a/app/code/Magento/Theme/Model/ResourceModel/Theme.php +++ b/app/code/Magento/Theme/Model/ResourceModel/Theme.php @@ -5,10 +5,12 @@ */ namespace Magento\Theme\Model\ResourceModel; +use Magento\Framework\Model\ResourceModel\Db\AbstractDb; + /** * Theme resource model */ -class Theme extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb +class Theme extends AbstractDb { /** * Resource initialization diff --git a/app/code/Magento/Theme/Model/ResourceModel/Theme/Collection.php b/app/code/Magento/Theme/Model/ResourceModel/Theme/Collection.php index f9dd501520109..e9723add90cf1 100644 --- a/app/code/Magento/Theme/Model/ResourceModel/Theme/Collection.php +++ b/app/code/Magento/Theme/Model/ResourceModel/Theme/Collection.php @@ -5,12 +5,20 @@ */ namespace Magento\Theme\Model\ResourceModel\Theme; +use Magento\Framework\App\Area; +use Magento\Framework\Data\Collection as DataCollection; +use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection; +use Magento\Framework\View\Design\Theme\Label\ListInterface as ThemeLabelListInterface; +use Magento\Framework\View\Design\Theme\ListInterface as ThemeListInterface; +use Magento\Framework\View\Design\ThemeInterface; +use Magento\Theme\Model\ResourceModel\Theme as ResourceTheme; +use Magento\Theme\Model\ResourceModel\Theme\Collection as ThemeCollection; +use Magento\Theme\Model\Theme as ModelTheme; + /** * Theme collection */ -class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection implements - \Magento\Framework\View\Design\Theme\Label\ListInterface, - \Magento\Framework\View\Design\Theme\ListInterface +class Collection extends AbstractCollection implements ThemeLabelListInterface, ThemeListInterface { /** * Default page size @@ -29,7 +37,7 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\Ab */ protected function _construct() { - $this->_init(\Magento\Theme\Model\Theme::class, \Magento\Theme\Model\ResourceModel\Theme::class); + $this->_init(ModelTheme::class, ResourceTheme::class); } /** @@ -53,7 +61,7 @@ public function addParentTitle() * @param string $area * @return $this */ - public function addAreaFilter($area = \Magento\Framework\App\Area::AREA_FRONTEND) + public function addAreaFilter($area = Area::AREA_FRONTEND) { $this->getSelect()->where('main_table.area=?', $area); return $this; @@ -103,8 +111,8 @@ public function filterVisibleThemes() { $this->addTypeFilter( [ - \Magento\Framework\View\Design\ThemeInterface::TYPE_PHYSICAL, - \Magento\Framework\View\Design\ThemeInterface::TYPE_VIRTUAL, + ThemeInterface::TYPE_PHYSICAL, + ThemeInterface::TYPE_VIRTUAL, ] ); return $this; @@ -134,7 +142,7 @@ public function toOptionHash() * Get theme from DB by area and theme_path * * @param string $fullPath - * @return \Magento\Theme\Model\Theme + * @return ModelTheme */ public function getThemeByFullPath($fullPath) { @@ -160,15 +168,15 @@ public function setPageSize($size = self::DEFAULT_PAGE_SIZE) /** * Update all child themes relations * - * @param \Magento\Framework\View\Design\ThemeInterface $themeModel + * @param ThemeInterface $themeModel * @return $this */ - public function updateChildRelations(\Magento\Framework\View\Design\ThemeInterface $themeModel) + public function updateChildRelations(ThemeInterface $themeModel) { $parentThemeId = $themeModel->getParentId(); $this->addFieldToFilter('parent_id', ['eq' => $themeModel->getId()])->load(); - /** @var $theme \Magento\Framework\View\Design\ThemeInterface */ + /** @var ThemeInterface $theme */ foreach ($this->getItems() as $theme) { $theme->setParentId($parentThemeId)->save(); } @@ -185,12 +193,12 @@ public function updateChildRelations(\Magento\Framework\View\Design\ThemeInterfa */ public function filterPhysicalThemes( $page = null, - $pageSize = \Magento\Theme\Model\ResourceModel\Theme\Collection::DEFAULT_PAGE_SIZE + $pageSize = ThemeCollection::DEFAULT_PAGE_SIZE ) { $this->addAreaFilter( - \Magento\Framework\App\Area::AREA_FRONTEND + Area::AREA_FRONTEND )->addTypeFilter( - \Magento\Framework\View\Design\ThemeInterface::TYPE_PHYSICAL + ThemeInterface::TYPE_PHYSICAL ); if ($page) { $this->setPageSize($pageSize)->setCurPage($page); @@ -206,8 +214,8 @@ public function filterPhysicalThemes( * @return $this */ public function filterThemeCustomizations( - $area = \Magento\Framework\App\Area::AREA_FRONTEND, - $type = \Magento\Framework\View\Design\ThemeInterface::TYPE_VIRTUAL + $area = Area::AREA_FRONTEND, + $type = ThemeInterface::TYPE_VIRTUAL ) { $this->addAreaFilter($area)->addTypeFilter($type); return $this; @@ -228,7 +236,7 @@ public function getLabels() public function loadRegisteredThemes() { $this->_reset()->clear(); - return $this->setOrder('theme_title', \Magento\Framework\Data\Collection::SORT_ORDER_ASC) - ->filterVisibleThemes()->addAreaFilter(\Magento\Framework\App\Area::AREA_FRONTEND); + return $this->setOrder('theme_title', DataCollection::SORT_ORDER_ASC) + ->filterVisibleThemes()->addAreaFilter(Area::AREA_FRONTEND); } } diff --git a/app/code/Magento/Theme/Model/ResourceModel/Theme/Customization/Update.php b/app/code/Magento/Theme/Model/ResourceModel/Theme/Customization/Update.php index 5cb0fbb7a3728..63c5e6ad2b3fc 100644 --- a/app/code/Magento/Theme/Model/ResourceModel/Theme/Customization/Update.php +++ b/app/code/Magento/Theme/Model/ResourceModel/Theme/Customization/Update.php @@ -5,10 +5,12 @@ */ namespace Magento\Theme\Model\ResourceModel\Theme\Customization; +use Magento\Framework\Model\ResourceModel\Db\AbstractDb; + /** * Theme customization link resource model */ -class Update extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb +class Update extends AbstractDb { /** * Resource initialization diff --git a/app/code/Magento/Theme/Model/ResourceModel/Theme/Data/Collection.php b/app/code/Magento/Theme/Model/ResourceModel/Theme/Data/Collection.php index 5a365501382d6..5490b53af87d3 100644 --- a/app/code/Magento/Theme/Model/ResourceModel/Theme/Data/Collection.php +++ b/app/code/Magento/Theme/Model/ResourceModel/Theme/Data/Collection.php @@ -5,18 +5,22 @@ */ namespace Magento\Theme\Model\ResourceModel\Theme\Data; +use Magento\Framework\View\Design\Theme\Label\ListInterface as ThemeLabelListInterface; +use Magento\Framework\View\Design\Theme\ListInterface as ThemeListInterface; +use Magento\Theme\Model\ResourceModel\Theme as ResourceTheme; +use Magento\Theme\Model\ResourceModel\Theme\Collection as ThemeCollection; +use Magento\Theme\Model\Theme\Data as ModelThemeData; + /** * Theme data collection */ -class Collection extends \Magento\Theme\Model\ResourceModel\Theme\Collection implements - \Magento\Framework\View\Design\Theme\Label\ListInterface, - \Magento\Framework\View\Design\Theme\ListInterface +class Collection extends ThemeCollection implements ThemeLabelListInterface, ThemeListInterface { /** * @inheritdoc */ protected function _construct() { - $this->_init(\Magento\Theme\Model\Theme\Data::class, \Magento\Theme\Model\ResourceModel\Theme::class); + $this->_init(ModelThemeData::class, ResourceTheme::class); } } diff --git a/app/code/Magento/Theme/Model/ResourceModel/Theme/File.php b/app/code/Magento/Theme/Model/ResourceModel/Theme/File.php index a2627fc895fac..be8b0a7355639 100644 --- a/app/code/Magento/Theme/Model/ResourceModel/Theme/File.php +++ b/app/code/Magento/Theme/Model/ResourceModel/Theme/File.php @@ -5,10 +5,12 @@ */ namespace Magento\Theme\Model\ResourceModel\Theme; +use Magento\Framework\Model\ResourceModel\Db\AbstractDb; + /** * Theme files resource model */ -class File extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb +class File extends AbstractDb { /** * Resource initialization diff --git a/app/code/Magento/Theme/Model/ResourceModel/Theme/File/Collection.php b/app/code/Magento/Theme/Model/ResourceModel/Theme/File/Collection.php index c414b7e928b05..1553b2e9fdd46 100644 --- a/app/code/Magento/Theme/Model/ResourceModel/Theme/File/Collection.php +++ b/app/code/Magento/Theme/Model/ResourceModel/Theme/File/Collection.php @@ -5,11 +5,16 @@ */ namespace Magento\Theme\Model\ResourceModel\Theme\File; +use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection; +use Magento\Framework\View\Design\Theme\File\CollectionInterface as ThemeFileCollectionInterface; +use Magento\Framework\View\Design\ThemeInterface; +use Magento\Theme\Model\ResourceModel\Theme\File as ResourceThemeFile; +use Magento\Theme\Model\Theme\File as ModelThemeFile; + /** * Theme files collection */ -class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection implements - \Magento\Framework\View\Design\Theme\File\CollectionInterface +class Collection extends AbstractCollection implements ThemeFileCollectionInterface { /** * Collection initialization @@ -18,7 +23,7 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\Ab */ protected function _construct() { - $this->_init(\Magento\Theme\Model\Theme\File::class, \Magento\Theme\Model\ResourceModel\Theme\File::class); + $this->_init(ModelThemeFile::class, ResourceThemeFile::class); } /** @@ -50,10 +55,10 @@ public function setDefaultOrder($direction = self::SORT_ORDER_ASC) /** * Filter out files that do not belong to a theme * - * @param \Magento\Framework\View\Design\ThemeInterface $theme + * @param ThemeInterface $theme * @return $this */ - public function addThemeFilter(\Magento\Framework\View\Design\ThemeInterface $theme) + public function addThemeFilter(ThemeInterface $theme) { $this->addFieldToFilter('theme_id', $theme->getId()); return $this; diff --git a/app/code/Magento/Theme/Model/ResourceModel/Theme/Grid/Collection.php b/app/code/Magento/Theme/Model/ResourceModel/Theme/Grid/Collection.php index 4ee6880c8190d..f944e549d4cd6 100644 --- a/app/code/Magento/Theme/Model/ResourceModel/Theme/Grid/Collection.php +++ b/app/code/Magento/Theme/Model/ResourceModel/Theme/Grid/Collection.php @@ -5,12 +5,15 @@ */ namespace Magento\Theme\Model\ResourceModel\Theme\Grid; +use Magento\Framework\App\Area; +use Magento\Theme\Model\ResourceModel\Theme\Collection as ThemeCollection; + /** * Theme grid collection * @deprecated 101.0.0 * @see \Magento\Theme\Ui\Component\Theme\DataProvider\SearchResult */ -class Collection extends \Magento\Theme\Model\ResourceModel\Theme\Collection +class Collection extends ThemeCollection { /** * Add area filter @@ -19,8 +22,8 @@ class Collection extends \Magento\Theme\Model\ResourceModel\Theme\Collection */ protected function _initSelect() { - \Magento\Theme\Model\ResourceModel\Theme\Collection::_initSelect(); - $this->filterVisibleThemes()->addAreaFilter(\Magento\Framework\App\Area::AREA_FRONTEND)->addParentTitle(); + ThemeCollection::_initSelect(); + $this->filterVisibleThemes()->addAreaFilter(Area::AREA_FRONTEND)->addParentTitle(); return $this; } } diff --git a/app/code/Magento/Theme/Model/Source/InitialThemeSource.php b/app/code/Magento/Theme/Model/Source/InitialThemeSource.php index bec751845ac4e..2f60de976cd2b 100644 --- a/app/code/Magento/Theme/Model/Source/InitialThemeSource.php +++ b/app/code/Magento/Theme/Model/Source/InitialThemeSource.php @@ -18,27 +18,6 @@ */ class InitialThemeSource implements ConfigSourceInterface { - /** - * A deployment config. - * - * @var DeploymentConfig - */ - private $deploymentConfig; - - /** - * A theme factory. - * - * @var ThemeFactory - */ - private $themeFactory; - - /** - * A data object factory. - * - * @var DataObjectFactory - */ - private $dataObjectFactory; - /** * Array with theme data. * @@ -52,13 +31,10 @@ class InitialThemeSource implements ConfigSourceInterface * @param DataObjectFactory $dataObjectFactory A data object factory */ public function __construct( - DeploymentConfig $deploymentConfig, - ThemeFactory $themeFactory, - DataObjectFactory $dataObjectFactory + private readonly DeploymentConfig $deploymentConfig, + private readonly ThemeFactory $themeFactory, + private readonly DataObjectFactory $dataObjectFactory ) { - $this->deploymentConfig = $deploymentConfig; - $this->themeFactory = $themeFactory; - $this->dataObjectFactory = $dataObjectFactory; } /** diff --git a/app/code/Magento/Theme/Model/Theme.php b/app/code/Magento/Theme/Model/Theme.php index b81fa117bdf14..71c5efe4bd38e 100644 --- a/app/code/Magento/Theme/Model/Theme.php +++ b/app/code/Magento/Theme/Model/Theme.php @@ -5,9 +5,23 @@ */ namespace Magento\Theme\Model; +use InvalidArgumentException; use Magento\Framework\App\ObjectManager; +use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Model\AbstractModel; +use Magento\Framework\Model\Context; +use Magento\Framework\Registry; +use Magento\Framework\View\Design\Theme\Customization; +use Magento\Framework\View\Design\Theme\CustomizationFactory; +use Magento\Framework\View\Design\Theme\Domain\Factory; +use Magento\Framework\View\Design\Theme\FlyweightFactory; +use Magento\Framework\View\Design\Theme\Image; +use Magento\Framework\View\Design\Theme\ImageFactory; +use Magento\Framework\View\Design\Theme\Validator; use Magento\Framework\View\Design\ThemeInterface; use Magento\Theme\Model\ResourceModel\Theme\Collection as ThemeCollection; +use Magento\Theme\Model\Theme\Domain\Staging; +use Magento\Theme\Model\Theme\Domain\Virtual; /** * Theme model class @@ -33,7 +47,7 @@ * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class Theme extends \Magento\Framework\Model\AbstractModel implements ThemeInterface +class Theme extends AbstractModel implements ThemeInterface { /** * {@inheritdoc} @@ -50,40 +64,35 @@ class Theme extends \Magento\Framework\Model\AbstractModel implements ThemeInter protected $_eventObject = 'theme'; /** - * @var \Magento\Framework\View\Design\Theme\FlyweightFactory + * @var FlyweightFactory */ protected $_themeFactory; /** - * @var \Magento\Framework\View\Design\Theme\Domain\Factory + * @var Factory */ protected $_domainFactory; /** - * @var \Magento\Framework\View\Design\Theme\ImageFactory + * @var ImageFactory */ protected $_imageFactory; /** - * @var \Magento\Framework\View\Design\Theme\Validator + * @var Validator */ protected $_validator; /** - * @var \Magento\Framework\View\Design\Theme\Customization + * @var Customization */ protected $_customization; /** - * @var \Magento\Framework\View\Design\Theme\CustomizationFactory + * @var CustomizationFactory */ protected $_customFactory; - /** - * @var ThemeFactory - */ - private $themeModelFactory; - /** * @var ThemeInterface[] */ @@ -92,31 +101,31 @@ class Theme extends \Magento\Framework\Model\AbstractModel implements ThemeInter /** * Initialize dependencies * - * @param \Magento\Framework\Model\Context $context - * @param \Magento\Framework\Registry $registry - * @param \Magento\Framework\View\Design\Theme\FlyweightFactory $themeFactory - * @param \Magento\Framework\View\Design\Theme\Domain\Factory $domainFactory - * @param \Magento\Framework\View\Design\Theme\ImageFactory $imageFactory - * @param \Magento\Framework\View\Design\Theme\Validator $validator - * @param \Magento\Framework\View\Design\Theme\CustomizationFactory $customizationFactory - * @param \Magento\Theme\Model\ResourceModel\Theme $resource - * @param \Magento\Theme\Model\ResourceModel\Theme\Collection $resourceCollection + * @param Context $context + * @param Registry $registry + * @param FlyweightFactory $themeFactory + * @param Factory $domainFactory + * @param ImageFactory $imageFactory + * @param Validator $validator + * @param CustomizationFactory $customizationFactory + * @param ResourceModel\Theme|null $resource + * @param ThemeCollection|null $resourceCollection * @param array $data - * @param ThemeFactory $themeModelFactory + * @param ThemeFactory|null $themeModelFactory * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( - \Magento\Framework\Model\Context $context, - \Magento\Framework\Registry $registry, - \Magento\Framework\View\Design\Theme\FlyweightFactory $themeFactory, - \Magento\Framework\View\Design\Theme\Domain\Factory $domainFactory, - \Magento\Framework\View\Design\Theme\ImageFactory $imageFactory, - \Magento\Framework\View\Design\Theme\Validator $validator, - \Magento\Framework\View\Design\Theme\CustomizationFactory $customizationFactory, - \Magento\Theme\Model\ResourceModel\Theme $resource = null, + Context $context, + Registry $registry, + FlyweightFactory $themeFactory, + Factory $domainFactory, + ImageFactory $imageFactory, + Validator $validator, + CustomizationFactory $customizationFactory, + ResourceModel\Theme $resource = null, ThemeCollection $resourceCollection = null, array $data = [], - ThemeFactory $themeModelFactory = null + private ?ThemeFactory $themeModelFactory = null ) { parent::__construct($context, $registry, $resource, $resourceCollection, $data); $this->_themeFactory = $themeFactory; @@ -135,13 +144,13 @@ public function __construct( */ protected function _construct() { - $this->_init(\Magento\Theme\Model\ResourceModel\Theme::class); + $this->_init(ResourceModel\Theme::class); } /** * Get theme image model * - * @return \Magento\Framework\View\Design\Theme\Image + * @return Image */ public function getThemeImage() { @@ -149,7 +158,7 @@ public function getThemeImage() } /** - * @return \Magento\Framework\View\Design\Theme\Customization + * @return Customization */ public function getCustomization() { @@ -305,13 +314,13 @@ public function getCode() * Get one of theme domain models * * @param int|null $type - * @return \Magento\Theme\Model\Theme\Domain\Virtual|\Magento\Theme\Model\Theme\Domain\Staging - * @throws \InvalidArgumentException + * @return Virtual|Staging + * @throws InvalidArgumentException */ public function getDomainModel($type = null) { if ($type !== null && $type != $this->getType()) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( sprintf( 'Invalid domain model "%s" requested for theme "%s" of type "%s"', $type, @@ -328,13 +337,13 @@ public function getDomainModel($type = null) * Validate theme data * * @return $this - * @throws \Magento\Framework\Exception\LocalizedException + * @throws LocalizedException */ protected function _validate() { if (!$this->_validator->validate($this)) { $messages = $this->_validator->getErrorMessages(); - throw new \Magento\Framework\Exception\LocalizedException(__(implode(PHP_EOL, reset($messages)))); + throw new LocalizedException(__(implode(PHP_EOL, reset($messages)))); } return $this; } @@ -429,7 +438,7 @@ public function populateFromArray(array $data) /** * Create Theme instance * - * @return \Magento\Theme\Model\Theme + * @return Theme */ private function createThemeInstance() { diff --git a/app/code/Magento/Theme/Model/Theme/Collection.php b/app/code/Magento/Theme/Model/Theme/Collection.php index 848dc29e71e51..0137361beac6f 100644 --- a/app/code/Magento/Theme/Model/Theme/Collection.php +++ b/app/code/Magento/Theme/Model/Theme/Collection.php @@ -5,12 +5,14 @@ */ namespace Magento\Theme\Model\Theme; +use Magento\Framework\View\Design\Theme\ThemeList; + /** * Theme filesystem collection * * @deprecated 100.2.0 There is no need for the class provided themes list to be in Theme module */ -class Collection extends \Magento\Framework\View\Design\Theme\ThemeList +class Collection extends ThemeList { // } diff --git a/app/code/Magento/Theme/Model/Theme/Customization/Config.php b/app/code/Magento/Theme/Model/Theme/Customization/Config.php index ebe805fc10519..5021759ef9839 100644 --- a/app/code/Magento/Theme/Model/Theme/Customization/Config.php +++ b/app/code/Magento/Theme/Model/Theme/Customization/Config.php @@ -9,7 +9,10 @@ */ namespace Magento\Theme\Model\Theme\Customization; -class Config implements \Magento\Framework\View\Design\Theme\Customization\ConfigInterface +use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\View\Design\Theme\Customization\ConfigInterface; + +class Config implements ConfigInterface { /** * XML path to definitions of customization services @@ -17,16 +20,11 @@ class Config implements \Magento\Framework\View\Design\Theme\Customization\Confi const XML_PATH_CUSTOM_FILES = 'theme/customization'; /** - * @var \Magento\Framework\App\Config\ScopeConfigInterface + * @param ScopeConfigInterface $config */ - protected $config; - - /** - * @param \Magento\Framework\App\Config\ScopeConfigInterface $config - */ - public function __construct(\Magento\Framework\App\Config\ScopeConfigInterface $config) - { - $this->config = $config; + public function __construct( + protected readonly ScopeConfigInterface $config + ) { } /** diff --git a/app/code/Magento/Theme/Model/Theme/Customization/File/CustomCss.php b/app/code/Magento/Theme/Model/Theme/Customization/File/CustomCss.php index 45cc72e80c390..ece5a2e7c5899 100644 --- a/app/code/Magento/Theme/Model/Theme/Customization/File/CustomCss.php +++ b/app/code/Magento/Theme/Model/Theme/Customization/File/CustomCss.php @@ -9,7 +9,10 @@ */ namespace Magento\Theme\Model\Theme\Customization\File; -class CustomCss extends \Magento\Framework\View\Design\Theme\Customization\AbstractFile +use Magento\Framework\View\Design\Theme\Customization\AbstractFile; +use Magento\Framework\View\Design\Theme\FileInterface; + +class CustomCss extends AbstractFile { /**#@+ * Custom CSS file type customization @@ -49,7 +52,7 @@ public function getContentType() /** * {@inheritdoc} */ - protected function _prepareFileName(\Magento\Framework\View\Design\Theme\FileInterface $file) + protected function _prepareFileName(FileInterface $file) { if (!$file->getFileName()) { $file->setFileName(self::FILE_NAME); @@ -59,7 +62,7 @@ protected function _prepareFileName(\Magento\Framework\View\Design\Theme\FileInt /** * {@inheritdoc} */ - protected function _prepareSortOrder(\Magento\Framework\View\Design\Theme\FileInterface $file) + protected function _prepareSortOrder(FileInterface $file) { $file->setData('sort_order', self::SORT_ORDER); } diff --git a/app/code/Magento/Theme/Model/Theme/Data.php b/app/code/Magento/Theme/Model/Theme/Data.php index 336989f065354..31b0794169349 100644 --- a/app/code/Magento/Theme/Model/Theme/Data.php +++ b/app/code/Magento/Theme/Model/Theme/Data.php @@ -5,12 +5,15 @@ */ namespace Magento\Theme\Model\Theme; +use Magento\Framework\View\Design\ThemeInterface; +use Magento\Theme\Model\Theme; + /** * Data model for themes * - * @method \Magento\Framework\View\Design\ThemeInterface setArea(string $area) + * @method ThemeInterface setArea(string $area) */ -class Data extends \Magento\Theme\Model\Theme +class Data extends Theme { /** * {@inheritdoc} diff --git a/app/code/Magento/Theme/Model/Theme/Data/Collection.php b/app/code/Magento/Theme/Model/Theme/Data/Collection.php index a6fe447c13333..4350744454f73 100644 --- a/app/code/Magento/Theme/Model/Theme/Data/Collection.php +++ b/app/code/Magento/Theme/Model/Theme/Data/Collection.php @@ -6,16 +6,18 @@ namespace Magento\Theme\Model\Theme\Data; use Magento\Framework\View\Design\Theme\ListInterface; +use Magento\Theme\Model\Theme\Collection as ThemeCollection; +use Magento\Theme\Model\Theme\Data as ThemeData; /** * Theme filesystem data collection */ -class Collection extends \Magento\Theme\Model\Theme\Collection implements ListInterface +class Collection extends ThemeCollection implements ListInterface { /** * Model of collection item * * @var string */ - protected $_itemObjectClass = \Magento\Theme\Model\Theme\Data::class; + protected $_itemObjectClass = ThemeData::class; } diff --git a/app/code/Magento/Theme/Model/Theme/Domain/Physical.php b/app/code/Magento/Theme/Model/Theme/Domain/Physical.php index 59ffd2f436398..a2f31dbe57939 100644 --- a/app/code/Magento/Theme/Model/Theme/Domain/Physical.php +++ b/app/code/Magento/Theme/Model/Theme/Domain/Physical.php @@ -9,41 +9,48 @@ */ namespace Magento\Theme\Model\Theme\Domain; -class Physical implements \Magento\Framework\View\Design\Theme\Domain\PhysicalInterface +use Magento\Framework\App\Area; +use Magento\Framework\View\Design\Theme\Domain\PhysicalInterface; +use Magento\Framework\View\Design\ThemeInterface; +use Magento\Theme\Model\CopyService; +use Magento\Theme\Model\ResourceModel\Theme\Collection as ThemeCollection; +use Magento\Theme\Model\ThemeFactory; + +class Physical implements PhysicalInterface { /** * Physical theme model instance * - * @var \Magento\Framework\View\Design\ThemeInterface + * @var ThemeInterface */ protected $_theme; /** - * @var \Magento\Theme\Model\ThemeFactory + * @var ThemeFactory */ protected $_themeFactory; /** - * @var \Magento\Theme\Model\CopyService + * @var CopyService */ protected $_themeCopyService; /** - * @var \Magento\Theme\Model\ResourceModel\Theme\Collection + * @var ThemeCollection */ protected $_themeCollection; /** - * @param \Magento\Framework\View\Design\ThemeInterface $theme - * @param \Magento\Theme\Model\ThemeFactory $themeFactory - * @param \Magento\Theme\Model\CopyService $themeCopyService - * @param \Magento\Theme\Model\ResourceModel\Theme\Collection $themeCollection + * @param ThemeInterface $theme + * @param ThemeFactory $themeFactory + * @param CopyService $themeCopyService + * @param ThemeCollection $themeCollection */ public function __construct( - \Magento\Framework\View\Design\ThemeInterface $theme, - \Magento\Theme\Model\ThemeFactory $themeFactory, - \Magento\Theme\Model\CopyService $themeCopyService, - \Magento\Theme\Model\ResourceModel\Theme\Collection $themeCollection + ThemeInterface $theme, + ThemeFactory $themeFactory, + CopyService $themeCopyService, + ThemeCollection $themeCollection ) { $this->_theme = $theme; $this->_themeFactory = $themeFactory; @@ -54,8 +61,8 @@ public function __construct( /** * Create theme customization * - * @param \Magento\Framework\View\Design\ThemeInterface $theme - * @return \Magento\Framework\View\Design\ThemeInterface + * @param ThemeInterface $theme + * @return ThemeInterface */ public function createVirtualTheme($theme) { @@ -64,9 +71,9 @@ public function createVirtualTheme($theme) $themeData['theme_id'] = null; $themeData['theme_path'] = null; $themeData['theme_title'] = $this->_getVirtualThemeTitle($theme); - $themeData['type'] = \Magento\Framework\View\Design\ThemeInterface::TYPE_VIRTUAL; + $themeData['type'] = ThemeInterface::TYPE_VIRTUAL; - /** @var $themeCustomization \Magento\Framework\View\Design\ThemeInterface */ + /** @var ThemeInterface $themeCustomization */ $themeCustomization = $this->_themeFactory->create()->setData($themeData); $themeCustomization->getThemeImage()->createPreviewImageCopy($theme); $themeCustomization->save(); @@ -79,15 +86,15 @@ public function createVirtualTheme($theme) /** * Get virtual theme title * - * @param \Magento\Framework\View\Design\ThemeInterface $theme + * @param ThemeInterface $theme * @return string */ protected function _getVirtualThemeTitle($theme) { $themeCopyCount = $this->_themeCollection->addAreaFilter( - \Magento\Framework\App\Area::AREA_FRONTEND + Area::AREA_FRONTEND )->addTypeFilter( - \Magento\Framework\View\Design\ThemeInterface::TYPE_VIRTUAL + ThemeInterface::TYPE_VIRTUAL )->addFilter( 'parent_id', $theme->getId() diff --git a/app/code/Magento/Theme/Model/Theme/Domain/Staging.php b/app/code/Magento/Theme/Model/Theme/Domain/Staging.php index 62c6e5f3c3bd5..fc8236083f987 100644 --- a/app/code/Magento/Theme/Model/Theme/Domain/Staging.php +++ b/app/code/Magento/Theme/Model/Theme/Domain/Staging.php @@ -9,27 +9,31 @@ */ namespace Magento\Theme\Model\Theme\Domain; -class Staging implements \Magento\Framework\View\Design\Theme\Domain\StagingInterface +use Magento\Framework\View\Design\Theme\Domain\StagingInterface; +use Magento\Framework\View\Design\ThemeInterface; +use Magento\Theme\Model\CopyService; + +class Staging implements StagingInterface { /** * Staging theme model instance * - * @var \Magento\Framework\View\Design\ThemeInterface + * @var ThemeInterface */ protected $_theme; /** - * @var \Magento\Theme\Model\CopyService + * @var CopyService */ protected $_themeCopyService; /** - * @param \Magento\Framework\View\Design\ThemeInterface $theme - * @param \Magento\Theme\Model\CopyService $themeCopyService + * @param ThemeInterface $theme + * @param CopyService $themeCopyService */ public function __construct( - \Magento\Framework\View\Design\ThemeInterface $theme, - \Magento\Theme\Model\CopyService $themeCopyService + ThemeInterface $theme, + CopyService $themeCopyService ) { $this->_theme = $theme; $this->_themeCopyService = $themeCopyService; @@ -38,7 +42,7 @@ public function __construct( /** * Copy changes from 'staging' theme * - * @return \Magento\Framework\View\Design\Theme\Domain\StagingInterface + * @return StagingInterface */ public function updateFromStagingTheme() { diff --git a/app/code/Magento/Theme/Model/Theme/Domain/Virtual.php b/app/code/Magento/Theme/Model/Theme/Domain/Virtual.php index 5c58e73437c74..27ec8de6e96b1 100644 --- a/app/code/Magento/Theme/Model/Theme/Domain/Virtual.php +++ b/app/code/Magento/Theme/Model/Theme/Domain/Virtual.php @@ -9,50 +9,56 @@ */ namespace Magento\Theme\Model\Theme\Domain; -class Virtual implements \Magento\Framework\View\Design\Theme\Domain\VirtualInterface +use Magento\Framework\View\Design\Theme\Domain\VirtualInterface; +use Magento\Framework\View\Design\ThemeInterface; +use Magento\Theme\Model\Config\Customization; +use Magento\Theme\Model\CopyService; +use Magento\Theme\Model\ThemeFactory; + +class Virtual implements VirtualInterface { /** * Virtual theme model instance * - * @var \Magento\Framework\View\Design\ThemeInterface + * @var ThemeInterface */ protected $_theme; /** - * @var \Magento\Theme\Model\ThemeFactory $themeFactory + * @var ThemeFactory $themeFactory */ protected $_themeFactory; /** * Staging theme model instance * - * @var \Magento\Framework\View\Design\ThemeInterface + * @var ThemeInterface */ protected $_stagingTheme; /** - * @var \Magento\Theme\Model\CopyService + * @var CopyService */ protected $_themeCopyService; /** * Theme customization config * - * @var \Magento\Theme\Model\Config\Customization + * @var Customization */ protected $_customizationConfig; /** - * @param \Magento\Framework\View\Design\ThemeInterface $theme - * @param \Magento\Theme\Model\ThemeFactory $themeFactory - * @param \Magento\Theme\Model\CopyService $themeCopyService - * @param \Magento\Theme\Model\Config\Customization $customizationConfig + * @param ThemeInterface $theme + * @param ThemeFactory $themeFactory + * @param CopyService $themeCopyService + * @param Customization $customizationConfig */ public function __construct( - \Magento\Framework\View\Design\ThemeInterface $theme, - \Magento\Theme\Model\ThemeFactory $themeFactory, - \Magento\Theme\Model\CopyService $themeCopyService, - \Magento\Theme\Model\Config\Customization $customizationConfig + ThemeInterface $theme, + ThemeFactory $themeFactory, + CopyService $themeCopyService, + Customization $customizationConfig ) { $this->_theme = $theme; $this->_themeFactory = $themeFactory; @@ -63,7 +69,7 @@ public function __construct( /** * Get 'staging' theme * - * @return \Magento\Framework\View\Design\ThemeInterface + * @return ThemeInterface */ public function getStagingTheme() { @@ -80,11 +86,11 @@ public function getStagingTheme() /** * Get 'physical' theme * - * @return \Magento\Framework\View\Design\ThemeInterface + * @return ThemeInterface */ public function getPhysicalTheme() { - /** @var $parentTheme \Magento\Framework\View\Design\ThemeInterface */ + /** @var ThemeInterface $parentTheme */ $parentTheme = $this->_theme->getParentTheme(); while ($parentTheme && !$parentTheme->isPhysical()) { $parentTheme = $parentTheme->getParentTheme(); @@ -110,7 +116,7 @@ public function isAssigned() /** * Create 'staging' theme associated with current 'virtual' theme * - * @return \Magento\Framework\View\Design\ThemeInterface + * @return ThemeInterface */ protected function _createStagingTheme() { @@ -122,7 +128,7 @@ protected function _createStagingTheme() 'theme_title' => sprintf('%s - Staging', $this->_theme->getThemeTitle()), 'preview_image' => $this->_theme->getPreviewImage(), 'is_featured' => $this->_theme->getIsFeatured(), - 'type' => \Magento\Framework\View\Design\ThemeInterface::TYPE_STAGING, + 'type' => ThemeInterface::TYPE_STAGING, ] ); $stagingTheme->save(); diff --git a/app/code/Magento/Theme/Model/Theme/File.php b/app/code/Magento/Theme/Model/Theme/File.php index 4907924ba119c..ff86121f1e9e3 100644 --- a/app/code/Magento/Theme/Model/Theme/File.php +++ b/app/code/Magento/Theme/Model/Theme/File.php @@ -5,9 +5,19 @@ */ namespace Magento\Theme\Model\Theme; +use Magento\Framework\Data\Collection\AbstractDb; +use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Model\AbstractModel; +use Magento\Framework\Model\Context; +use Magento\Framework\Model\ResourceModel\AbstractResource; +use Magento\Framework\Registry; use Magento\Framework\View\Design\Theme\Customization\FileInterface as CustomizationFileInterface; +use Magento\Framework\View\Design\Theme\Customization\FileServiceFactory; use Magento\Framework\View\Design\Theme\FileInterface; +use Magento\Framework\View\Design\Theme\FlyweightFactory; +use Magento\Framework\View\Design\ThemeInterface; +use Magento\Theme\Model\ResourceModel\Theme\File as ResourceThemeFile; +use UnexpectedValueException; /** * Theme files model class @@ -29,12 +39,12 @@ class File extends AbstractModel implements FileInterface protected $_eventObject = 'file'; /** - * @var \Magento\Framework\View\Design\ThemeInterface + * @var ThemeInterface */ protected $_theme; /** - * @var \Magento\Framework\View\Design\Theme\Customization\FileServiceFactory + * @var FileServiceFactory */ protected $_fileServiceFactory; @@ -44,26 +54,26 @@ class File extends AbstractModel implements FileInterface protected $_fileService; /** - * @var \Magento\Framework\View\Design\Theme\FlyweightFactory + * @var FlyweightFactory */ protected $_themeFactory; /** - * @param \Magento\Framework\Model\Context $context - * @param \Magento\Framework\Registry $registry - * @param \Magento\Framework\View\Design\Theme\FlyweightFactory $themeFactory - * @param \Magento\Framework\View\Design\Theme\Customization\FileServiceFactory $fileServiceFactory - * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource - * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection + * @param Context $context + * @param Registry $registry + * @param FlyweightFactory $themeFactory + * @param FileServiceFactory $fileServiceFactory + * @param AbstractResource $resource + * @param AbstractDb $resourceCollection * @param array $data */ public function __construct( - \Magento\Framework\Model\Context $context, - \Magento\Framework\Registry $registry, - \Magento\Framework\View\Design\Theme\FlyweightFactory $themeFactory, - \Magento\Framework\View\Design\Theme\Customization\FileServiceFactory $fileServiceFactory, - \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, - \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, + Context $context, + Registry $registry, + FlyweightFactory $themeFactory, + FileServiceFactory $fileServiceFactory, + AbstractResource $resource = null, + AbstractDb $resourceCollection = null, array $data = [] ) { $this->_themeFactory = $themeFactory; @@ -78,7 +88,7 @@ public function __construct( */ protected function _construct() { - $this->_init(\Magento\Theme\Model\ResourceModel\Theme\File::class); + $this->_init(ResourceThemeFile::class); } /** @@ -96,14 +106,14 @@ public function setCustomizationService(CustomizationFileInterface $fileService) * {@inheritdoc} * * @return CustomizationFileInterface - * @throws \UnexpectedValueException + * @throws UnexpectedValueException */ public function getCustomizationService() { if (!$this->_fileService && $this->hasData('file_type')) { $this->_fileService = $this->_fileServiceFactory->create($this->getData('file_type')); } elseif (!$this->_fileService) { - throw new \UnexpectedValueException('Type of file is empty'); + throw new UnexpectedValueException('Type of file is empty'); } return $this->_fileService; } @@ -111,7 +121,7 @@ public function getCustomizationService() /** * {@inheritdoc} */ - public function setTheme(\Magento\Framework\View\Design\ThemeInterface $theme) + public function setTheme(ThemeInterface $theme) { $this->_theme = $theme; $this->setData('theme_id', $theme->getId()); @@ -122,13 +132,13 @@ public function setTheme(\Magento\Framework\View\Design\ThemeInterface $theme) /** * {@inheritdoc} * - * @throws \Magento\Framework\Exception\LocalizedException + * @throws LocalizedException */ public function getTheme() { $theme = $this->_themeFactory->create($this->getData('theme_id')); if (!$theme) { - throw new \Magento\Framework\Exception\LocalizedException(__('Theme id should be set')); + throw new LocalizedException(__('Theme id should be set')); } return $theme; } diff --git a/app/code/Magento/Theme/Model/Theme/FileProvider.php b/app/code/Magento/Theme/Model/Theme/FileProvider.php index 371dbe03c8eb8..ad1e82f373462 100644 --- a/app/code/Magento/Theme/Model/Theme/FileProvider.php +++ b/app/code/Magento/Theme/Model/Theme/FileProvider.php @@ -5,27 +5,27 @@ */ namespace Magento\Theme\Model\Theme; -class FileProvider implements \Magento\Framework\View\Design\Theme\FileProviderInterface -{ - /** - * @var \Magento\Theme\Model\ResourceModel\Theme\File\CollectionFactory - */ - protected $fileFactory; +use Magento\Framework\View\Design\Theme\File\CollectionInterface; +use Magento\Framework\View\Design\Theme\FileProviderInterface; +use Magento\Framework\View\Design\ThemeInterface; +use Magento\Theme\Model\ResourceModel\Theme\File\CollectionFactory; +class FileProvider implements FileProviderInterface +{ /** - * @param \Magento\Theme\Model\ResourceModel\Theme\File\CollectionFactory $fileFactory + * @param CollectionFactory $fileFactory */ - public function __construct(\Magento\Theme\Model\ResourceModel\Theme\File\CollectionFactory $fileFactory) - { - $this->fileFactory = $fileFactory; + public function __construct( + protected readonly CollectionFactory $fileFactory + ) { } /** * {@inheritdoc} */ - public function getItems(\Magento\Framework\View\Design\ThemeInterface $theme, array $filters = []) + public function getItems(ThemeInterface $theme, array $filters = []) { - /** @var \Magento\Framework\View\Design\Theme\File\CollectionInterface $themeFiles */ + /** @var CollectionInterface $themeFiles */ $themeFiles = $this->fileFactory->create(); $themeFiles->addThemeFilter($theme); foreach ($filters as $field => $value) { diff --git a/app/code/Magento/Theme/Model/Theme/Image/Path.php b/app/code/Magento/Theme/Model/Theme/Image/Path.php index f073e8773c825..c9b47fb730f23 100644 --- a/app/code/Magento/Theme/Model/Theme/Image/Path.php +++ b/app/code/Magento/Theme/Model/Theme/Image/Path.php @@ -7,12 +7,18 @@ namespace Magento\Theme\Model\Theme\Image; use Magento\Framework\App\Filesystem\DirectoryList; +use Magento\Framework\Filesystem; +use Magento\Framework\Filesystem\Directory\ReadInterface as DirectoryReadInterface; +use Magento\Framework\UrlInterface; +use Magento\Framework\View\Asset\Repository as AssetRepository; +use Magento\Framework\View\Design\Theme\Image\PathInterface as ImagePathInterface; use Magento\Framework\View\Design\ThemeInterface; +use Magento\Store\Model\StoreManagerInterface; /** * Theme Image Path */ -class Path implements \Magento\Framework\View\Design\Theme\Image\PathInterface +class Path implements ImagePathInterface { /** * Default theme preview image @@ -20,35 +26,23 @@ class Path implements \Magento\Framework\View\Design\Theme\Image\PathInterface public const DEFAULT_PREVIEW_IMAGE = 'Magento_Theme::theme/default_preview.jpg'; /** - * @var \Magento\Framework\Filesystem\Directory\ReadInterface + * @var DirectoryReadInterface */ protected $mediaDirectory; - /** - * @var \Magento\Framework\View\Asset\Repository - */ - protected $assetRepo; - - /** - * @var \Magento\Store\Model\StoreManagerInterface - */ - protected $storeManager; - /** * Initialize dependencies * - * @param \Magento\Framework\Filesystem $filesystem - * @param \Magento\Framework\View\Asset\Repository $assetRepo - * @param \Magento\Store\Model\StoreManagerInterface $storeManager + * @param Filesystem $filesystem + * @param AssetRepository $assetRepo + * @param StoreManagerInterface $storeManager */ public function __construct( - \Magento\Framework\Filesystem $filesystem, - \Magento\Framework\View\Asset\Repository $assetRepo, - \Magento\Store\Model\StoreManagerInterface $storeManager + Filesystem $filesystem, + protected readonly AssetRepository $assetRepo, + protected readonly StoreManagerInterface $storeManager ) { $this->mediaDirectory = $filesystem->getDirectoryRead(DirectoryList::MEDIA); - $this->assetRepo = $assetRepo; - $this->storeManager = $storeManager; } /** @@ -59,7 +53,7 @@ public function __construct( */ public function getPreviewImageUrl(ThemeInterface $theme) { - return $this->storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA) + return $this->storeManager->getStore()->getBaseUrl(UrlInterface::URL_TYPE_MEDIA) . self::PREVIEW_DIRECTORY_PATH . '/' . $theme->getPreviewImage(); } diff --git a/app/code/Magento/Theme/Model/Theme/Plugin/Registration.php b/app/code/Magento/Theme/Model/Theme/Plugin/Registration.php index 13102a722eddf..b3c4b15ca4b12 100644 --- a/app/code/Magento/Theme/Model/Theme/Plugin/Registration.php +++ b/app/code/Magento/Theme/Model/Theme/Plugin/Registration.php @@ -6,6 +6,7 @@ namespace Magento\Theme\Model\Theme\Plugin; use Magento\Framework\App\ActionInterface; +use Magento\Theme\Model\Theme as ModelTheme; use Magento\Theme\Model\Theme\Registration as ThemeRegistration; use Magento\Framework\Exception\LocalizedException; use Psr\Log\LoggerInterface; @@ -21,31 +22,6 @@ */ class Registration { - /** - * @var ThemeRegistration - */ - protected $themeRegistration; - - /** - * @var ThemeCollection - */ - protected $themeCollection; - - /** - * @var ThemeLoader - */ - protected $themeLoader; - - /** - * @var LoggerInterface - */ - protected $logger; - - /** - * @var AppState - */ - protected $appState; - /** * @param ThemeRegistration $themeRegistration * @param ThemeCollection $themeCollection @@ -54,17 +30,12 @@ class Registration * @param AppState $appState */ public function __construct( - ThemeRegistration $themeRegistration, - ThemeCollection $themeCollection, - ThemeLoader $themeLoader, - LoggerInterface $logger, - AppState $appState + protected readonly ThemeRegistration $themeRegistration, + protected readonly ThemeCollection $themeCollection, + protected readonly ThemeLoader $themeLoader, + protected readonly LoggerInterface $logger, + protected readonly AppState $appState ) { - $this->themeRegistration = $themeRegistration; - $this->themeCollection = $themeCollection; - $this->themeLoader = $themeLoader; - $this->logger = $logger; - $this->appState = $appState; } /** @@ -96,9 +67,9 @@ public function beforeExecute( protected function updateThemeData() { $themesFromConfig = $this->themeCollection->loadData(); - /** @var \Magento\Theme\Model\Theme $themeFromConfig */ + /** @var ModelTheme $themeFromConfig */ foreach ($themesFromConfig as $themeFromConfig) { - /** @var \Magento\Theme\Model\Theme $themeFromDb */ + /** @var ModelTheme $themeFromDb */ $themeFromDb = $this->themeLoader->getThemeByFullPath( $themeFromConfig->getArea() . Theme::THEME_PATH_SEPARATOR diff --git a/app/code/Magento/Theme/Model/Theme/Registration.php b/app/code/Magento/Theme/Model/Theme/Registration.php index e42d8dad77bf2..6986f128297e5 100644 --- a/app/code/Magento/Theme/Model/Theme/Registration.php +++ b/app/code/Magento/Theme/Model/Theme/Registration.php @@ -8,6 +8,8 @@ use Magento\Framework\Filesystem; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\View\Design\ThemeInterface; +use Magento\Theme\Model\ResourceModel\Theme\Data\CollectionFactory; +use Magento\Theme\Model\Theme\Data\Collection as ThemeDataCollection; /** * Theme registration model class @@ -15,7 +17,7 @@ class Registration { /** - * @var \Magento\Theme\Model\ResourceModel\Theme\Data\CollectionFactory + * @var CollectionFactory */ protected $_collectionFactory; @@ -49,12 +51,12 @@ class Registration /** * Initialize dependencies * - * @param \Magento\Theme\Model\ResourceModel\Theme\Data\CollectionFactory $collectionFactory - * @param \Magento\Theme\Model\Theme\Data\Collection $filesystemCollection + * @param CollectionFactory $collectionFactory + * @param ThemeDataCollection $filesystemCollection */ public function __construct( - \Magento\Theme\Model\ResourceModel\Theme\Data\CollectionFactory $collectionFactory, - \Magento\Theme\Model\Theme\Data\Collection $filesystemCollection + CollectionFactory $collectionFactory, + ThemeDataCollection $filesystemCollection ) { $this->_collectionFactory = $collectionFactory; $this->_themeCollection = $filesystemCollection; @@ -83,8 +85,8 @@ public function register() * * Second param is optional and is used to prevent circular references in inheritance chain * - * @param ThemeInterface &$theme - * @param array $inheritanceChain + * @param ThemeInterface &$theme + * @param array $inheritanceChain * @return $this * * @throws LocalizedException @@ -156,7 +158,7 @@ public function getThemeFromDb($fullPath) public function checkPhysicalThemes() { $themes = $this->_collectionFactory->create()->addTypeFilter(ThemeInterface::TYPE_PHYSICAL); - /** @var $theme ThemeInterface */ + /** @var ThemeInterface $theme */ foreach ($themes as $theme) { if (!$this->_themeCollection->hasTheme($theme)) { $theme->setType(ThemeInterface::TYPE_VIRTUAL)->save(); @@ -176,7 +178,7 @@ public function checkAllowedThemeRelations() list($parentType, $childType) = $typesSequence; $collection = $this->_collectionFactory->create(); $collection->addTypeRelationFilter($parentType, $childType); - /** @var $theme ThemeInterface */ + /** @var ThemeInterface $theme */ foreach ($collection as $theme) { $parentId = $this->_getResetParentId($theme); if ($theme->getParentId() != $parentId) { diff --git a/app/code/Magento/Theme/Model/Theme/Resolver.php b/app/code/Magento/Theme/Model/Theme/Resolver.php index 59a3202a0b49b..fbc083cc873e6 100644 --- a/app/code/Magento/Theme/Model/Theme/Resolver.php +++ b/app/code/Magento/Theme/Model/Theme/Resolver.php @@ -5,45 +5,34 @@ */ namespace Magento\Theme\Model\Theme; +use Magento\Framework\App\State; +use Magento\Framework\View\Design\Theme\ResolverInterface; +use Magento\Framework\View\Design\ThemeInterface; +use Magento\Framework\View\DesignInterface; +use Magento\Theme\Model\ResourceModel\Theme\Collection as ThemeCollection; +use Magento\Theme\Model\ResourceModel\Theme\CollectionFactory; + /** * Theme resolver model */ -class Resolver implements \Magento\Framework\View\Design\Theme\ResolverInterface +class Resolver implements ResolverInterface { /** - * @var \Magento\Framework\View\DesignInterface - */ - protected $design; - - /** - * @var \Magento\Theme\Model\ResourceModel\Theme\CollectionFactory - */ - protected $themeFactory; - - /** - * @var \Magento\Framework\App\State - */ - protected $appState; - - /** - * @param \Magento\Framework\App\State $appState - * @param \Magento\Framework\View\DesignInterface $design - * @param \Magento\Theme\Model\ResourceModel\Theme\CollectionFactory $themeFactory + * @param State $appState + * @param DesignInterface $design + * @param CollectionFactory $themeFactory */ public function __construct( - \Magento\Framework\App\State $appState, - \Magento\Framework\View\DesignInterface $design, - \Magento\Theme\Model\ResourceModel\Theme\CollectionFactory $themeFactory + protected readonly State $appState, + protected readonly DesignInterface $design, + protected readonly CollectionFactory $themeFactory ) { - $this->design = $design; - $this->themeFactory = $themeFactory; - $this->appState = $appState; } /** * Retrieve instance of a theme currently used in an area * - * @return \Magento\Framework\View\Design\ThemeInterface + * @return ThemeInterface */ public function get() { @@ -52,13 +41,13 @@ public function get() return $this->design->getDesignTheme(); } - /** @var \Magento\Theme\Model\ResourceModel\Theme\Collection $themeCollection */ + /** @var ThemeCollection $themeCollection */ $themeCollection = $this->themeFactory->create(); $themeIdentifier = $this->design->getConfigurationDesignTheme($area); if (is_numeric($themeIdentifier)) { $result = $themeCollection->getItemById($themeIdentifier); } else { - $themeFullPath = $area . \Magento\Framework\View\Design\ThemeInterface::PATH_SEPARATOR . $themeIdentifier; + $themeFullPath = $area . ThemeInterface::PATH_SEPARATOR . $themeIdentifier; $result = $themeCollection->getThemeByFullPath($themeFullPath); } return $result; diff --git a/app/code/Magento/Theme/Model/Theme/SingleFile.php b/app/code/Magento/Theme/Model/Theme/SingleFile.php index 44e19bedeb3c7..76ccd070f4070 100644 --- a/app/code/Magento/Theme/Model/Theme/SingleFile.php +++ b/app/code/Magento/Theme/Model/Theme/SingleFile.php @@ -9,29 +9,34 @@ */ namespace Magento\Theme\Model\Theme; +use Magento\Framework\View\Design\Theme\Customization\FileInterface; +use Magento\Framework\View\Design\Theme\FileInterface as ThemeFileInterface; +use Magento\Framework\View\Design\ThemeInterface; + class SingleFile { /** - * @var \Magento\Framework\View\Design\Theme\Customization\FileInterface + * @var FileInterface */ protected $_fileService; /** - * @param \Magento\Framework\View\Design\Theme\Customization\FileInterface $fileService + * @param FileInterface $fileService */ - public function __construct(\Magento\Framework\View\Design\Theme\Customization\FileInterface $fileService) - { + public function __construct( + FileInterface $fileService + ) { $this->_fileService = $fileService; } /** * Creates or updates custom single file which belong to a selected theme * - * @param \Magento\Framework\View\Design\ThemeInterface $themeModel + * @param ThemeInterface $themeModel * @param string $fileContent - * @return \Magento\Framework\View\Design\Theme\FileInterface + * @return ThemeFileInterface */ - public function update(\Magento\Framework\View\Design\ThemeInterface $themeModel, $fileContent) + public function update(ThemeInterface $themeModel, $fileContent) { $customFiles = $themeModel->getCustomization()->getFilesByType($this->_fileService->getType()); $customCss = reset($customFiles); diff --git a/app/code/Magento/Theme/Model/Theme/Source/Theme.php b/app/code/Magento/Theme/Model/Theme/Source/Theme.php index 48678f6368c19..984c66c4402e6 100644 --- a/app/code/Magento/Theme/Model/Theme/Source/Theme.php +++ b/app/code/Magento/Theme/Model/Theme/Source/Theme.php @@ -18,17 +18,12 @@ */ class Theme extends AbstractSource { - /** - * @var Label - */ - protected $themeLabel; - /** * @param Label $themeLabel */ - public function __construct(Label $themeLabel) - { - $this->themeLabel = $themeLabel; + public function __construct( + protected readonly Label $themeLabel + ) { } /** diff --git a/app/code/Magento/Theme/Model/Theme/StoreDefaultThemeResolver.php b/app/code/Magento/Theme/Model/Theme/StoreDefaultThemeResolver.php index 26bd5604294d1..f09f130d8a7dc 100644 --- a/app/code/Magento/Theme/Model/Theme/StoreDefaultThemeResolver.php +++ b/app/code/Magento/Theme/Model/Theme/StoreDefaultThemeResolver.php @@ -11,6 +11,7 @@ use Magento\Framework\View\Design\ThemeInterface; use Magento\Framework\View\DesignInterface; use Magento\Store\Api\Data\StoreInterface; +use Magento\Theme\Model\ResourceModel\Theme\Collection as ThemeCollection; use Magento\Theme\Model\ResourceModel\Theme\CollectionFactory; /** @@ -20,14 +21,6 @@ */ class StoreDefaultThemeResolver implements StoreThemesResolverInterface { - /** - * @var CollectionFactory - */ - private $themeCollectionFactory; - /** - * @var DesignInterface - */ - private $design; /** * @var ThemeInterface[] */ @@ -38,11 +31,9 @@ class StoreDefaultThemeResolver implements StoreThemesResolverInterface * @param DesignInterface $design */ public function __construct( - CollectionFactory $themeCollectionFactory, - DesignInterface $design + private readonly CollectionFactory $themeCollectionFactory, + private readonly DesignInterface $design ) { - $this->design = $design; - $this->themeCollectionFactory = $themeCollectionFactory; } /** @@ -77,7 +68,7 @@ private function getRegisteredThemes(): array { if ($this->registeredThemes === null) { $this->registeredThemes = []; - /** @var \Magento\Theme\Model\ResourceModel\Theme\Collection $collection */ + /** @var ThemeCollection $collection */ $collection = $this->themeCollectionFactory->create(); $themes = $collection->loadRegisteredThemes(); /** @var ThemeInterface $theme */ diff --git a/app/code/Magento/Theme/Model/Theme/StoreUserAgentThemeResolver.php b/app/code/Magento/Theme/Model/Theme/StoreUserAgentThemeResolver.php index fb5d68e37c99b..dd85efeaef4c5 100644 --- a/app/code/Magento/Theme/Model/Theme/StoreUserAgentThemeResolver.php +++ b/app/code/Magento/Theme/Model/Theme/StoreUserAgentThemeResolver.php @@ -19,25 +19,15 @@ class StoreUserAgentThemeResolver implements StoreThemesResolverInterface { private const XML_PATH_THEME_USER_AGENT = 'design/theme/ua_regexp'; - /** - * @var ScopeConfigInterface - */ - private $scopeConfig; - /** - * @var Json - */ - private $serializer; /** * @param ScopeConfigInterface $scopeConfig * @param Json $serializer */ public function __construct( - ScopeConfigInterface $scopeConfig, - Json $serializer + private readonly ScopeConfigInterface $scopeConfig, + private readonly Json $serializer ) { - $this->scopeConfig = $scopeConfig; - $this->serializer = $serializer; } /** diff --git a/app/code/Magento/Theme/Model/Theme/ThemeDependencyChecker.php b/app/code/Magento/Theme/Model/Theme/ThemeDependencyChecker.php index 6aaba752f7574..ac68ffcae6194 100644 --- a/app/code/Magento/Theme/Model/Theme/ThemeDependencyChecker.php +++ b/app/code/Magento/Theme/Model/Theme/ThemeDependencyChecker.php @@ -6,6 +6,7 @@ namespace Magento\Theme\Model\Theme; +use Magento\Theme\Model\Theme\Data as ThemeData; use Magento\Theme\Model\Theme\Data\Collection as ThemeCollection; /** @@ -13,27 +14,6 @@ */ class ThemeDependencyChecker { - /** - * Theme Collection - * - * @var ThemeCollection - */ - private $themeCollection; - - /** - * Provider for themes registered in db - * - * @var ThemeProvider - */ - private $themeProvider; - - /** - * Package name finder - * - * @var ThemePackageInfo - */ - private $themePackageInfo; - /** * Constructor * @@ -42,13 +22,10 @@ class ThemeDependencyChecker * @param ThemePackageInfo $themePackageInfo, */ public function __construct( - ThemeCollection $themeCollection, - ThemeProvider $themeProvider, - ThemePackageInfo $themePackageInfo + private readonly ThemeCollection $themeCollection, + private readonly ThemeProvider $themeProvider, + private readonly ThemePackageInfo $themePackageInfo ) { - $this->themeCollection = $themeCollection; - $this->themeProvider = $themeProvider; - $this->themePackageInfo = $themePackageInfo; } /** @@ -117,7 +94,7 @@ private function getParentChildThemeMap() $map = []; $this->themeCollection->resetConstraints(); $this->themeCollection->clear(); - /** @var \Magento\Theme\Model\Theme\Data $theme */ + /** @var ThemeData $theme */ foreach ($this->themeCollection as $theme) { if ($theme->getParentTheme()) { $map[$theme->getParentTheme()->getFullPath()][] = $theme->getFullPath(); diff --git a/app/code/Magento/Theme/Model/Theme/ThemePackageInfo.php b/app/code/Magento/Theme/Model/Theme/ThemePackageInfo.php index f98fe3d76a35e..f1246c0c48984 100644 --- a/app/code/Magento/Theme/Model/Theme/ThemePackageInfo.php +++ b/app/code/Magento/Theme/Model/Theme/ThemePackageInfo.php @@ -5,50 +5,36 @@ */ namespace Magento\Theme\Model\Theme; +use Magento\Framework\App\ObjectManager; use Magento\Framework\Component\ComponentRegistrar; use Magento\Framework\Filesystem\Directory\ReadFactory; +use Magento\Framework\Serialize\Serializer\Json; +use Magento\Theme\Model\Theme; /** * Maps package name to full theme path, and vice versa */ class ThemePackageInfo { - /** - * @var ComponentRegistrar - */ - private $componentRegistrar; - - /** - * @var ReadFactory - */ - private $readDirFactory; - /** * @var array */ private $packageNameToFullPathMap = []; - /** - * @var \Magento\Framework\Serialize\Serializer\Json - */ - private $serializer; - /** * Initialize dependencies. * * @param ComponentRegistrar $componentRegistrar * @param ReadFactory $readDirFactory - * @param \Magento\Framework\Serialize\Serializer\Json|null $serializer + * @param Json|null $serializer */ public function __construct( - ComponentRegistrar $componentRegistrar, - ReadFactory $readDirFactory, - \Magento\Framework\Serialize\Serializer\Json $serializer = null + private readonly ComponentRegistrar $componentRegistrar, + private readonly ReadFactory $readDirFactory, + private ?Json $serializer = null ) { - $this->componentRegistrar = $componentRegistrar; - $this->readDirFactory = $readDirFactory; - $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() - ->get(\Magento\Framework\Serialize\Serializer\Json::class); + $this->serializer = $serializer ?: ObjectManager::getInstance() + ->get(Json::class); } /** @@ -94,7 +80,7 @@ public function getFullThemePath($packageName) private function initializeMap() { $themePaths = $this->componentRegistrar->getPaths(ComponentRegistrar::THEME); - /** @var \Magento\Theme\Model\Theme $theme */ + /** @var Theme $theme */ foreach ($themePaths as $fullThemePath => $themeDir) { $themeDirRead = $this->readDirFactory->create($themeDir); if ($themeDirRead->isExist('composer.json')) { diff --git a/app/code/Magento/Theme/Model/Theme/ThemeProvider.php b/app/code/Magento/Theme/Model/Theme/ThemeProvider.php index 04e4c131dbcd3..c9b4a2f06d093 100644 --- a/app/code/Magento/Theme/Model/Theme/ThemeProvider.php +++ b/app/code/Magento/Theme/Model/Theme/ThemeProvider.php @@ -5,33 +5,26 @@ */ namespace Magento\Theme\Model\Theme; +use Magento\Framework\App\Area; +use Magento\Framework\App\CacheInterface; use Magento\Framework\App\ObjectManager; use Magento\Framework\Serialize\Serializer\Json; use Magento\Framework\View\Design\Theme\ListInterface; use Magento\Framework\App\DeploymentConfig; +use Magento\Framework\View\Design\Theme\ThemeProviderInterface; +use Magento\Framework\View\Design\ThemeInterface; +use Magento\Theme\Model\ResourceModel\Theme\Collection as ThemeCollection; +use Magento\Theme\Model\ResourceModel\Theme\CollectionFactory; +use Magento\Theme\Model\Theme; +use Magento\Theme\Model\ThemeFactory; /** * Provide data for theme grid and for theme edit page */ -class ThemeProvider implements \Magento\Framework\View\Design\Theme\ThemeProviderInterface +class ThemeProvider implements ThemeProviderInterface { /** - * @var \Magento\Theme\Model\ResourceModel\Theme\CollectionFactory - */ - protected $collectionFactory; - - /** - * @var \Magento\Theme\Model\ThemeFactory - */ - protected $themeFactory; - - /** - * @var \Magento\Framework\App\CacheInterface - */ - protected $cache; - - /** - * @var \Magento\Framework\View\Design\ThemeInterface[] + * @var ThemeInterface[] */ private $themes; @@ -45,28 +38,20 @@ class ThemeProvider implements \Magento\Framework\View\Design\Theme\ThemeProvide */ private $deploymentConfig; - /** - * @var Json - */ - private $serializer; - /** * ThemeProvider constructor. * - * @param \Magento\Theme\Model\ResourceModel\Theme\CollectionFactory $collectionFactory - * @param \Magento\Theme\Model\ThemeFactory $themeFactory - * @param \Magento\Framework\App\CacheInterface $cache - * @param Json $serializer + * @param CollectionFactory $collectionFactory + * @param ThemeFactory $themeFactory + * @param CacheInterface $cache + * @param Json|null $serializer */ public function __construct( - \Magento\Theme\Model\ResourceModel\Theme\CollectionFactory $collectionFactory, - \Magento\Theme\Model\ThemeFactory $themeFactory, - \Magento\Framework\App\CacheInterface $cache, - Json $serializer = null + protected readonly CollectionFactory $collectionFactory, + protected readonly ThemeFactory $themeFactory, + protected readonly CacheInterface $cache, + private ?Json $serializer = null ) { - $this->collectionFactory = $collectionFactory; - $this->themeFactory = $themeFactory; - $this->cache = $cache; $this->serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class); } @@ -103,10 +88,10 @@ public function getThemeByFullPath($fullPath) * @inheritdoc */ public function getThemeCustomizations( - $area = \Magento\Framework\App\Area::AREA_FRONTEND, - $type = \Magento\Framework\View\Design\ThemeInterface::TYPE_VIRTUAL + $area = Area::AREA_FRONTEND, + $type = ThemeInterface::TYPE_VIRTUAL ) { - /** @var $themeCollection \Magento\Theme\Model\ResourceModel\Theme\Collection */ + /** @var $themeCollection ThemeCollection */ $themeCollection = $this->collectionFactory->create(); $themeCollection->addAreaFilter($area)->addTypeFilter($type); return $themeCollection; @@ -139,7 +124,7 @@ public function getThemeById($themeId) * Load Theme model from cache * * @param string $cacheId - * @return \Magento\Theme\Model\Theme|null + * @return Theme|null */ private function loadThemeFromCache($cacheId) { @@ -156,11 +141,11 @@ private function loadThemeFromCache($cacheId) /** * Save Theme model to the cache * - * @param \Magento\Theme\Model\Theme $theme + * @param Theme $theme * @param string $cacheId * @return void */ - private function saveThemeToCache(\Magento\Theme\Model\Theme $theme, $cacheId) + private function saveThemeToCache(Theme $theme, $cacheId) { $themeData = $this->serializer->serialize($theme->toArray()); $this->cache->save($themeData, $cacheId); diff --git a/app/code/Magento/Theme/Model/Theme/ThemeUninstaller.php b/app/code/Magento/Theme/Model/Theme/ThemeUninstaller.php index bdc3016e34a1d..4090b03c2496a 100644 --- a/app/code/Magento/Theme/Model/Theme/ThemeUninstaller.php +++ b/app/code/Magento/Theme/Model/Theme/ThemeUninstaller.php @@ -10,21 +10,6 @@ class ThemeUninstaller { - /** - * @var ThemePackageInfo - */ - private $themePackageInfo; - - /** - * @var Remove - */ - private $remove; - - /** - * @var ThemeProvider - */ - private $themeProvider; - /** * Constructor * @@ -32,11 +17,11 @@ class ThemeUninstaller * @param Remove $remove * @param ThemeProvider $themeProvider */ - public function __construct(ThemePackageInfo $themePackageInfo, Remove $remove, ThemeProvider $themeProvider) - { - $this->themePackageInfo = $themePackageInfo; - $this->remove = $remove; - $this->themeProvider = $themeProvider; + public function __construct( + private readonly ThemePackageInfo $themePackageInfo, + private readonly Remove $remove, + private readonly ThemeProvider $themeProvider + ) { } /** diff --git a/app/code/Magento/Theme/Model/ThemeValidator.php b/app/code/Magento/Theme/Model/ThemeValidator.php index 83873374897b5..f8e3b58d4b15a 100644 --- a/app/code/Magento/Theme/Model/ThemeValidator.php +++ b/app/code/Magento/Theme/Model/ThemeValidator.php @@ -16,41 +16,16 @@ */ class ThemeValidator { - - /** - * Store Manager - * - * @var StoreManagerInterface $storeManager - */ - private $storeManager; - - /** - * Provider for themes registered in db - * - * @var ThemeProviderInterface $themeProvider - */ - private $themeProvider; - - /** - * Configuration Data - * - * @var ValueInterface $configData - */ - private $configData; - /** * @param StoreManagerInterface $storeManager * @param ThemeProviderInterface $themeProvider * @param ValueInterface $configData */ public function __construct( - StoreManagerInterface $storeManager, - ThemeProviderInterface $themeProvider, - ValueInterface $configData + private readonly StoreManagerInterface $storeManager, + private readonly ThemeProviderInterface $themeProvider, + private readonly ValueInterface $configData ) { - $this->storeManager = $storeManager; - $this->themeProvider = $themeProvider; - $this->configData = $configData; } /** diff --git a/app/code/Magento/Theme/Model/Uploader/Service.php b/app/code/Magento/Theme/Model/Uploader/Service.php index 4fc14522da169..e394e4d7c7bee 100644 --- a/app/code/Magento/Theme/Model/Uploader/Service.php +++ b/app/code/Magento/Theme/Model/Uploader/Service.php @@ -8,8 +8,13 @@ namespace Magento\Theme\Model\Uploader; use Magento\Framework\Convert\DataSize; +use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\File\Size; use Magento\Framework\Filesystem; +use Magento\Framework\Filesystem\Directory\ReadInterface; use Magento\Framework\Filesystem\DirectoryList; +use Magento\MediaStorage\Model\File\Uploader; +use Magento\MediaStorage\Model\File\UploaderFactory; class Service { @@ -21,33 +26,26 @@ class Service protected $_filePath; /** - * @var \Magento\Framework\Filesystem\Directory\ReadInterface + * @var ReadInterface */ protected $_tmpDirectory; /** * File size * - * @var \Magento\Framework\File\Size + * @var Size */ protected $_fileSize; - /** - * Data size converter - * - * @var \Magento\Framework\Convert\DataSize - */ - protected $dataSize; - /** * File uploader * - * @var \Magento\MediaStorage\Model\File\Uploader + * @var Uploader */ protected $_uploader; /** - * @var \Magento\MediaStorage\Model\File\Uploader + * @var Uploader */ protected $_uploaderFactory; @@ -64,23 +62,22 @@ class Service /** * Constructor * - * @param \Magento\Framework\Filesystem $filesystem - * @param \Magento\Framework\File\Size $fileSize - * @param \Magento\Framework\Convert\DataSize $dataSize - * @param \Magento\MediaStorage\Model\File\UploaderFactory $uploaderFactory + * @param Filesystem $filesystem + * @param Size $fileSize + * @param DataSize $dataSize + * @param UploaderFactory $uploaderFactory * @param array $uploadLimits keys are 'css' and 'js' for file type, values defines maximum file size, example: 2M */ public function __construct( - \Magento\Framework\Filesystem $filesystem, - \Magento\Framework\File\Size $fileSize, - \Magento\Framework\Convert\DataSize $dataSize, - \Magento\MediaStorage\Model\File\UploaderFactory $uploaderFactory, + Filesystem $filesystem, + Size $fileSize, + protected readonly DataSize $dataSize, + UploaderFactory $uploaderFactory, array $uploadLimits = [] ) { $this->_tmpDirectory = $filesystem->getDirectoryRead(DirectoryList::SYS_TMP); $this->_fileSize = $fileSize; $this->_uploaderFactory = $uploaderFactory; - $this->dataSize = $dataSize; if (isset($uploadLimits['css'])) { $this->_cssUploadLimit = $uploadLimits['css']; } @@ -94,11 +91,11 @@ public function __construct( * * @param string $file - Key in the $_FILES array * @return array - * @throws \Magento\Framework\Exception\LocalizedException + * @throws LocalizedException */ public function uploadCssFile($file) { - /** @var $fileUploader \Magento\MediaStorage\Model\File\Uploader */ + /** @var Uploader $fileUploader */ $fileUploader = $this->_uploaderFactory->create(['fileId' => $file]); $fileUploader->setAllowedExtensions(['css']); $fileUploader->setAllowRenameFiles(true); @@ -106,7 +103,7 @@ public function uploadCssFile($file) $isValidFileSize = $this->_validateFileSize($fileUploader->getFileSize(), $this->getCssUploadMaxSize()); if (!$isValidFileSize) { - throw new \Magento\Framework\Exception\LocalizedException( + throw new LocalizedException( __('The CSS file must be less than %1M.', $this->getCssUploadMaxSizeInMb()) ); } @@ -120,11 +117,11 @@ public function uploadCssFile($file) * * @param string $file - Key in the $_FILES array * @return array - * @throws \Magento\Framework\Exception\LocalizedException + * @throws LocalizedException */ public function uploadJsFile($file) { - /** @var $fileUploader \Magento\MediaStorage\Model\File\Uploader */ + /** @var Uploader $fileUploader */ $fileUploader = $this->_uploaderFactory->create(['fileId' => $file]); $fileUploader->setAllowedExtensions(['js']); $fileUploader->setAllowRenameFiles(true); @@ -132,7 +129,7 @@ public function uploadJsFile($file) $isValidFileSize = $this->_validateFileSize($fileUploader->getFileSize(), $this->getJsUploadMaxSize()); if (!$isValidFileSize) { - throw new \Magento\Framework\Exception\LocalizedException( + throw new LocalizedException( __('The JS file must be less than %1M.', $this->getJsUploadMaxSizeInMb()) ); } diff --git a/app/code/Magento/Theme/Model/Url/Plugin/Signature.php b/app/code/Magento/Theme/Model/Url/Plugin/Signature.php index 21d2f5c45ee1d..351b9af409861 100644 --- a/app/code/Magento/Theme/Model/Url/Plugin/Signature.php +++ b/app/code/Magento/Theme/Model/Url/Plugin/Signature.php @@ -6,6 +6,11 @@ namespace Magento\Theme\Model\Url\Plugin; +use Magento\Framework\App\View\Deployment\Version; +use Magento\Framework\Url\ScopeInterface; +use Magento\Framework\UrlInterface; +use Magento\Framework\View\Url\ConfigInterface; + /** * Plugin that activates signing of static file URLs with corresponding deployment version */ @@ -22,46 +27,34 @@ class Signature const SIGNATURE_TEMPLATE = 'version%s'; /** - * @var \Magento\Framework\View\Url\ConfigInterface - */ - private $config; - - /** - * @var \Magento\Framework\App\View\Deployment\Version - */ - private $deploymentVersion; - - /** - * @param \Magento\Framework\View\Url\ConfigInterface $config - * @param \Magento\Framework\App\View\Deployment\Version $deploymentVersion + * @param ConfigInterface $config + * @param Version $deploymentVersion */ public function __construct( - \Magento\Framework\View\Url\ConfigInterface $config, - \Magento\Framework\App\View\Deployment\Version $deploymentVersion + private readonly ConfigInterface $config, + private readonly Version $deploymentVersion ) { - $this->config = $config; - $this->deploymentVersion = $deploymentVersion; } /** * Append signature to rendered base URL for static view files * - * @param \Magento\Framework\Url\ScopeInterface $subject + * @param ScopeInterface $subject * @param string $baseUrl * @param string $type * @param null $secure * @return string - * @see \Magento\Framework\Url\ScopeInterface::getBaseUrl() + * @see ScopeInterface::getBaseUrl * * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function afterGetBaseUrl( - \Magento\Framework\Url\ScopeInterface $subject, + ScopeInterface $subject, $baseUrl, - $type = \Magento\Framework\UrlInterface::URL_TYPE_LINK, + $type = UrlInterface::URL_TYPE_LINK, $secure = null ) { - if ($type == \Magento\Framework\UrlInterface::URL_TYPE_STATIC && $this->isUrlSignatureEnabled()) { + if ($type == UrlInterface::URL_TYPE_STATIC && $this->isUrlSignatureEnabled()) { $baseUrl .= $this->renderUrlSignature() . '/'; } return $baseUrl; diff --git a/app/code/Magento/Theme/Model/View/Design.php b/app/code/Magento/Theme/Model/View/Design.php index f45b6b233a6a5..ce96b91b8ba47 100644 --- a/app/code/Magento/Theme/Model/View/Design.php +++ b/app/code/Magento/Theme/Model/View/Design.php @@ -7,12 +7,21 @@ namespace Magento\Theme\Model\View; use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\App\State; +use Magento\Framework\Locale\ResolverInterface; +use Magento\Framework\ObjectManagerInterface; +use Magento\Framework\View\Design\Theme\FlyweightFactory; +use Magento\Framework\View\Design\ThemeInterface; +use Magento\Framework\View\DesignInterface; use Magento\Store\Model\ScopeInterface; +use Magento\Store\Model\StoreManagerInterface; +use Magento\Theme\Model\Theme; +use Magento\Theme\Model\ThemeFactory; /** * Keeps design settings for current request */ -class Design implements \Magento\Framework\View\DesignInterface +class Design implements DesignInterface { /** * Package area @@ -24,7 +33,7 @@ class Design implements \Magento\Framework\View\DesignInterface /** * Package theme * - * @var \Magento\Theme\Model\Theme + * @var Theme */ protected $_theme; @@ -39,37 +48,32 @@ class Design implements \Magento\Framework\View\DesignInterface /** * Store list manager * - * @var \Magento\Store\Model\StoreManagerInterface + * @var StoreManagerInterface */ protected $_storeManager; /** - * @var \Magento\Framework\View\Design\Theme\FlyweightFactory + * @var FlyweightFactory */ protected $_flyweightFactory; /** - * @var \Magento\Theme\Model\ThemeFactory + * @var ThemeFactory */ protected $_themeFactory; /** - * @var \Magento\Framework\App\Config\ScopeConfigInterface + * @var ScopeConfigInterface */ private $_scopeConfig; /** - * @var \Magento\Framework\Locale\ResolverInterface + * @var ResolverInterface */ protected $_locale; /** - * @var \Magento\Framework\ObjectManagerInterface - */ - protected $objectManager; - - /** - * @var \Magento\Framework\App\State + * @var State */ protected $_appState; @@ -79,21 +83,21 @@ class Design implements \Magento\Framework\View\DesignInterface private $_themes; /** - * @param \Magento\Store\Model\StoreManagerInterface $storeManager - * @param \Magento\Framework\View\Design\Theme\FlyweightFactory $flyweightFactory - * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig - * @param \Magento\Theme\Model\ThemeFactory $themeFactory - * @param \Magento\Framework\ObjectManagerInterface $objectManager - * @param \Magento\Framework\App\State $appState + * @param StoreManagerInterface $storeManager + * @param FlyweightFactory $flyweightFactory + * @param ScopeConfigInterface $scopeConfig + * @param ThemeFactory $themeFactory + * @param ObjectManagerInterface $objectManager + * @param State $appState * @param array $themes */ public function __construct( - \Magento\Store\Model\StoreManagerInterface $storeManager, - \Magento\Framework\View\Design\Theme\FlyweightFactory $flyweightFactory, - \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, - \Magento\Theme\Model\ThemeFactory $themeFactory, - \Magento\Framework\ObjectManagerInterface $objectManager, - \Magento\Framework\App\State $appState, + StoreManagerInterface $storeManager, + FlyweightFactory $flyweightFactory, + ScopeConfigInterface $scopeConfig, + ThemeFactory $themeFactory, + protected readonly ObjectManagerInterface $objectManager, + State $appState, array $themes ) { $this->_storeManager = $storeManager; @@ -102,7 +106,6 @@ public function __construct( $this->_scopeConfig = $scopeConfig; $this->_appState = $appState; $this->_themes = $themes; - $this->objectManager = $objectManager; } /** @@ -135,7 +138,7 @@ public function getArea() /** * Set theme path * - * @param \Magento\Framework\View\Design\ThemeInterface|string $theme + * @param ThemeInterface|string $theme * @param string $area * @return $this */ @@ -147,7 +150,7 @@ public function setDesignTheme($theme, $area = null) $area = $this->getArea(); } - if ($theme instanceof \Magento\Framework\View\Design\ThemeInterface) { + if ($theme instanceof ThemeInterface) { $this->_theme = $theme; } else { $this->_theme = $this->_flyweightFactory->create($theme, $area); @@ -221,7 +224,7 @@ public function setDefaultDesignTheme() /** * Design theme model getter * - * @return \Magento\Theme\Model\Theme + * @return Theme */ public function getDesignTheme() { @@ -234,7 +237,7 @@ public function getDesignTheme() /** * {@inheritdoc} */ - public function getThemePath(\Magento\Framework\View\Design\ThemeInterface $theme) + public function getThemePath(ThemeInterface $theme) { $themePath = $theme->getThemePath(); if (!$themePath) { @@ -256,16 +259,16 @@ public function getThemePath(\Magento\Framework\View\Design\ThemeInterface $them public function getLocale() { if (null === $this->_locale) { - $this->_locale = $this->objectManager->get(\Magento\Framework\Locale\ResolverInterface::class); + $this->_locale = $this->objectManager->get(ResolverInterface::class); } return $this->_locale->getLocale(); } /** - * @param \Magento\Framework\Locale\ResolverInterface $locale + * @param ResolverInterface $locale * @return $this */ - public function setLocale(\Magento\Framework\Locale\ResolverInterface $locale) + public function setLocale(ResolverInterface $locale) { $this->_locale = $locale; return $this; diff --git a/app/code/Magento/Theme/Model/Wysiwyg/Storage.php b/app/code/Magento/Theme/Model/Wysiwyg/Storage.php index 435d2f57d6659..ecac09f2d73b2 100644 --- a/app/code/Magento/Theme/Model/Wysiwyg/Storage.php +++ b/app/code/Magento/Theme/Model/Wysiwyg/Storage.php @@ -8,9 +8,19 @@ use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\App\ObjectManager; +use Magento\Framework\Exception\FileSystemException; use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Filesystem; use Magento\Framework\Filesystem\DriverInterface; +use Magento\Framework\Filesystem\Io\File as IoFile; +use Magento\Framework\Image\AdapterFactory; +use Magento\Framework\ObjectManagerInterface; +use Magento\Framework\Url\DecoderInterface; +use Magento\Framework\Url\EncoderInterface; use Magento\MediaStorage\Model\File\Uploader; +use Magento\Theme\Helper\Storage as ThemeStorageHelper; +use Magento\Theme\Model\Wysiwyg\Storage as WysiwygStorage; +use Psr\Log\LoggerInterface; /** * Theme wysiwyg storage model @@ -56,17 +66,17 @@ class Storage /** * Storage helper * - * @var \Magento\Theme\Helper\Storage + * @var ThemeStorageHelper */ protected $_helper; /** - * @var \Magento\Framework\ObjectManagerInterface + * @var ObjectManagerInterface */ protected $_objectManager; /** - * @var \Magento\Framework\Image\AdapterFactory + * @var AdapterFactory */ protected $_imageFactory; @@ -75,57 +85,36 @@ class Storage */ protected $mediaWriteDirectory; - /** - * @var \Magento\Framework\Url\EncoderInterface - */ - protected $urlEncoder; - - /** - * @var \Magento\Framework\Url\DecoderInterface - */ - protected $urlDecoder; - /** - * @var \Magento\Framework\Filesystem\Io\File|null - */ - private $file; - - /** - * @var DriverInterface - */ - private $filesystemDriver; - /** * Initialize dependencies * - * @param \Magento\Framework\Filesystem $filesystem - * @param \Magento\Theme\Helper\Storage $helper - * @param \Magento\Framework\ObjectManagerInterface $objectManager - * @param \Magento\Framework\Image\AdapterFactory $imageFactory - * @param \Magento\Framework\Url\EncoderInterface $urlEncoder - * @param \Magento\Framework\Url\DecoderInterface $urlDecoder - * @param \Magento\Framework\Filesystem\Io\File|null $file + * @param Filesystem $filesystem + * @param ThemeStorageHelper $helper + * @param ObjectManagerInterface $objectManager + * @param AdapterFactory $imageFactory + * @param EncoderInterface $urlEncoder + * @param DecoderInterface $urlDecoder + * @param IoFile|null $file * @param DriverInterface|null $filesystemDriver * - * @throws \Magento\Framework\Exception\FileSystemException + * @throws FileSystemException */ public function __construct( - \Magento\Framework\Filesystem $filesystem, - \Magento\Theme\Helper\Storage $helper, - \Magento\Framework\ObjectManagerInterface $objectManager, - \Magento\Framework\Image\AdapterFactory $imageFactory, - \Magento\Framework\Url\EncoderInterface $urlEncoder, - \Magento\Framework\Url\DecoderInterface $urlDecoder, - \Magento\Framework\Filesystem\Io\File $file = null, - DriverInterface $filesystemDriver = null + Filesystem $filesystem, + ThemeStorageHelper $helper, + ObjectManagerInterface $objectManager, + AdapterFactory $imageFactory, + protected readonly EncoderInterface $urlEncoder, + protected readonly DecoderInterface $urlDecoder, + private ?IoFile $file = null, + private ?DriverInterface $filesystemDriver = null ) { $this->mediaWriteDirectory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA); $this->_helper = $helper; $this->_objectManager = $objectManager; $this->_imageFactory = $imageFactory; - $this->urlEncoder = $urlEncoder; - $this->urlDecoder = $urlDecoder; $this->file = $file ?: ObjectManager::getInstance()->get( - \Magento\Framework\Filesystem\Io\File::class + IoFile::class ); $this->filesystemDriver = $filesystemDriver ?: ObjectManager::getInstance() ->get(DriverInterface::class); @@ -185,8 +174,8 @@ public function _createThumbnail($source) $image->keepAspectRatio(true); $image->resize(self::THUMBNAIL_WIDTH, self::THUMBNAIL_HEIGHT); $image->save($this->mediaWriteDirectory->getAbsolutePath($thumbnailPath)); - } catch (\Magento\Framework\Exception\FileSystemException $e) { - $this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e); + } catch (FileSystemException $e) { + $this->_objectManager->get(LoggerInterface::class)->critical($e); return false; } @@ -237,7 +226,7 @@ public function createFolder($name, $path) * Delete file * * @param string $file - * @return \Magento\Theme\Model\Wysiwyg\Storage + * @return WysiwygStorage */ public function deleteFile($file) { diff --git a/app/code/Magento/Theme/Observer/ApplyThemeCustomizationObserver.php b/app/code/Magento/Theme/Observer/ApplyThemeCustomizationObserver.php index e2566adff1b78..9d1803e3b6ce7 100644 --- a/app/code/Magento/Theme/Observer/ApplyThemeCustomizationObserver.php +++ b/app/code/Magento/Theme/Observer/ApplyThemeCustomizationObserver.php @@ -6,10 +6,19 @@ namespace Magento\Theme\Observer; +use InvalidArgumentException; use Magento\Framework\Event\Observer as EventObserver; use Magento\Framework\Event\ObserverInterface; +use Magento\Framework\UrlInterface; +use Magento\Framework\View\Asset\GroupedCollection; +use Magento\Framework\View\Asset\Repository; +use Magento\Framework\View\Design\Theme\Customization\FileAssetInterface; +use Magento\Framework\View\Design\Theme\Customization\Path; +use Magento\Framework\View\DesignInterface; use Magento\Theme\Model\Theme; use Magento\Framework\App\Filesystem\DirectoryList; +use Magento\Theme\Model\Theme\File; +use Psr\Log\LoggerInterface; /** * Theme Observer model @@ -23,64 +32,52 @@ class ApplyThemeCustomizationObserver implements ObserverInterface private $currentTheme; /** - * @var \Magento\Framework\View\Asset\GroupedCollection + * @var GroupedCollection */ private $pageAssets; /** - * @var \Magento\Framework\View\Asset\Repository - */ - protected $assetRepo; - - /** - * @var \Psr\Log\LoggerInterface - */ - protected $logger; - - /** - * @param \Magento\Framework\View\DesignInterface $design - * @param \Magento\Framework\View\Asset\GroupedCollection $assets - * @param \Magento\Framework\View\Asset\Repository $assetRepo - * @param \Psr\Log\LoggerInterface $logger + * @param DesignInterface $design + * @param GroupedCollection $assets + * @param Repository $assetRepo + * @param LoggerInterface $logger */ public function __construct( - \Magento\Framework\View\DesignInterface $design, - \Magento\Framework\View\Asset\GroupedCollection $assets, - \Magento\Framework\View\Asset\Repository $assetRepo, - \Psr\Log\LoggerInterface $logger + DesignInterface $design, + GroupedCollection $assets, + protected readonly Repository $assetRepo, + protected readonly LoggerInterface $logger ) { $this->currentTheme = $design->getDesignTheme(); $this->pageAssets = $assets; - $this->assetRepo = $assetRepo; - $this->logger = $logger; } /** * Apply customized static files to frontend * - * @param \Magento\Framework\Event\Observer $observer + * @param EventObserver $observer * @return void * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ - public function execute(\Magento\Framework\Event\Observer $observer) + public function execute(EventObserver $observer) { - /** @var $themeFile \Magento\Theme\Model\Theme\File */ + /** @var $themeFile File */ foreach ($this->currentTheme->getCustomization()->getFiles() as $themeFile) { try { $service = $themeFile->getCustomizationService(); - if ($service instanceof \Magento\Framework\View\Design\Theme\Customization\FileAssetInterface) { + if ($service instanceof FileAssetInterface) { $identifier = $themeFile->getData('file_path'); - $dirPath = \Magento\Framework\View\Design\Theme\Customization\Path::DIR_NAME + $dirPath = Path::DIR_NAME . '/' . $this->currentTheme->getId(); $asset = $this->assetRepo->createArbitrary( $identifier, $dirPath, DirectoryList::MEDIA, - \Magento\Framework\UrlInterface::URL_TYPE_MEDIA + UrlInterface::URL_TYPE_MEDIA ); $this->pageAssets->add($identifier, $asset); } - } catch (\InvalidArgumentException $e) { + } catch (InvalidArgumentException $e) { $this->logger->critical($e); } } diff --git a/app/code/Magento/Theme/Observer/CheckThemeIsAssignedObserver.php b/app/code/Magento/Theme/Observer/CheckThemeIsAssignedObserver.php index ca7dad1f3362a..931f7b975d35f 100644 --- a/app/code/Magento/Theme/Observer/CheckThemeIsAssignedObserver.php +++ b/app/code/Magento/Theme/Observer/CheckThemeIsAssignedObserver.php @@ -6,32 +6,23 @@ namespace Magento\Theme\Observer; +use Magento\Framework\Event\ManagerInterface; use Magento\Framework\Event\Observer as EventObserver; use Magento\Framework\Event\ObserverInterface; +use Magento\Framework\View\Design\ThemeInterface; +use Magento\Theme\Model\Config\Customization; use Magento\Theme\Model\Theme; class CheckThemeIsAssignedObserver implements ObserverInterface { /** - * @var \Magento\Theme\Model\Config\Customization - */ - protected $themeConfig; - - /** - * @var \Magento\Framework\Event\ManagerInterface - */ - protected $eventDispatcher; - - /** - * @param \Magento\Theme\Model\Config\Customization $themeConfig - * @param \Magento\Framework\Event\ManagerInterface $eventDispatcher + * @param Customization $themeConfig + * @param ManagerInterface $eventDispatcher */ public function __construct( - \Magento\Theme\Model\Config\Customization $themeConfig, - \Magento\Framework\Event\ManagerInterface $eventDispatcher + protected readonly Customization $themeConfig, + protected readonly ManagerInterface $eventDispatcher ) { - $this->themeConfig = $themeConfig; - $this->eventDispatcher = $eventDispatcher; } /** @@ -43,8 +34,8 @@ public function __construct( public function execute(EventObserver $observer) { $theme = $observer->getEvent()->getData('theme'); - if ($theme instanceof \Magento\Framework\View\Design\ThemeInterface) { - /** @var $theme \Magento\Framework\View\Design\ThemeInterface */ + if ($theme instanceof ThemeInterface) { + /** @var ThemeInterface $theme */ if ($this->themeConfig->isThemeAssignedToStore($theme)) { $this->eventDispatcher->dispatch('assigned_theme_changed', ['theme' => $theme]); } diff --git a/app/code/Magento/Theme/Observer/CleanThemeRelatedContentObserver.php b/app/code/Magento/Theme/Observer/CleanThemeRelatedContentObserver.php index 006672f0890ad..41dc094e59d93 100644 --- a/app/code/Magento/Theme/Observer/CleanThemeRelatedContentObserver.php +++ b/app/code/Magento/Theme/Observer/CleanThemeRelatedContentObserver.php @@ -8,38 +8,25 @@ use Magento\Framework\Event\Observer as EventObserver; use Magento\Framework\Event\ObserverInterface; +use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\View\Design\Theme\ImageFactory; +use Magento\Framework\View\Design\ThemeInterface; +use Magento\Theme\Model\Config\Customization; use Magento\Theme\Model\Theme; +use Magento\Widget\Model\ResourceModel\Layout\Update\Collection; class CleanThemeRelatedContentObserver implements ObserverInterface { /** - * @var \Magento\Framework\View\Design\Theme\ImageFactory - */ - protected $themeImageFactory; - - /** - * @var \Magento\Widget\Model\ResourceModel\Layout\Update\Collection - */ - protected $updateCollection; - - /** - * @var \Magento\Theme\Model\Config\Customization - */ - protected $themeConfig; - - /** - * @param \Magento\Framework\View\Design\Theme\ImageFactory $themeImageFactory - * @param \Magento\Widget\Model\ResourceModel\Layout\Update\Collection $updateCollection - * @param \Magento\Theme\Model\Config\Customization $themeConfig + * @param ImageFactory $themeImageFactory + * @param Collection $updateCollection + * @param Customization $themeConfig */ public function __construct( - \Magento\Framework\View\Design\Theme\ImageFactory $themeImageFactory, - \Magento\Widget\Model\ResourceModel\Layout\Update\Collection $updateCollection, - \Magento\Theme\Model\Config\Customization $themeConfig + protected readonly ImageFactory $themeImageFactory, + protected readonly Collection $updateCollection, + protected readonly Customization $themeConfig ) { - $this->themeImageFactory = $themeImageFactory; - $this->updateCollection = $updateCollection; - $this->themeConfig = $themeConfig; } /** @@ -47,17 +34,17 @@ public function __construct( * * @param EventObserver $observer * @return void - * @throws \Magento\Framework\Exception\LocalizedException + * @throws LocalizedException */ public function execute(EventObserver $observer) { $theme = $observer->getEvent()->getData('theme'); - if (!($theme instanceof \Magento\Framework\View\Design\ThemeInterface)) { + if (!($theme instanceof ThemeInterface)) { return; } - /** @var $theme \Magento\Framework\View\Design\ThemeInterface */ + /** @var $theme ThemeInterface */ if ($this->themeConfig->isThemeAssignedToStore($theme)) { - throw new \Magento\Framework\Exception\LocalizedException(__('Theme isn\'t deletable.')); + throw new LocalizedException(__('Theme isn\'t deletable.')); } $this->themeImageFactory->create(['theme' => $theme])->removePreviewImage(); $this->updateCollection->addThemeFilter($theme->getId())->delete(); diff --git a/app/code/Magento/Theme/Plugin/LoadDesignPlugin.php b/app/code/Magento/Theme/Plugin/LoadDesignPlugin.php index c4f8d3a905d0f..1fc3c4c23521e 100644 --- a/app/code/Magento/Theme/Plugin/LoadDesignPlugin.php +++ b/app/code/Magento/Theme/Plugin/LoadDesignPlugin.php @@ -18,26 +18,14 @@ */ class LoadDesignPlugin { - /** - * @var DesignLoader - */ - private $designLoader; - - /** - * @var MessageManagerInterface - */ - private $messageManager; - /** * @param DesignLoader $designLoader * @param MessageManagerInterface $messageManager */ public function __construct( - DesignLoader $designLoader, - MessageManagerInterface $messageManager + private readonly DesignLoader $designLoader, + private readonly MessageManagerInterface $messageManager ) { - $this->designLoader = $designLoader; - $this->messageManager = $messageManager; } /** diff --git a/app/code/Magento/Theme/Setup/Patch/Data/ConvertSerializedData.php b/app/code/Magento/Theme/Setup/Patch/Data/ConvertSerializedData.php index 0e132eb429f60..e6b20e6a18697 100644 --- a/app/code/Magento/Theme/Setup/Patch/Data/ConvertSerializedData.php +++ b/app/code/Magento/Theme/Setup/Patch/Data/ConvertSerializedData.php @@ -10,6 +10,7 @@ use Magento\Framework\DB\FieldDataConverterFactory; use Magento\Framework\DB\Select\QueryModifierFactory; use Magento\Framework\App\ResourceConnection; +use Magento\Framework\Setup\ModuleDataSetupInterface; use Magento\Framework\Setup\Patch\DataPatchInterface; use Magento\Framework\Setup\Patch\PatchVersionInterface; @@ -19,35 +20,17 @@ */ class ConvertSerializedData implements DataPatchInterface, PatchVersionInterface { - /** - * @var \Magento\Framework\Setup\ModuleDataSetupInterface - */ - private $moduleDataSetup; - - /** - * @var FieldDataConverterFactory - */ - private $fieldDataConverterFactory; - - /** - * @var QueryModifierFactory - */ - private $queryModifierFactory; - /** * ConvertSerializedData constructor. - * @param \Magento\Framework\Setup\ModuleDataSetupInterface $moduleDataSetup + * @param ModuleDataSetupInterface $moduleDataSetup * @param FieldDataConverterFactory $fieldDataConverterFactory * @param QueryModifierFactory $queryModifierFactory */ public function __construct( - \Magento\Framework\Setup\ModuleDataSetupInterface $moduleDataSetup, - FieldDataConverterFactory $fieldDataConverterFactory, - QueryModifierFactory $queryModifierFactory + private readonly ModuleDataSetupInterface $moduleDataSetup, + private readonly FieldDataConverterFactory $fieldDataConverterFactory, + private readonly QueryModifierFactory $queryModifierFactory ) { - $this->moduleDataSetup = $moduleDataSetup; - $this->fieldDataConverterFactory = $fieldDataConverterFactory; - $this->queryModifierFactory = $queryModifierFactory; } /** diff --git a/app/code/Magento/Theme/Setup/Patch/Data/RegisterThemes.php b/app/code/Magento/Theme/Setup/Patch/Data/RegisterThemes.php index 31b6c6b47773e..19bdeea34c5b0 100644 --- a/app/code/Magento/Theme/Setup/Patch/Data/RegisterThemes.php +++ b/app/code/Magento/Theme/Setup/Patch/Data/RegisterThemes.php @@ -6,6 +6,7 @@ namespace Magento\Theme\Setup\Patch\Data; +use Magento\Framework\Setup\ModuleDataSetupInterface; use Magento\Theme\Model\Theme\Registration; use Magento\Framework\App\ResourceConnection; use Magento\Framework\Setup\Patch\DataPatchInterface; @@ -17,26 +18,15 @@ */ class RegisterThemes implements DataPatchInterface, PatchVersionInterface { - /** - * @var \Magento\Framework\Setup\ModuleDataSetupInterface - */ - private $moduleDataSetup; - /** - * @var Registration - */ - private $themeRegistration; - /** * RegisterThemes constructor. - * @param \Magento\Framework\Setup\ModuleDataSetupInterface $moduleDataSetup + * @param ModuleDataSetupInterface $moduleDataSetup * @param Registration $themeRegistration */ public function __construct( - \Magento\Framework\Setup\ModuleDataSetupInterface $moduleDataSetup, - Registration $themeRegistration + private readonly ModuleDataSetupInterface $moduleDataSetup, + private readonly Registration $themeRegistration ) { - $this->moduleDataSetup = $moduleDataSetup; - $this->themeRegistration = $themeRegistration; } /** diff --git a/app/code/Magento/Theme/Setup/RecurringData.php b/app/code/Magento/Theme/Setup/RecurringData.php index 972b60dc67f89..f604053312d5d 100644 --- a/app/code/Magento/Theme/Setup/RecurringData.php +++ b/app/code/Magento/Theme/Setup/RecurringData.php @@ -18,28 +18,16 @@ */ class RecurringData implements InstallDataInterface { - /** - * Theme registration - * - * @var Registration - */ - private $themeRegistration; - - /** - * @var IndexerRegistry - */ - private $indexerRegistry; - /** * Init * * @param Registration $themeRegistration * @param IndexerRegistry $indexerRegistry */ - public function __construct(Registration $themeRegistration, IndexerRegistry $indexerRegistry) - { - $this->themeRegistration = $themeRegistration; - $this->indexerRegistry = $indexerRegistry; + public function __construct( + private readonly Registration $themeRegistration, + private readonly IndexerRegistry $indexerRegistry + ) { } /** diff --git a/app/code/Magento/Theme/Ui/Component/Design/Config/DataProvider.php b/app/code/Magento/Theme/Ui/Component/Design/Config/DataProvider.php index 1960b6f67f29f..3d468b71145a5 100644 --- a/app/code/Magento/Theme/Ui/Component/Design/Config/DataProvider.php +++ b/app/code/Magento/Theme/Ui/Component/Design/Config/DataProvider.php @@ -9,6 +9,7 @@ use Magento\Framework\Api\Search\ReportingInterface; use Magento\Framework\Api\Search\SearchCriteriaBuilder; use Magento\Framework\App\RequestInterface; +use Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider as UiComponentDataProvider; use Magento\Store\Model\StoreManagerInterface; /** @@ -17,14 +18,8 @@ * @api * @since 100.1.0 */ -class DataProvider extends \Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider +class DataProvider extends UiComponentDataProvider { - /** - * @var StoreManagerInterface - * @since 100.1.0 - */ - protected $storeManager; - /** * @param string $name * @param string $primaryFieldName @@ -46,7 +41,7 @@ public function __construct( SearchCriteriaBuilder $searchCriteriaBuilder, RequestInterface $request, FilterBuilder $filterBuilder, - StoreManagerInterface $storeManager, + protected readonly StoreManagerInterface $storeManager, array $meta = [], array $data = [] ) { @@ -61,7 +56,6 @@ public function __construct( $meta, $data ); - $this->storeManager = $storeManager; } /** diff --git a/app/code/Magento/Theme/Ui/Component/Design/Config/SearchRobots/ResetButton.php b/app/code/Magento/Theme/Ui/Component/Design/Config/SearchRobots/ResetButton.php index f0e668d10c3a6..94eebb96979be 100644 --- a/app/code/Magento/Theme/Ui/Component/Design/Config/SearchRobots/ResetButton.php +++ b/app/code/Magento/Theme/Ui/Component/Design/Config/SearchRobots/ResetButton.php @@ -6,8 +6,10 @@ namespace Magento\Theme\Ui\Component\Design\Config\SearchRobots; use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\Exception\LocalizedException; use Magento\Framework\View\Element\UiComponent\ContextInterface; use Magento\Framework\View\Element\UiComponentFactory; +use Magento\Framework\View\Element\UiComponentInterface; use Magento\Ui\Component\Form\Field; /** @@ -23,17 +25,12 @@ class ResetButton extends Field */ const XML_PATH_ROBOTS_DEFAULT_CUSTOM_INSTRUCTIONS = 'design/search_engine_robots/default_custom_instructions'; - /** - * @var ScopeConfigInterface - */ - private $scopeConfig; - /** * ResetButton constructor * * @param ContextInterface $context * @param UiComponentFactory $uiComponentFactory - * @param \Magento\Framework\View\Element\UiComponentInterface[] $components + * @param UiComponentInterface[] $components * @param array $data * @param ScopeConfigInterface $scopeConfig */ @@ -42,9 +39,8 @@ public function __construct( UiComponentFactory $uiComponentFactory, $components, array $data, - ScopeConfigInterface $scopeConfig + private readonly ScopeConfigInterface $scopeConfig ) { - $this->scopeConfig = $scopeConfig; parent::__construct($context, $uiComponentFactory, $components, $data); } @@ -65,7 +61,7 @@ private function getRobotsDefaultCustomInstructions() * Add js listener to reset button * * @return void - * @throws \Magento\Framework\Exception\LocalizedException + * @throws LocalizedException * @since 100.1.9 */ public function prepare() diff --git a/app/code/Magento/Theme/Ui/Component/Listing/Column/EditAction.php b/app/code/Magento/Theme/Ui/Component/Listing/Column/EditAction.php index 821eee8114bae..e04d7044a6ec4 100644 --- a/app/code/Magento/Theme/Ui/Component/Listing/Column/EditAction.php +++ b/app/code/Magento/Theme/Ui/Component/Listing/Column/EditAction.php @@ -17,11 +17,6 @@ */ class EditAction extends Column { - /** - * @var UrlInterface - */ - protected $urlBuilder; - /** * Constructor * @@ -34,11 +29,10 @@ class EditAction extends Column public function __construct( ContextInterface $context, UiComponentFactory $uiComponentFactory, - UrlInterface $urlBuilder, + protected readonly UrlInterface $urlBuilder, array $components = [], array $data = [] ) { - $this->urlBuilder = $urlBuilder; parent::__construct($context, $uiComponentFactory, $components, $data); } diff --git a/app/code/Magento/Theme/Ui/Component/Listing/Column/ViewAction.php b/app/code/Magento/Theme/Ui/Component/Listing/Column/ViewAction.php index a49e622b9d42a..eba1044ed9f4c 100644 --- a/app/code/Magento/Theme/Ui/Component/Listing/Column/ViewAction.php +++ b/app/code/Magento/Theme/Ui/Component/Listing/Column/ViewAction.php @@ -18,11 +18,6 @@ */ class ViewAction extends Column { - /** - * @var UrlInterface - */ - private $urlBuilder; - /** * Constructor * @@ -35,11 +30,10 @@ class ViewAction extends Column public function __construct( ContextInterface $context, UiComponentFactory $uiComponentFactory, - UrlInterface $urlBuilder, + private readonly UrlInterface $urlBuilder, array $components = [], array $data = [] ) { - $this->urlBuilder = $urlBuilder; parent::__construct($context, $uiComponentFactory, $components, $data); } diff --git a/app/code/Magento/Theme/Ui/Component/Theme/DataProvider/SearchResult.php b/app/code/Magento/Theme/Ui/Component/Theme/DataProvider/SearchResult.php index 696b38a71761a..375da74e5e9fc 100644 --- a/app/code/Magento/Theme/Ui/Component/Theme/DataProvider/SearchResult.php +++ b/app/code/Magento/Theme/Ui/Component/Theme/DataProvider/SearchResult.php @@ -8,10 +8,14 @@ namespace Magento\Theme\Ui\Component\Theme\DataProvider; +use Magento\Framework\App\Area; +use Magento\Framework\View\Design\ThemeInterface; +use Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult as DataProviderSearchResult; + /** * Theme search result */ -class SearchResult extends \Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult +class SearchResult extends DataProviderSearchResult { /** * {@inheritdoc} @@ -35,10 +39,10 @@ protected function _initSelect() { parent::_initSelect(); $this - ->addFieldToFilter('main_table.area', \Magento\Framework\App\Area::AREA_FRONTEND) + ->addFieldToFilter('main_table.area', Area::AREA_FRONTEND) ->addFieldToFilter('main_table.type', ['in' => [ - \Magento\Framework\View\Design\ThemeInterface::TYPE_PHYSICAL, - \Magento\Framework\View\Design\ThemeInterface::TYPE_VIRTUAL, + ThemeInterface::TYPE_PHYSICAL, + ThemeInterface::TYPE_VIRTUAL, ]]) ; diff --git a/app/code/Magento/Theme/ViewModel/Block/Html/Header/LogoPathResolver.php b/app/code/Magento/Theme/ViewModel/Block/Html/Header/LogoPathResolver.php index 1a10fe9177320..f3229b27d96d3 100644 --- a/app/code/Magento/Theme/ViewModel/Block/Html/Header/LogoPathResolver.php +++ b/app/code/Magento/Theme/ViewModel/Block/Html/Header/LogoPathResolver.php @@ -17,18 +17,12 @@ */ class LogoPathResolver implements LogoPathResolverInterface, ArgumentInterface { - /** - * @var ScopeConfigInterface - */ - private $scopeConfig; - /** * @param ScopeConfigInterface $scopeConfig */ public function __construct( - ScopeConfigInterface $scopeConfig + private readonly ScopeConfigInterface $scopeConfig ) { - $this->scopeConfig = $scopeConfig; } /** diff --git a/app/code/Magento/Theme/ViewModel/Block/Html/Header/LogoSizeResolver.php b/app/code/Magento/Theme/ViewModel/Block/Html/Header/LogoSizeResolver.php index 24d7fa3f7ab95..0c8198577600e 100644 --- a/app/code/Magento/Theme/ViewModel/Block/Html/Header/LogoSizeResolver.php +++ b/app/code/Magento/Theme/ViewModel/Block/Html/Header/LogoSizeResolver.php @@ -26,18 +26,12 @@ class LogoSizeResolver implements LogoSizeResolverInterface, ArgumentInterface */ private const XML_PATH_DESIGN_HEADER_LOGO_HEIGHT = 'design/header/logo_height'; - /** - * @var ScopeConfigInterface - */ - private $scopeConfig; - /** * @param ScopeConfigInterface $scopeConfig */ public function __construct( - ScopeConfigInterface $scopeConfig + private readonly ScopeConfigInterface $scopeConfig ) { - $this->scopeConfig = $scopeConfig; } /** diff --git a/app/code/Magento/Theme/ViewModel/Block/SessionConfig.php b/app/code/Magento/Theme/ViewModel/Block/SessionConfig.php index d697c0a61b448..242652e1d1cf0 100644 --- a/app/code/Magento/Theme/ViewModel/Block/SessionConfig.php +++ b/app/code/Magento/Theme/ViewModel/Block/SessionConfig.php @@ -15,22 +15,14 @@ */ class SessionConfig implements ArgumentInterface { - /** - * Session config - * - * @var ConfigInterface - */ - private $sessionConfig; - /** * Constructor * * @param ConfigInterface $sessionConfig */ public function __construct( - ConfigInterface $sessionConfig + private readonly ConfigInterface $sessionConfig ) { - $this->sessionConfig = $sessionConfig; } /** * Get session.cookie_secure diff --git a/app/code/Magento/Theme/registration.php b/app/code/Magento/Theme/registration.php index c00f6e4ba2136..533dbc81cb4b3 100644 --- a/app/code/Magento/Theme/registration.php +++ b/app/code/Magento/Theme/registration.php @@ -6,4 +6,8 @@ use Magento\Framework\Component\ComponentRegistrar; -ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_Theme', __DIR__); +ComponentRegistrar::register( + ComponentRegistrar::MODULE, + 'Magento_Theme', + __DIR__ +);