Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 24a05ad

Browse filesBrowse files
authored
Merge pull request #169 from magento-commerce/imported-svera-magento-coding-standard-380
2 parents e4108e3 + 2f6052f commit 24a05ad
Copy full SHA for 24a05ad

File tree

Expand file treeCollapse file tree

3 files changed

+28
-33
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+28
-33
lines changed

‎Magento2/Sniffs/Legacy/ModuleXMLSniff.php

Copy file name to clipboardExpand all lines: Magento2/Sniffs/Legacy/ModuleXMLSniff.php
+12-33Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class ModuleXMLSniff implements Sniff
1818
{
1919
private const WARNING_CODE = 'FoundObsoleteAttribute';
2020
private const ERROR_CODE = 'WrongXML';
21-
21+
2222
/**
2323
* @inheritdoc
2424
*/
@@ -34,8 +34,7 @@ public function register(): array
3434
*/
3535
public function process(File $phpcsFile, $stackPtr)
3636
{
37-
$line = $phpcsFile->getTokens()[$stackPtr]['content'];
38-
if (strpos(trim($line), '<module') === false) {
37+
if ($stackPtr > 0) {
3938
return;
4039
}
4140

@@ -52,53 +51,33 @@ public function process(File $phpcsFile, $stackPtr)
5251
$stackPtr,
5352
self::ERROR_CODE
5453
);
55-
}
56-
57-
$foundElements = $xml->xpath('/config/module');
58-
if ($foundElements === false) {
5954
return;
6055
}
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) {
6860
$phpcsFile->addWarning(
6961
'The "version" attribute is obsolete. Use "setup_version" instead.',
70-
$stackPtr,
62+
dom_import_simplexml($element)->getLineNo()-1,
7163
self::WARNING_CODE
7264
);
7365
}
66+
}
7467

75-
if (property_exists($element->attributes(), 'active')) {
68+
$foundElements = $xml->xpath('/config/module[@active]');
69+
if ($foundElements !== false) {
70+
foreach ($foundElements as $element) {
7671
$phpcsFile->addWarning(
7772
'The "active" attribute is obsolete. The list of active modules '.
7873
'is defined in deployment configuration.',
79-
$stackPtr,
74+
dom_import_simplexml($element)->getLineNo()-1,
8075
self::WARNING_CODE
8176
);
8277
}
8378
}
8479
}
8580

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-
10281
/**
10382
* Format the incoming XML to avoid tags split into several lines.
10483
*
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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"
9+
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
10+
<module name="Training_Backend" active="true" version="1" />
11+
</config>

‎Magento2/Tests/Legacy/ModuleXMLUnitTest.php

Copy file name to clipboardExpand all lines: Magento2/Tests/Legacy/ModuleXMLUnitTest.php
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ public function getWarningList($testFile = '')
3535
if ($testFile === 'ModuleXMLUnitTest.3.xml') {
3636
return [];
3737
}
38+
if ($testFile === 'ModuleXMLUnitTest.4.xml') {
39+
return [
40+
9 => 2,
41+
];
42+
}
3843
return [];
3944
}
4045
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.