@@ -18,7 +18,7 @@ class ModuleXMLSniff implements Sniff
1818{
1919 private const WARNING_CODE = 'FoundObsoleteAttribute ' ;
2020 private const ERROR_CODE = 'WrongXML ' ;
21-
21+
2222 /**
2323 * @inheritdoc
2424 */
@@ -34,8 +34,7 @@ public function register(): array
3434 */
3535 public function process (File $ phpcsFile , $ stackPtr )
3636 {
37- $ line = $ phpcsFile ->getTokens ()[$ stackPtr ]['content ' ];
38- if (strpos (trim ($ line ), '<module ' ) === false ) {
37+ if ($ stackPtr > 0 ) {
3938 return ;
4039 }
4140
@@ -54,51 +53,30 @@ public function process(File $phpcsFile, $stackPtr)
5453 );
5554 }
5655
57- $ foundElements = $ xml ->xpath ('/config/module ' );
58- if ($ foundElements === false ) {
59- return ;
60- }
61-
62- foreach ($ foundElements as $ element ) {
63- if (!$ this ->elementIsCurrentlySniffedLine ($ element , $ stackPtr )) {
64- continue ;
65- }
66-
67- if (property_exists ($ element ->attributes (), 'version ' )) {
56+ $ foundElements = $ xml ->xpath ('/config/module[@version] ' );
57+ if ($ foundElements !== false ) {
58+ foreach ($ foundElements as $ element ) {
6859 $ phpcsFile ->addWarning (
6960 'The "version" attribute is obsolete. Use "setup_version" instead. ' ,
70- $ stackPtr ,
61+ dom_import_simplexml ( $ element )-> getLineNo ()- 1 ,
7162 self ::WARNING_CODE
7263 );
7364 }
65+ }
7466
75- if (property_exists ($ element ->attributes (), 'active ' )) {
67+ $ foundElements = $ xml ->xpath ('/config/module[@active] ' );
68+ if ($ foundElements !== false ) {
69+ foreach ($ foundElements as $ element ) {
7670 $ phpcsFile ->addWarning (
7771 'The "active" attribute is obsolete. The list of active modules ' .
7872 'is defined in deployment configuration. ' ,
79- $ stackPtr ,
73+ dom_import_simplexml ( $ element )-> getLineNo ()- 1 ,
8074 self ::WARNING_CODE
8175 );
8276 }
8377 }
8478 }
8579
86- /**
87- * Check if the element passed is in the currently sniffed line
88- *
89- * @param SimpleXMLElement $element
90- * @param int $stackPtr
91- * @return bool
92- */
93- private function elementIsCurrentlySniffedLine (SimpleXMLElement $ element , int $ stackPtr ): bool
94- {
95- $ node = dom_import_simplexml ($ element );
96- if ($ node ->getLineNo () === $ stackPtr +1 ) {
97- return true ;
98- }
99- return false ;
100- }
101-
10280 /**
10381 * Format the incoming XML to avoid tags split into several lines.
10482 *
0 commit comments