Skip to content

Commit df14044

Browse files
committed
AC-661: Create phpcs static check for XmlTest
1 parent 64512dd commit df14044

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

Magento2/Sniffs/Legacy/WidgetXMLSniff.php

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,11 @@ public function process(File $phpcsFile, $stackPtr)
4141
try {
4242
$xml = simplexml_load_string($this->getFormattedXML($phpcsFile));
4343
} catch (\Exception $e) {
44-
$phpcsFile->addError(
45-
sprintf(
46-
"Couldn't parse contents of '%s', check that they are in valid XML format",
47-
$phpcsFile->getFilename(),
48-
),
49-
$stackPtr,
50-
self::ERROR_CODE_XML
51-
);
44+
$this->invalidXML($phpcsFile, $stackPtr);
45+
return;
46+
}
47+
if ($xml === false) {
48+
$this->invalidXML($phpcsFile, $stackPtr);
5249
return;
5350
}
5451

@@ -87,6 +84,22 @@ public function process(File $phpcsFile, $stackPtr)
8784
}
8885
}
8986

87+
/**
88+
* @param File $phpcsFile
89+
* @param int $stackPtr
90+
*/
91+
protected function invalidXML(File $phpcsFile, int $stackPtr): void
92+
{
93+
$phpcsFile->addError(
94+
sprintf(
95+
"Couldn't parse contents of '%s', check that they are in valid XML format",
96+
$phpcsFile->getFilename(),
97+
),
98+
$stackPtr,
99+
self::ERROR_CODE_XML
100+
);
101+
}
102+
90103
/**
91104
* Check if the element passed is in the currently sniffed line
92105
*

0 commit comments

Comments
 (0)