Skip to content

Commit a781bf6

Browse files
committed
Add backwards compatibility to XmlCatalog PhpStorm changes
1 parent 0d65213 commit a781bf6

File tree

4 files changed

+31
-15
lines changed

4 files changed

+31
-15
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
namespace Magento\Developer\Model\XmlCatalog\Format;
88

99
use Magento\Developer\Model\XmlCatalog\Format\PhpStorm\DomDocumentFactory;
10+
use Magento\Framework\App\ObjectManager;
1011
use Magento\Framework\Exception\FileSystemException;
1112
use Magento\Framework\Filesystem\Directory\ReadFactory;
1213
use Magento\Framework\Filesystem\Directory\ReadInterface;
13-
use Magento\Framework\Filesystem\File\WriteFactory as FileWriteFactory;
14+
use Magento\Framework\Filesystem\File\WriteFactory;
1415

1516
/**
1617
* Class PhpStorm generates URN catalog for PhpStorm 9
@@ -23,7 +24,7 @@ class PhpStorm implements FormatInterface
2324
private $currentDirRead;
2425

2526
/**
26-
* @var FileWriteFactory
27+
* @var WriteFactory
2728
*/
2829
private $fileWriteFactory;
2930

@@ -34,17 +35,17 @@ class PhpStorm implements FormatInterface
3435

3536
/**
3637
* @param ReadFactory $readFactory
37-
* @param FileWriteFactory $fileWriteFactory
38+
* @param WriteFactory $fileWriteFactory
3839
* @param DomDocumentFactory $domDocumentFactory
3940
*/
4041
public function __construct(
4142
ReadFactory $readFactory,
42-
FileWriteFactory $fileWriteFactory,
43-
DomDocumentFactory $domDocumentFactory
43+
WriteFactory $fileWriteFactory,
44+
DomDocumentFactory $domDocumentFactory = null
4445
) {
4546
$this->currentDirRead = $readFactory->create(getcwd());
4647
$this->fileWriteFactory = $fileWriteFactory;
47-
$this->domDocumentFactory = $domDocumentFactory;
48+
$this->domDocumentFactory = $domDocumentFactory ?: ObjectManager::getInstance()->get(DomDocumentFactory::class);
4849
}
4950

5051
/**

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,28 @@
77

88
use DOMDocument;
99

10-
class DomDocumentFactory extends \Magento\Framework\DomDocument\DomDocumentFactory
10+
class DomDocumentFactory
1111
{
12+
/**
13+
* @var \Magento\Framework\DomDocument\DomDocumentFactory
14+
*/
15+
private $documentFactory;
16+
17+
/**
18+
* DomDocumentFactory constructor.
19+
* @param \Magento\Framework\DomDocument\DomDocumentFactory $documentFactory
20+
*/
21+
public function __construct(\Magento\Framework\DomDocument\DomDocumentFactory $documentFactory)
22+
{
23+
$this->documentFactory = $documentFactory;
24+
}
25+
1226
/**
1327
* {@inheritdoc}
1428
*/
15-
public function create($data = null)
29+
public function create(string $data = null)
1630
{
17-
$dom = parent::create($data);
31+
$dom = $this->documentFactory->create($data);
1832

1933
if (empty($data)) {
2034
$this->initializeDocument($dom);

lib/internal/Magento/Framework/DomDocument/DomDocumentFactory.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@ public function __construct(\Magento\Framework\ObjectManagerInterface $objectMan
3434
*
3535
* @return DOMDocument
3636
*/
37-
public function create($data = null)
37+
public function create(string $data = null)
3838
{
39+
/** @var DOMDocument $dom */
3940
$dom = $this->objectManager->create(DOMDocument::class);
4041

41-
if (!empty($data) && is_string($data)) {
42+
if (!empty($data)) {
4243
$dom->loadXML($data);
4344
}
4445

lib/internal/Magento/Framework/Test/Unit/DomDocument/DomDocumentFactoryTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,14 @@ public function testCreate($data = null)
6868
->with(DOMDocument::class)
6969
->willReturn($this->domDocumentMock);
7070

71-
if (empty($data) || !is_string($data)) {
72-
$this->domDocumentMock->expects($this->never())
73-
->method('loadXML');
74-
} else {
71+
if (!empty($data)) {
7572
$this->domDocumentMock->expects($this->once())
7673
->method('loadXML')
7774
->with($data)
7875
->willReturn(true);
76+
} else {
77+
$this->domDocumentMock->expects($this->never())
78+
->method('loadXML');
7979
}
8080

8181
$this->domDocumentFactory->create($data);

0 commit comments

Comments
 (0)