Skip to content

Commit c688fd3

Browse files
committed
Remove duplicate code
1 parent 880d4f7 commit c688fd3

7 files changed

+10
-52
lines changed

Magento2/Sniffs/Legacy/ClassReferencesInConfigurationFilesSniff.php

+1-8
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,7 @@ public function process(File $phpcsFile, $stackPtr)
4747
// instead, as it is the one we compare with $stackPtr later on.
4848
$xml = simplexml_load_string($this->getFormattedXML($phpcsFile));
4949
if ($xml === false) {
50-
$phpcsFile->addError(
51-
"Couldn't parse contents of '%s', check that they are in valid XML format",
52-
$stackPtr,
53-
self::ERROR_CODE_CONFIG,
54-
[
55-
$phpcsFile->getFilename(),
56-
]
57-
);
50+
return;
5851
}
5952

6053
$classes = $this->collectClassesInConfig($xml);

Magento2/Sniffs/Legacy/LayoutSniff.php

-8
Original file line numberDiff line numberDiff line change
@@ -221,14 +221,6 @@ public function process(File $phpcsFile, $stackPtr)
221221
$layout = simplexml_load_string($this->getFormattedXML($phpcsFile));
222222

223223
if ($layout === false) {
224-
$phpcsFile->addError(
225-
"Couldn't parse contents of '%s', check that they are in valid XML format",
226-
$stackPtr,
227-
self::ERROR_CODE_XML,
228-
[
229-
$phpcsFile->getFilename(),
230-
]
231-
);
232224
return;
233225
}
234226

Magento2/Sniffs/Legacy/ModuleXMLSniff.php

-8
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,6 @@ public function process(File $phpcsFile, $stackPtr)
4646
// instead, as it is the one we compare with $stackPtr later on.
4747
$xml = simplexml_load_string($this->getFormattedXML($phpcsFile));
4848
if ($xml === false) {
49-
$phpcsFile->addError(
50-
"Couldn't parse contents of '%s', check that they are in valid XML format",
51-
$stackPtr,
52-
self::ERROR_CODE,
53-
[
54-
$phpcsFile->getFilename(),
55-
]
56-
);
5749
return;
5850
}
5951

Magento2/Sniffs/Legacy/ObsoleteConfigNodesSniff.php

+1-8
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,7 @@ public function process(File $phpcsFile, $stackPtr)
4242
// instead, as it is the one we compare with $stackPtr later on.
4343
$xml = simplexml_load_string($this->getFormattedXML($phpcsFile));
4444
if ($xml === false) {
45-
$phpcsFile->addError(
46-
"Couldn't parse contents of '%s', check that they are in valid XML format",
47-
$stackPtr,
48-
self::ERROR_CODE_CONFIG,
49-
[
50-
$phpcsFile->getFilename(),
51-
]
52-
);
45+
return;
5346
}
5447

5548
foreach ($this->getObsoleteNodes() as $xpath => $suggestion) {

Magento2/Sniffs/Legacy/ObsoleteSystemConfigurationSniff.php

-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ public function process(File $phpcsFile, $stackPtr)
3939
$xml = simplexml_load_string($this->getFormattedXML($phpcsFile));
4040

4141
if ($xml === false) {
42-
$this->invalidXML($phpcsFile, $stackPtr);
4342
return;
4443
}
4544

Magento2/Sniffs/Legacy/ParseXMLTrait.php

+8-18
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,6 @@
1212

1313
trait ParseXMLTrait
1414
{
15-
/**
16-
* Adds an invalid XML error
17-
*
18-
* @param File $phpcsFile
19-
* @param int $stackPtr
20-
*/
21-
private function invalidXML(File $phpcsFile, int $stackPtr): void
22-
{
23-
$phpcsFile->addError(
24-
"Couldn't parse contents of '%s', check that they are in valid XML format.",
25-
$stackPtr,
26-
'WrongXML',
27-
[
28-
$phpcsFile->getFilename(),
29-
]
30-
);
31-
}
32-
3315
/**
3416
* Format the incoming XML to avoid tags split into several lines.
3517
*
@@ -45,6 +27,14 @@ private function getFormattedXML(File $phpcsFile)
4527
$doc->loadXML($phpcsFile->getTokensAsString(0, count($phpcsFile->getTokens())));
4628
return $doc->saveXML();
4729
} catch (\Exception $e) {
30+
$phpcsFile->addError(
31+
"Couldn't parse contents of '%s', check that they are in valid XML format.",
32+
0,
33+
'WrongXML',
34+
[
35+
$phpcsFile->getFilename(),
36+
]
37+
);
4838
return false;
4939
}
5040
}

Magento2/Sniffs/Legacy/WidgetXMLSniff.php

-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ public function process(File $phpcsFile, $stackPtr)
4444
$xml = simplexml_load_string($this->getFormattedXML($phpcsFile));
4545

4646
if ($xml === false) {
47-
$this->invalidXML($phpcsFile, $stackPtr);
4847
return;
4948
}
5049

0 commit comments

Comments
 (0)