Skip to content

Commit 427717a

Browse files
authored
ENGCOM-7238: Cleanup ObjectManager usage - Magento_Developer #27491
2 parents 4b9dbf7 + e10243d commit 427717a

File tree

7 files changed

+172
-145
lines changed

7 files changed

+172
-145
lines changed

app/code/Magento/Developer/Console/Command/GeneratePatchCommand.php

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@
77

88
namespace Magento\Developer\Console\Command;
99

10-
use Magento\Framework\App\ObjectManager;
1110
use Magento\Framework\Component\ComponentRegistrar;
1211
use Magento\Framework\Console\Cli;
1312
use Magento\Framework\Exception\FileSystemException;
14-
use Magento\Framework\Filesystem\DirectoryList;
1513
use Magento\Framework\Filesystem\Directory\ReadFactory;
1614
use Magento\Framework\Filesystem\Directory\WriteFactory;
15+
use Magento\Framework\Filesystem\DirectoryList;
1716
use Symfony\Component\Console\Command\Command;
1817
use Symfony\Component\Console\Input\InputArgument;
1918
use Symfony\Component\Console\Input\InputInterface;
@@ -58,20 +57,20 @@ class GeneratePatchCommand extends Command
5857
* GeneratePatchCommand constructor.
5958
*
6059
* @param ComponentRegistrar $componentRegistrar
61-
* @param DirectoryList|null $directoryList
62-
* @param ReadFactory|null $readFactory
63-
* @param WriteFactory|null $writeFactory
60+
* @param DirectoryList $directoryList
61+
* @param ReadFactory $readFactory
62+
* @param WriteFactory $writeFactory
6463
*/
6564
public function __construct(
6665
ComponentRegistrar $componentRegistrar,
67-
DirectoryList $directoryList = null,
68-
ReadFactory $readFactory = null,
69-
WriteFactory $writeFactory = null
66+
DirectoryList $directoryList,
67+
ReadFactory $readFactory,
68+
WriteFactory $writeFactory
7069
) {
7170
$this->componentRegistrar = $componentRegistrar;
72-
$this->directoryList = $directoryList ?: ObjectManager::getInstance()->get(DirectoryList::class);
73-
$this->readFactory = $readFactory ?: ObjectManager::getInstance()->get(ReadFactory::class);
74-
$this->writeFactory = $writeFactory ?: ObjectManager::getInstance()->get(WriteFactory::class);
71+
$this->directoryList = $directoryList;
72+
$this->readFactory = $readFactory;
73+
$this->writeFactory = $writeFactory;
7574

7675
parent::__construct();
7776
}
@@ -120,6 +119,7 @@ protected function configure()
120119
*
121120
* @param InputInterface $input
122121
* @param OutputInterface $output
122+
*
123123
* @return int
124124
* @throws FileSystemException
125125
*/
@@ -194,8 +194,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
194194
private function getPatchTemplate(): string
195195
{
196196
$read = $this->readFactory->create(__DIR__ . '/');
197-
$content = $read->readFile('patch_template.php.dist');
198-
return $content;
197+
return $read->readFile('patch_template.php.dist');
199198
}
200199

201200
/**
@@ -207,7 +206,6 @@ private function getPatchTemplate(): string
207206
private function getRevertMethodTemplate(): string
208207
{
209208
$read = $this->readFactory->create(__DIR__ . '/');
210-
$content = $read->readFile('template_revert_function.php.dist');
211-
return $content;
209+
return $read->readFile('template_revert_function.php.dist');
212210
}
213211
}

app/code/Magento/Developer/Model/Css/PreProcessor/FileGenerator/PublicationDecorator.php

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Developer\Model\Css\PreProcessor\FileGenerator;
79

810
use Magento\Developer\Model\Config\Source\WorkflowType;
911
use Magento\Framework\App\Config\ScopeConfigInterface;
10-
use Magento\Framework\App\ObjectManager;
1112
use Magento\Framework\App\State;
1213
use Magento\Framework\App\View\Asset\Publisher;
1314
use Magento\Framework\Css\PreProcessor\File\Temporary;
@@ -31,34 +32,35 @@ class PublicationDecorator extends RelatedGenerator
3132
private $scopeConfig;
3233

3334
/**
34-
* @var bool
35+
* @var State
3536
*/
36-
private $hasRelatedPublishing;
37+
private $state;
3738

3839
/**
39-
* @var State
40+
* @var bool
4041
*/
41-
private $state;
42+
private $hasRelatedPublishing;
4243

