diff --git a/app/code/Magento/SampleData/Console/Command/SampleDataDeployCommand.php b/app/code/Magento/SampleData/Console/Command/SampleDataDeployCommand.php index 1358d80e84830..ede11a9f86399 100644 --- a/app/code/Magento/SampleData/Console/Command/SampleDataDeployCommand.php +++ b/app/code/Magento/SampleData/Console/Command/SampleDataDeployCommand.php @@ -31,28 +31,16 @@ class SampleDataDeployCommand extends Command { public const OPTION_NO_UPDATE = 'no-update'; - /** @var Filesystem */ - private Filesystem $filesystem; - - /** @var Dependency */ - private Dependency $sampleDataDependency; - - /** @var ApplicationFactory */ - private ApplicationFactory $applicationFactory; - /** * @param Filesystem $filesystem * @param Dependency $sampleDataDependency * @param ApplicationFactory $applicationFactory */ public function __construct( - Filesystem $filesystem, - Dependency $sampleDataDependency, - ApplicationFactory $applicationFactory + private readonly Filesystem $filesystem, + private readonly Dependency $sampleDataDependency, + private readonly ApplicationFactory $applicationFactory ) { - $this->filesystem = $filesystem; - $this->sampleDataDependency = $sampleDataDependency; - $this->applicationFactory = $applicationFactory; parent::__construct(); } diff --git a/app/code/Magento/SampleData/Console/Command/SampleDataRemoveCommand.php b/app/code/Magento/SampleData/Console/Command/SampleDataRemoveCommand.php index 8251bf62c302b..cc549529149d5 100644 --- a/app/code/Magento/SampleData/Console/Command/SampleDataRemoveCommand.php +++ b/app/code/Magento/SampleData/Console/Command/SampleDataRemoveCommand.php @@ -26,43 +26,18 @@ class SampleDataRemoveCommand extends Command { public const OPTION_NO_UPDATE = 'no-update'; - /** - * @var Filesystem - */ - private $filesystem; - - /** - * @var Dependency - */ - private $sampleDataDependency; - - /** - * @var ArrayInputFactory - * @deprecated 100.1.0 - */ - private $arrayInputFactory; // phpcs:ignore Magento2.Commenting.ClassPropertyPHPDocFormatting - - /** - * @var ApplicationFactory - */ - private $applicationFactory; - /** * @param Filesystem $filesystem * @param Dependency $sampleDataDependency - * @param ArrayInputFactory $arrayInputFactory + * @param ArrayInputFactory $arrayInputFactory @deprecated 100.1.0 * @param ApplicationFactory $applicationFactory */ public function __construct( - Filesystem $filesystem, - Dependency $sampleDataDependency, - ArrayInputFactory $arrayInputFactory, - ApplicationFactory $applicationFactory + private readonly Filesystem $filesystem, + private readonly Dependency $sampleDataDependency, + private readonly ArrayInputFactory $arrayInputFactory, + private readonly ApplicationFactory $applicationFactory ) { - $this->filesystem = $filesystem; - $this->sampleDataDependency = $sampleDataDependency; - $this->arrayInputFactory = $arrayInputFactory; - $this->applicationFactory = $applicationFactory; parent::__construct(); } diff --git a/app/code/Magento/SampleData/Console/Command/SampleDataResetCommand.php b/app/code/Magento/SampleData/Console/Command/SampleDataResetCommand.php index da0d4bb40bf8d..bab42c9cbfdd5 100644 --- a/app/code/Magento/SampleData/Console/Command/SampleDataResetCommand.php +++ b/app/code/Magento/SampleData/Console/Command/SampleDataResetCommand.php @@ -19,34 +19,16 @@ */ class SampleDataResetCommand extends Command { - /** - * @var Dependency - */ - private $sampleDataDependency; - - /** - * @var ModuleResource - */ - private $moduleResource; - - /** - * @var PackageInfo - */ - private $packageInfo; - /** * @param Dependency $sampleDataDependency * @param ModuleResource $moduleResource * @param PackageInfo $packageInfo */ public function __construct( - Dependency $sampleDataDependency, - ModuleResource $moduleResource, - PackageInfo $packageInfo + private readonly Dependency $sampleDataDependency, + private readonly ModuleResource $moduleResource, + private readonly PackageInfo $packageInfo ) { - $this->sampleDataDependency = $sampleDataDependency; - $this->moduleResource = $moduleResource; - $this->packageInfo = $packageInfo; parent::__construct(); } diff --git a/app/code/Magento/SampleData/Console/CommandList.php b/app/code/Magento/SampleData/Console/CommandList.php index 4a1cd4a8c75b3..6c78ee6433532 100644 --- a/app/code/Magento/SampleData/Console/CommandList.php +++ b/app/code/Magento/SampleData/Console/CommandList.php @@ -5,26 +5,23 @@ */ namespace Magento\SampleData\Console; +use Exception; +use Magento\Framework\Console\CommandListInterface; use Magento\Framework\ObjectManagerInterface; +use Magento\SampleData\Console\Command\SampleDataDeployCommand; +use Magento\SampleData\Console\Command\SampleDataRemoveCommand; /** * Class CommandList */ -class CommandList implements \Magento\Framework\Console\CommandListInterface +class CommandList implements CommandListInterface { /** - * Object Manager - * - * @var ObjectManagerInterface + * @param ObjectManagerInterface $objectManager Object Manager */ - private $objectManager; - - /** - * @param ObjectManagerInterface $objectManager - */ - public function __construct(ObjectManagerInterface $objectManager) - { - $this->objectManager = $objectManager; + public function __construct( + private readonly ObjectManagerInterface $objectManager + ) { } /** @@ -35,8 +32,8 @@ public function __construct(ObjectManagerInterface $objectManager) protected function getCommandsClasses() { return [ - \Magento\SampleData\Console\Command\SampleDataDeployCommand::class, - \Magento\SampleData\Console\Command\SampleDataRemoveCommand::class + SampleDataDeployCommand::class, + SampleDataRemoveCommand::class ]; } @@ -50,7 +47,7 @@ public function getCommands() if (class_exists($class)) { $commands[] = $this->objectManager->get($class); } else { - throw new \Exception('Class ' . $class . ' does not exist'); + throw new Exception('Class ' . $class . ' does not exist'); } } return $commands; diff --git a/app/code/Magento/SampleData/Model/Dependency.php b/app/code/Magento/SampleData/Model/Dependency.php index 682331c3041cf..db342585d211b 100644 --- a/app/code/Magento/SampleData/Model/Dependency.php +++ b/app/code/Magento/SampleData/Model/Dependency.php @@ -11,8 +11,11 @@ use Magento\Framework\Composer\ComposerInformation; use Magento\Framework\Config\Composer\Package; use Magento\Framework\Config\Composer\PackageFactory; +use Magento\Framework\Exception\FileSystemException; use Magento\Framework\Filesystem; use Magento\Framework\Filesystem\Directory\ReadFactory; +use Magento\Framework\Filesystem\Directory\ReadInterface; +use stdClass; /** * Sample Data dependency @@ -24,26 +27,6 @@ class Dependency */ public const SAMPLE_DATA_SUGGEST = 'Sample Data version:'; - /** - * @var ComposerInformation - */ - protected $composerInformation; - - /** - * @var PackageFactory - */ - private $packageFactory; - - /** - * @var ComponentRegistrarInterface - */ - private $componentRegistrar; - - /** - * @var ReadFactory - */ - private $directoryReadFactory; - /** * Initialize dependencies. * @@ -51,19 +34,16 @@ class Dependency * @param Filesystem $filesystem @deprecated 2.3.0 $directoryReadFactory is used instead * @param PackageFactory $packageFactory * @param ComponentRegistrarInterface $componentRegistrar - * @param Filesystem\Directory\ReadFactory|null $directoryReadFactory + * @param ReadFactory|null $directoryReadFactory * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function __construct( - ComposerInformation $composerInformation, + protected readonly ComposerInformation $composerInformation, Filesystem $filesystem, - PackageFactory $packageFactory, - ComponentRegistrarInterface $componentRegistrar, - \Magento\Framework\Filesystem\Directory\ReadFactory $directoryReadFactory = null + private readonly PackageFactory $packageFactory, + private readonly ComponentRegistrarInterface $componentRegistrar, + private ?ReadFactory $directoryReadFactory = null ) { - $this->composerInformation = $composerInformation; - $this->packageFactory = $packageFactory; - $this->componentRegistrar = $componentRegistrar; $this->directoryReadFactory = $directoryReadFactory ?: ObjectManager::getInstance()->get(ReadFactory::class); } @@ -72,7 +52,7 @@ public function __construct( * Retrieve list of sample data packages from suggests * * @return array - * @throws \Magento\Framework\Exception\FileSystemException + * @throws FileSystemException */ public function getSampleDataPackages() { @@ -91,7 +71,7 @@ public function getSampleDataPackages() * Retrieve suggested sample data packages from modules composer.json * * @return array - * @throws \Magento\Framework\Exception\FileSystemException + * @throws FileSystemException */ protected function getSuggestsFromModules() { @@ -111,7 +91,7 @@ protected function getSuggestsFromModules() * * @param string $moduleDir * @return Package - * @throws \Magento\Framework\Exception\FileSystemException + * @throws FileSystemException */ private function getModuleComposerPackage($moduleDir) { @@ -122,13 +102,13 @@ private function getModuleComposerPackage($moduleDir) * see: https://github.com/php-pds/skeleton */ foreach ([$moduleDir, $moduleDir . DIRECTORY_SEPARATOR . '..'] as $dir) { - /** @var Filesystem\Directory\ReadInterface $directory */ + /** @var ReadInterface $directory */ $directory = $this->directoryReadFactory->create($dir); if ($directory->isExist('composer.json') && $directory->isReadable('composer.json')) { /** @var Package $package */ return $this->packageFactory->create(['json' => json_decode($directory->readFile('composer.json'))]); } } - return $this->packageFactory->create(['json' => new \stdClass]); + return $this->packageFactory->create(['json' => new stdClass]); } } diff --git a/app/code/Magento/SampleData/Setup/Patch/Data/ClearSampleDataState.php b/app/code/Magento/SampleData/Setup/Patch/Data/ClearSampleDataState.php index 2725573b1ab99..598ab46fc2d76 100644 --- a/app/code/Magento/SampleData/Setup/Patch/Data/ClearSampleDataState.php +++ b/app/code/Magento/SampleData/Setup/Patch/Data/ClearSampleDataState.php @@ -7,8 +7,10 @@ namespace Magento\SampleData\Setup\Patch\Data; use Magento\Framework\Setup; +use Magento\Framework\Setup\ModuleDataSetupInterface; use Magento\Framework\Setup\Patch\DataPatchInterface; use Magento\Framework\Setup\Patch\PatchVersionInterface; +use Magento\Framework\Setup\SampleData\State; /** * Class ClearSampleDataState @@ -16,27 +18,15 @@ */ class ClearSampleDataState implements DataPatchInterface, PatchVersionInterface { - /** - * @var \Magento\Framework\Setup\ModuleDataSetupInterface - */ - private $moduleDataSetup; - - /** - * @var Setup\SampleData\State - */ - private $state; - /** * ClearSampleDataState constructor. - * @param \Magento\Framework\Setup\ModuleDataSetupInterface $moduleDataSetup - * @param Setup\SampleData\State $state + * @param ModuleDataSetupInterface $moduleDataSetup + * @param State $state */ public function __construct( - \Magento\Framework\Setup\ModuleDataSetupInterface $moduleDataSetup, - \Magento\Framework\Setup\SampleData\State $state + private readonly ModuleDataSetupInterface $moduleDataSetup, + private readonly State $state ) { - $this->moduleDataSetup = $moduleDataSetup; - $this->state = $state; } /** diff --git a/app/code/Magento/SampleData/cli_commands.php b/app/code/Magento/SampleData/cli_commands.php index 00471d39a4564..725c6567e7eea 100644 --- a/app/code/Magento/SampleData/cli_commands.php +++ b/app/code/Magento/SampleData/cli_commands.php @@ -4,6 +4,9 @@ * See COPYING.txt for license details. */ +use Magento\Framework\Console\CommandLocator; +use Magento\SampleData\Console\CommandList; + if (PHP_SAPI == 'cli') { - \Magento\Framework\Console\CommandLocator::register(\Magento\SampleData\Console\CommandList::class); + CommandLocator::register(CommandList::class); } diff --git a/app/code/Magento/SampleData/registration.php b/app/code/Magento/SampleData/registration.php index 2e86fc7e1cc48..08cea5ef26fb6 100644 --- a/app/code/Magento/SampleData/registration.php +++ b/app/code/Magento/SampleData/registration.php @@ -6,4 +6,8 @@ use Magento\Framework\Component\ComponentRegistrar; -ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_SampleData', __DIR__); +ComponentRegistrar::register( + ComponentRegistrar::MODULE, + 'Magento_SampleData', + __DIR__ +);