Skip to content

Commit cabf082

Browse files
committed
AC-674: Create phpcs static check for ObsoleteAclTest
- Refactor: Get rid of elementIsCurrentlySniffedLine
1 parent 64a6d6d commit cabf082

File tree

3 files changed

+12
-24
lines changed

3 files changed

+12
-24
lines changed

Magento2/Sniffs/Legacy/ObsoleteAclSniff.php

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use DOMDocument;
99
use PHP_CodeSniffer\Files\File;
1010
use 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
*

Magento2/Tests/Legacy/ObsoleteAclUnitTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff 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
}

Magento2/Tests/Legacy/ObsoleteAclUnitTest.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,9 @@
2020
<title>
2121
<children default_policy="deny"/>
2222
</title>
23+
<children>
24+
<title
25+
value="foo"/>
26+
</children>
2327
</acl>
2428
</config>

0 commit comments

Comments
 (0)