4344
/**
44-
* Constructor
45-
*
4645
* @param Repository $assetRepository
4746
* @param Temporary $temporaryFile
4847
* @param Publisher $assetPublisher
4948
* @param ScopeConfigInterface $scopeConfig
49+
* @param State $state
5050
* @param bool $hasRelatedPublishing
5151
*/
5252
public function __construct(
5353
Repository $assetRepository,
5454
Temporary $temporaryFile,
5555
Publisher $assetPublisher,
5656
ScopeConfigInterface $scopeConfig,
57+
State $state,
5758
$hasRelatedPublishing = false
5859
) {
5960
parent::__construct($assetRepository, $temporaryFile);
6061
$this->assetPublisher = $assetPublisher;
6162
$this->scopeConfig = $scopeConfig;
63+
$this->state = $state;
6264
$this->hasRelatedPublishing = $hasRelatedPublishing;
6365
}
6466

@@ -69,7 +71,7 @@ protected function generateRelatedFile($relatedFileId, LocalInterface $asset)
6971
{
7072
$relatedAsset = parent::generateRelatedFile($relatedFileId, $asset);
7173
$isClientSideCompilation =
72-
$this->getState()->getMode() !== State::MODE_PRODUCTION
74+
$this->state->getMode() !== State::MODE_PRODUCTION
7375
&& WorkflowType::CLIENT_SIDE_COMPILATION === $this->scopeConfig->getValue(WorkflowType::CONFIG_NAME_PATH);
7476

7577
if ($this->hasRelatedPublishing || $isClientSideCompilation) {
@@ -78,17 +80,4 @@ protected function generateRelatedFile($relatedFileId, LocalInterface $asset)
7880

7981
return $relatedAsset;
8082
}
81-
82-
/**
83-
* @return State
84-
* @deprecated 100.2.0
85-
*/
86-
private function getState()
87-
{
88-
if (null === $this->state) {
89-
$this->state = ObjectManager::getInstance()->get(State::class);
90-
}
91-
92-
return $this->state;
93-
}
9483
}

app/code/Magento/Developer/Model/TemplateEngine/Plugin/DebugHints.php

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<?php
22
/**
3-
* Plugin for the template engine factory that makes a decision of whether to activate debugging hints or not
4-
*
53
* Copyright © Magento, Inc. All rights reserved.
64
* See COPYING.txt for license details.
75
*/
@@ -16,6 +14,9 @@
1614
use Magento\Store\Model\StoreManagerInterface;
1715
use Magento\Framework\App\Request\Http;
1816

17+
/**
18+
* Plugin for the template engine factory that makes a decision of whether to activate debugging hints or not
19+
*/
1920
class DebugHints
2021
{
2122
/**
@@ -26,22 +27,27 @@ class DebugHints
2627
/**
2728
* @var ScopeConfigInterface
2829
*/
29-
protected $scopeConfig;
30+
private $scopeConfig;
3031

3132
/**
3233
* @var StoreManagerInterface
3334
*/
34-
protected $storeManager;
35+
private $storeManager;
3536

3637
/**
3738
* @var DevHelper
3839
*/
39-
protected $devHelper;
40+
private $devHelper;
4041

4142
/**
4243
* @var DebugHintsFactory
4344
*/
44-
protected $debugHintsFactory;
45+
private $debugHintsFactory;
46+
47+
/**
48+
* @var Http
49+
*/
50+
private $http;
4551

4652
/**
4753
* XPath of configuration of the debug hints
@@ -52,7 +58,7 @@ class DebugHints
5258
*
5359
* @var string
5460
*/
55-
protected $debugHintsPath;
61+
private $debugHintsPath;
5662

5763
/**
5864
* XPath of configuration of the debug hints show with parameter
@@ -77,8 +83,8 @@ class DebugHints
7783
* @param StoreManagerInterface $storeManager
7884
* @param DevHelper $devHelper
7985
* @param DebugHintsFactory $debugHintsFactory
80-
* @param string $debugHintsPath
8186
* @param Http $http
87+
* @param string $debugHintsPath
8288
* @param string $debugHintsWithParam
8389
* @param string $debugHintsParameter
8490
*/
@@ -87,19 +93,17 @@ public function __construct(
8793
StoreManagerInterface $storeManager,
8894
DevHelper $devHelper,
8995
DebugHintsFactory $debugHintsFactory,
96+
Http $http,
9097
$debugHintsPath,
91-
Http $http = null,
9298
$debugHintsWithParam = null,
9399
$debugHintsParameter = null
94100
) {
95101
$this->scopeConfig = $scopeConfig;
96102
$this->storeManager = $storeManager;
97103
$this->devHelper = $devHelper;
98104
$this->debugHintsFactory = $debugHintsFactory;
105+
$this->http = $http;
99106
$this->debugHintsPath = $debugHintsPath;
100-
$this->http = $http ?: \Magento\Framework\App\ObjectManager::getInstance()->get(
101-
\Magento\Framework\App\Request\Http::class
102-
);
103107
$this->debugHintsWithParam = $debugHintsWithParam;
104108
$this->debugHintsParameter = $debugHintsParameter;
105109
}
@@ -152,6 +156,7 @@ public function afterCreate(
152156
]);
153157
}
154158
}
159+
155160
return $invocationResult;
156161
}
157162
}

