Skip to content

Commit 2b58f92

Browse files
authoredOct 5, 2021
Merge pull request #92 from magento-commerce/develop
Develop to Master Version 13
2 parents 67926bd + aa0c657 commit 2b58f92

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+6963
-834
lines changed
 

‎.github/workflows/php.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ jobs:
4242
- name: Install dependencies
4343
run: npm install
4444
- name: Run ESLint
45-
run: npm run eslint -- eslint/rules
45+
run: npm run eslint -- eslint/rules Magento2 --ignore-pattern 'Magento2/Tests/Eslint/*Test.js'
46+
- name: Run JSCS
47+
run: npm run jscs eslint/rules Magento2
4648

4749
- name: Validate composer
4850
run: composer validate
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento2\Sniffs\Legacy;
7+
8+
use DOMDocument;
9+
use PHP_CodeSniffer\Files\File;
10+
use PHP_CodeSniffer\Sniffs\Sniff;
11+
12+
/**
13+
* Test to find obsolete acl declaration
14+
*/
15+
class ObsoleteAclSniff implements Sniff
16+
{
17+
private const WARNING_OBSOLETE_ACL_STRUCTURE = 'ObsoleteAclStructure';
18+
19+
/**
20+
* @inheritdoc
21+
*/
22+
public function register(): array
23+
{
24+
return [
25+
T_INLINE_HTML
26+
];
27+
}
28+
29+
/**
30+
* @inheritDoc
31+
*/
32+
public function process(File $phpcsFile, $stackPtr)
33+
{
34+
if ($stackPtr > 0) {
35+
return;
36+
}
37+
38+
$xml = simplexml_load_string($this->getFormattedXML($phpcsFile));
39+
$foundElements = $xml->xpath('/config/acl/*[boolean(./children) or boolean(./title)]');
40+
foreach ($foundElements as $element) {
41+
$phpcsFile->addWarning(
42+
'Obsolete acl structure detected in line ' . dom_import_simplexml($element)->getLineNo(),
43+
dom_import_simplexml($element)->getLineNo() - 1,
44+
self::WARNING_OBSOLETE_ACL_STRUCTURE
45+
);
46+
}
47+
}
48+
49+
/**
50+
* Format the incoming XML to avoid tags split into several lines.
51+
*
52+
* @param File $phpcsFile
53+
* @return false|string
54+
*/
55+
private function getFormattedXML(File $phpcsFile)
56+
{
57+
$doc = new DomDocument('1.0');
58+
$doc->formatOutput = true;
59+
$doc->loadXML($phpcsFile->getTokensAsString(0, 999999));
60+
return $doc->saveXML();
61+
}
62+
}

0 commit comments

Comments
 (0)
Please sign in to comment.