3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+ declare (strict_types = 1 );
6
7
7
8
namespace Magento \Developer \Model \XmlCatalog \Format ;
8
9
9
- use Magento \Framework \App \ObjectManager ;
10
10
use Magento \Framework \DomDocument \DomDocumentFactory ;
11
11
use Magento \Framework \Exception \FileSystemException ;
12
12
use Magento \Framework \Filesystem \Directory \ReadFactory ;
13
13
use Magento \Framework \Filesystem \Directory \ReadInterface ;
14
+ use Magento \Framework \Filesystem \DriverPool ;
14
15
use Magento \Framework \Filesystem \File \WriteFactory ;
15
16
16
17
/**
19
20
class VsCode implements FormatInterface
20
21
{
21
22
private const PROJECT_PATH_IDENTIFIER = '.. ' ;
23
+ private const FILE_MODE_READ = 'r ' ;
24
+ private const FILE_MODE_WRITE = 'w ' ;
22
25
23
26
/**
24
27
* @var ReadInterface
@@ -47,26 +50,22 @@ public function __construct(
47
50
) {
48
51
$ this ->currentDirRead = $ readFactory ->create (getcwd ());
49
52
$ this ->fileWriteFactory = $ fileWriteFactory ;
50
- $ this ->domDocumentFactory = $ domDocumentFactory ?: ObjectManager:: getInstance ()-> get (DomDocumentFactory::class) ;
53
+ $ this ->domDocumentFactory = $ domDocumentFactory ;
51
54
}
52
55
53
56
/**
54
57
* Generate Catalog of URNs for the VsCode
55
58
*
56
59
* @param string[] $dictionary
57
- * @param string $configFilePath relative path to the PhpStorm misc .xml
60
+ * @param string $configFile relative path to the VsCode catalog .xml
58
61
* @return void
59
62
*/
60
- public function generateCatalog (array $ dictionary , $ configFilePath )
63
+ public function generateCatalog (array $ dictionary , $ configFile ): void
61
64
{
62
65
$ catalogNode = null ;
63
66
64
67
try {
65
- $ file = $ this ->fileWriteFactory ->create (
66
- $ configFilePath ,
67
- \Magento \Framework \Filesystem \DriverPool::FILE ,
68
- 'r '
69
- );
68
+ $ file = $ this ->fileWriteFactory ->create ($ configFile , DriverPool::FILE , self ::FILE_MODE_READ );
70
69
$ dom = $ this ->domDocumentFactory ->create ();
71
70
$ fileContent = $ file ->readAll ();
72
71
if (!empty ($ fileContent )) {
@@ -91,11 +90,7 @@ public function generateCatalog(array $dictionary, $configFilePath)
91
90
$ catalogNode ->appendChild ($ node );
92
91
}
93
92
$ dom ->formatOutput = true ;
94
- $ file = $ this ->fileWriteFactory ->create (
95
- $ configFilePath ,
96
- \Magento \Framework \Filesystem \DriverPool::FILE ,
97
- 'w '
98
- );
93
+ $ file = $ this ->fileWriteFactory ->create ($ configFile , DriverPool::FILE , self ::FILE_MODE_WRITE );
99
94
$ file ->write ($ dom ->saveXML ());
100
95
$ file ->close ();
101
96
}
@@ -106,7 +101,7 @@ public function generateCatalog(array $dictionary, $configFilePath)
106
101
* @param \DOMDocument $dom
107
102
* @return \DOMElement
108
103
*/
109
- private function initEmptyFile (\DOMDocument $ dom )
104
+ private function initEmptyFile (\DOMDocument $ dom ): \ DOMElement
110
105
{
111
106
$ catalogNode = $ dom ->createElement ('catalog ' );
112
107
0 commit comments