app/code/Magento/Developer/Model/View/Asset/PreProcessor/PreprocessorStrategy.php

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,32 +42,34 @@ class PreprocessorStrategy implements PreProcessorInterface
4242
private $state;
4343

4444
/**
45-
* Constructor
46-
*
4745
* @param AlternativeSourceInterface $alternativeSource
4846
* @param FrontendCompilation $frontendCompilation
4947
* @param ScopeConfigInterface $scopeConfig
48+
* @param State|null $state
5049
*/
5150
public function __construct(
5251
AlternativeSourceInterface $alternativeSource,
5352
FrontendCompilation $frontendCompilation,
54-
ScopeConfigInterface $scopeConfig
53+
ScopeConfigInterface $scopeConfig,
54+
?State $state = null
5555
) {
5656
$this->frontendCompilation = $frontendCompilation;
5757
$this->alternativeSource = $alternativeSource;
5858
$this->scopeConfig = $scopeConfig;
59+
$this->state = $state ?? ObjectManager::getInstance()->get(State::class);
5960
}
6061

6162
/**
6263
* Transform content and/or content type for the specified pre-processing chain object
6364
*
6465
* @param PreProcessor\Chain $chain
66+
*
6567
* @return void
6668
*/
6769
public function process(PreProcessor\Chain $chain)
6870
{
6971
$isClientSideCompilation =
70-
$this->getState()->getMode() !== State::MODE_PRODUCTION
72+
$this->state->getMode() !== State::MODE_PRODUCTION
7173
&& WorkflowType::CLIENT_SIDE_COMPILATION === $this->scopeConfig->getValue(WorkflowType::CONFIG_NAME_PATH);
7274

7375
if ($isClientSideCompilation) {
@@ -76,16 +78,4 @@ public function process(PreProcessor\Chain $chain)
7678
$this->alternativeSource->process($chain);
7779
}
7880
}
79-
80-
/**
81-
* @return State
82-
* @deprecated 100.2.0
83-
*/
84-
private function getState()
85-
{
86-
if (null === $this->state) {
87-
$this->state = ObjectManager::getInstance()->get(State::class);
88-
}
89-
return $this->state;
90-
}
9181
}

app/code/Magento/Developer/Model/XmlCatalog/Format/PhpStorm.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\Developer\Model\XmlCatalog\Format;
89

9-
use Magento\Framework\App\ObjectManager;
1010
use Magento\Framework\DomDocument\DomDocumentFactory;
1111
use Magento\Framework\Exception\FileSystemException;
1212
use Magento\Framework\Filesystem\Directory\ReadFactory;
1313
use Magento\Framework\Filesystem\Directory\ReadInterface;
14+
use Magento\Framework\Filesystem\DriverPool;
1415
use Magento\Framework\Filesystem\File\WriteFactory;
1516

1617
/**
@@ -43,18 +44,19 @@ class PhpStorm implements FormatInterface
4344
public function __construct(
4445
ReadFactory $readFactory,
4546
WriteFactory $fileWriteFactory,
46-
DomDocumentFactory $domDocumentFactory = null
47+
DomDocumentFactory $domDocumentFactory
4748
) {
4849
$this->currentDirRead = $readFactory->create(getcwd());
4950
$this->fileWriteFactory = $fileWriteFactory;
50-
$this->domDocumentFactory = $domDocumentFactory ?: ObjectManager::getInstance()->get(DomDocumentFactory::class);
51+
$this->domDocumentFactory = $domDocumentFactory;
5152
}
5253

5354
/**
5455
* Generate Catalog of URNs for the PhpStorm 9
5556
*
5657
* @param string[] $dictionary
5758
* @param string $configFilePath relative path to the PhpStorm misc.xml
59+
*
5860
* @return void
5961
*/
6062
public function generateCatalog(array $dictionary, $configFilePath)
@@ -65,7 +67,7 @@ public function generateCatalog(array $dictionary, $configFilePath)
6567
try {
6668
$file = $this->fileWriteFactory->create(
6769
$configFilePath,
68-
\Magento\Framework\Filesystem\DriverPool::FILE,
70+
DriverPool::FILE,
6971
'r'
7072
);
7173
$dom = $this->domDocumentFactory->create();
@@ -103,7 +105,7 @@ public function generateCatalog(array $dictionary, $configFilePath)
103105
$dom->formatOutput = true;
104106
$file = $this->fileWriteFactory->create(
105107
$configFilePath,
106-
\Magento\Framework\Filesystem\DriverPool::FILE,
108+
DriverPool::FILE,
107109
'w'
108110
);
109111
$file->write($dom->saveXML());

0 commit comments

Comments
 (0)