Skip to content

Commit ffd3fb4

Browse files
committed
Remove duplicate code
1 parent 4050675 commit ffd3fb4

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
@@ -14,24 +14,6 @@ trait ParseXMLTrait
1414
{
1515
private const ERROR_CODE_XML = 'WrongXML';
1616

17-
/**
18-
* Adds an invalid XML error
19-
*
20-
* @param File $phpcsFile
21-
* @param int $stackPtr
22-
*/
23-
private function invalidXML(File $phpcsFile, int $stackPtr): void
24-
{
25-
$phpcsFile->addError(
26-
"Couldn't parse contents of '%s', check that they are in valid XML format.",
27-
$stackPtr,
28-
self::ERROR_CODE_XML,
29-
[
30-
$phpcsFile->getFilename(),
31-
]
32-
);
33-
}
34-
3517
/**
3618
* Format the incoming XML to avoid tags split into several lines.
3719
*
@@ -47,6 +29,14 @@ private function getFormattedXML(File $phpcsFile)
4729
$doc->loadXML($phpcsFile->getTokensAsString(0, count($phpcsFile->getTokens())));
4830
return $doc->saveXML();
4931
} catch (\Exception $e) {
32+
$phpcsFile->addError(
33+
"Couldn't parse contents of '%s', check that they are in valid XML format.",
34+
0,
35+
self::ERROR_CODE_XML,
36+
[
37+
$phpcsFile->getFilename(),
38+
]
39+
);
5040
return false;
5141
}
5242
}

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)