File tree Expand file tree Collapse file tree 3 files changed +12
-24
lines changed Expand file tree Collapse file tree 3 files changed +12
-24
lines changed Original file line number Diff line number Diff line change 88use DOMDocument ;
99use PHP_CodeSniffer \Files \File ;
1010use PHP_CodeSniffer \Sniffs \Sniff ;
11- use SimpleXMLElement ;
1211
1312/**
1413 * Test to find obsolete acl declaration
@@ -32,37 +31,21 @@ public function register(): array
3231 */
3332 public function process (File $ phpcsFile , $ stackPtr )
3433 {
34+ if ($ stackPtr > 0 ) {
35+ return ;
36+ }
37+
3538 $ xml = simplexml_load_string ($ this ->getFormattedXML ($ phpcsFile ));
3639 $ foundElements = $ xml ->xpath ('/config/acl/*[boolean(./children) or boolean(./title)] ' );
3740 foreach ($ foundElements as $ element ) {
38- if (!$ this ->elementIsCurrentlySniffedLine ($ element , $ stackPtr )) {
39- continue ;
40- }
41-
4241 $ phpcsFile ->addWarning (
43- 'Obsolete acl structure detected in line ' . ( $ stackPtr + 1 ),
44- $ stackPtr ,
42+ 'Obsolete acl structure detected in line ' . dom_import_simplexml ( $ element )-> getLineNo ( ),
43+ dom_import_simplexml ( $ element )-> getLineNo () - 1 ,
4544 self ::WARNING_OBSOLETE_ACL_STRUCTURE
4645 );
4746 }
4847 }
4948
50- /**
51- * Check if the element passed is in the currently sniffed line
52- *
53- * @param SimpleXMLElement $element
54- * @param int $stackPtr
55- * @return bool
56- */
57- private function elementIsCurrentlySniffedLine (SimpleXMLElement $ element , int $ stackPtr ): bool
58- {
59- $ node = dom_import_simplexml ($ element );
60- if ($ node ->getLineNo () === $ stackPtr +1 ) {
61- return true ;
62- }
63- return false ;
64- }
65-
6649 /**
6750 * Format the incoming XML to avoid tags split into several lines.
6851 *
Original file line number Diff line number Diff line change @@ -24,7 +24,8 @@ public function getWarningList(): array
2424 {
2525 return [
2626 15 => 1 ,
27- 20 => 1
27+ 20 => 1 ,
28+ 23 => 1
2829 ];
2930 }
3031}
Original file line number Diff line number Diff line change 2020 <title >
2121 <children default_policy =" deny" />
2222 </title >
23+ <children >
24+ <title
25+ value =" foo" />
26+ </children >
2327 </acl >
2428</config >
You can’t perform that action at this time.
0 commit comments