@@ -18,7 +18,7 @@ class ModuleXMLSniff implements Sniff
18
18
{
19
19
private const WARNING_CODE = 'FoundObsoleteAttribute ' ;
20
20
private const ERROR_CODE = 'WrongXML ' ;
21
-
21
+
22
22
/**
23
23
* @inheritdoc
24
24
*/
@@ -34,8 +34,7 @@ public function register(): array
34
34
*/
35
35
public function process (File $ phpcsFile , $ stackPtr )
36
36
{
37
- $ line = $ phpcsFile ->getTokens ()[$ stackPtr ]['content ' ];
38
- if (strpos (trim ($ line ), '<module ' ) === false ) {
37
+ if ($ stackPtr > 0 ) {
39
38
return ;
40
39
}
41
40
@@ -52,53 +51,33 @@ public function process(File $phpcsFile, $stackPtr)
52
51
$ stackPtr ,
53
52
self ::ERROR_CODE
54
53
);
55
- }
56
-
57
- $ foundElements = $ xml ->xpath ('/config/module ' );
58
- if ($ foundElements === false ) {
59
54
return ;
60
55
}
61
-
62
- foreach ($ foundElements as $ element ) {
63
- if (!$ this ->elementIsCurrentlySniffedLine ($ element , $ stackPtr )) {
64
- continue ;
65
- }
66
-
67
- if (property_exists ($ element ->attributes (), 'version ' )) {
56
+
57
+ $ foundElements = $ xml ->xpath ('/config/module[@version] ' );
58
+ if ($ foundElements !== false ) {
59
+ foreach ($ foundElements as $ element ) {
68
60
$ phpcsFile ->addWarning (
69
61
'The "version" attribute is obsolete. Use "setup_version" instead. ' ,
70
- $ stackPtr ,
62
+ dom_import_simplexml ( $ element )-> getLineNo ()- 1 ,
71
63
self ::WARNING_CODE
72
64
);
73
65
}
66
+ }
74
67
75
- if (property_exists ($ element ->attributes (), 'active ' )) {
68
+ $ foundElements = $ xml ->xpath ('/config/module[@active] ' );
69
+ if ($ foundElements !== false ) {
70
+ foreach ($ foundElements as $ element ) {
76
71
$ phpcsFile ->addWarning (
77
72
'The "active" attribute is obsolete. The list of active modules ' .
78
73
'is defined in deployment configuration. ' ,
79
- $ stackPtr ,
74
+ dom_import_simplexml ( $ element )-> getLineNo ()- 1 ,
80
75
self ::WARNING_CODE
81
76
);
82
77
}
83
78
}
84
79
}
85
80
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
-
102
81
/**
103
82
* Format the incoming XML to avoid tags split into several lines.
104
83
*
0 commit comments