Skip to content

Commit a25e2ca

Browse files
committed
AC-661: Create phpcs static check for XmlTest
1 parent 76359c2 commit a25e2ca

File tree

1 file changed

+11
-21
lines changed

1 file changed

+11
-21
lines changed

Magento2/Sniffs/Legacy/WidgetXMLSniff.php

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use PHP_CodeSniffer\Sniffs\Sniff;
1212

1313
/**
14-
* Test for obsolete nodes/attributes in the module.xml
14+
* Test for obsolete nodes/attributes in the widget.xml
1515
*/
1616
class WidgetXMLSniff implements Sniff
1717
{
@@ -39,29 +39,19 @@ public function process(File $phpcsFile, $stackPtr)
3939
}
4040

4141
$xml = simplexml_load_string($this->getFormattedXML($phpcsFile));
42-
if ($xml === false) {
43-
$phpcsFile->addError(
44-
sprintf(
45-
"Couldn't parse contents of '%s', check that they are in valid XML format",
46-
$phpcsFile->getFilename(),
47-
),
48-
1,
49-
self::ERROR_CODE_XML
50-
);
51-
}
5242

5343
$foundElements = $xml->xpath('/widgets/*[@type]');
54-
5544
foreach ($foundElements as $element) {
56-
if (property_exists($element->attributes(), 'type')) {
57-
$type = $element['type'];
58-
if (preg_match('/\//', $type)) {
59-
$phpcsFile->addError(
60-
"Factory name detected: {$type}.",
61-
dom_import_simplexml($element)->getLineNo() - 1,
62-
self::ERROR_CODE_FACTORY
63-
);
64-
}
45+
if (!property_exists($element->attributes(), 'type')) {
46+
continue;
47+
}
48+
$type = $element['type'];
49+
if (preg_match('/\//', $type)) {
50+
$phpcsFile->addError(
51+
"Factory name detected: {$type}.",
52+
dom_import_simplexml($element)->getLineNo() - 1,
53+
self::ERROR_CODE_FACTORY
54+
);
6555
}
6656
}
6757

0 commit comments

Comments
 (0)