|
11 | 11 | use PHP_CodeSniffer\Sniffs\Sniff; |
12 | 12 |
|
13 | 13 | /** |
14 | | - * Test for obsolete nodes/attributes in the module.xml |
| 14 | + * Test for obsolete nodes/attributes in the widget.xml |
15 | 15 | */ |
16 | 16 | class WidgetXMLSniff implements Sniff |
17 | 17 | { |
@@ -39,29 +39,19 @@ public function process(File $phpcsFile, $stackPtr) |
39 | 39 | } |
40 | 40 |
|
41 | 41 | $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 | | - } |
52 | 42 |
|
53 | 43 | $foundElements = $xml->xpath('/widgets/*[@type]'); |
54 | | - |
55 | 44 | 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 | + ); |
65 | 55 | } |
66 | 56 | } |
67 | 57 |
|
|
0 commit comments