File tree Expand file tree Collapse file tree 5 files changed +105
-1
lines changed Expand file tree Collapse file tree 5 files changed +105
-1
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+ /**
3+ * Copyright © Magento, Inc. All rights reserved.
4+ * See COPYING.txt for license details.
5+ */
6+
7+ namespace Magento2 \Sniffs \Legacy ;
8+
9+ use PHP_CodeSniffer \Files \File ;
10+ use PHP_CodeSniffer \Sniffs \Sniff ;
11+
12+ /**
13+ * Test for obsolete nodes/attributes in the module.xml
14+ */
15+ class ModuleXMLSniff implements Sniff
16+ {
17+ /**
18+ * Error violation code.
19+ *
20+ * @var string
21+ */
22+ protected $ warningCode = 'FoundObsoleteAttribute ' ;
23+
24+ /**
25+ * @inheritdoc
26+ */
27+ public function register (): array
28+ {
29+ return [
30+ T_INLINE_HTML
31+ ];
32+ }
33+
34+ /**
35+ * @inheritDoc
36+ */
37+ public function process (File $ phpcsFile , $ stackPtr )
38+ {
39+ $ xml = simplexml_load_string ($ phpcsFile ->getTokensAsString (0 , 999999 ));
40+
41+ if ($ xml ->xpath ('/config/module/@version ' ) !== false ) {
42+ $ phpcsFile ->addWarning (
43+ 'The "version" attribute is obsolete. Use "setup_version" instead. ' ,
44+ $ stackPtr ,
45+ $ this ->warningCode
46+ );
47+ }
48+
49+ if ($ xml ->xpath ('/config/module/@active ' ) !== false ) {
50+ $ phpcsFile ->addWarning (
51+ 'The "active" attribute is obsolete. The list of active modules is defined in deployment configuration. ' ,
52+ $ stackPtr ,
53+ $ this ->warningCode
54+ );
55+ }
56+ }
57+ }
Original file line number Diff line number Diff line change 1+ <?php
2+ /**
3+ * Copyright © Magento. All rights reserved.
4+ * See COPYING.txt for license details.
5+ */
6+ namespace Magento2 \Tests \Legacy ;
7+
8+ use PHP_CodeSniffer \Tests \Standards \AbstractSniffUnitTest ;
9+
10+ class ModuleXMLUnitTest extends AbstractSniffUnitTest
11+ {
12+ /**
13+ * @inheritdoc
14+ */
15+ public function getErrorList ()
16+ {
17+ return [];
18+ }
19+
20+ /**
21+ * @inheritdoc
22+ */
23+ public function getWarningList ()
24+ {
25+ return [
26+ 1 => 2
27+ ];
28+ }
29+ }
Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" ?>
2+ <!--
3+ /**
4+ * Copyright © Magento, Inc. All rights reserved.
5+ * See COPYING.txt for license details.
6+ */
7+ -->
8+ <config xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance" xsi : noNamespaceSchemaLocation =" urn:magento:framework:Module/etc/module.xsd" >
9+ <module name =" Magento_TestModule" active =" true" version =" 1" />
10+ </config >
Original file line number Diff line number Diff line change 223223 <severity >8</severity >
224224 <type >warning</type >
225225 </rule >
226+ <rule ref =" Magento2.Legacy.ModuleXML" >
227+ <exclude-pattern >*\.php$</exclude-pattern >
228+ <include-pattern >module.xml</include-pattern >
229+ <include-pattern >ModuleXMLUnitTest.xml</include-pattern >
230+ <severity >8</severity >
231+ <type >warning</type >
232+ </rule >
226233
227234 <!-- Severity 7 warnings: General code issues. -->
228235 <rule ref =" Generic.Arrays.DisallowLongArraySyntax" >
Original file line number Diff line number Diff line change 1010 "require" : {
1111 "php" : " >=7.3" ,
1212 "squizlabs/php_codesniffer" : " ^3.6" ,
13- "webonyx/graphql-php" : " ^14.9"
13+ "webonyx/graphql-php" : " ^14.9" ,
14+ "ext-simplexml" : " *"
1415 },
1516 "require-dev" : {
1617 "phpunit/phpunit" : " ^9.5.8"
You can’t perform that action at this time.
0 commit comments