Skip to content

Commit 20b1378

Browse files
authored
Merge pull request #32 from magento-commerce/imported-magento-magento-coding-standard-233
[Imported] Create phpcs static check for DiConfigTest
2 parents 05c75c0 + 8c60047 commit 20b1378

File tree

4 files changed

+117
-1
lines changed

4 files changed

+117
-1
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
class DiConfigSniff implements Sniff
13+
{
14+
private const WARNING_CODE = 'FoundObsoleteAttribute';
15+
16+
/**
17+
* @var string[] Associative array containing the obsolete nodes and the message to display when they are found.
18+
*/
19+
private $obsoleteDiNodes = [
20+
'<param' => 'The <param> node is obsolete. Instead, use the <argument name="..." xsi:type="...">',
21+
'<instance' => 'The <instance> node is obsolete. Instead, use the <argument name="..." xsi:type="object">',
22+
'<array' => 'The <array> node is obsolete. Instead, use the <argument name="..." xsi:type="array">',
23+
'<item key=' => 'The <item key="..."> node is obsolete. Instead, use the <item name="..." xsi:type="...">',
24+
'<value' => 'The <value> node is obsolete. Instead, provide the actual value as a text literal.'
25+
];
26+
27+
/**
28+
* @inheritDoc
29+
*/
30+
public function register(): array
31+
{
32+
return [
33+
T_INLINE_HTML
34+
];
35+
}
36+
37+
/**
38+
* @inheritDoc
39+
*/
40+
public function process(File $phpcsFile, $stackPtr)
41+
{
42+
$lineContent = $phpcsFile->getTokensAsString($stackPtr, 1);
43+
44+
foreach ($this->obsoleteDiNodes as $element => $message) {
45+
if (strpos($lineContent, $element) !== false) {
46+
$phpcsFile->addWarning(
47+
$message,
48+
$stackPtr,
49+
self::WARNING_CODE
50+
);
51+
}
52+
}
53+
}
54+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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 DiConfigUnitTest extends AbstractSniffUnitTest
11+
{
12+
/**
13+
* @inheritdoc
14+
*/
15+
public function getErrorList(): array
16+
{
17+
return [];
18+
}
19+
20+
/**
21+
* @inheritdoc
22+
*/
23+
public function getWarningList(): array
24+
{
25+
return [
26+
12 => 1,
27+
16 => 1,
28+
17 => 1,
29+
18 => 1,
30+
19 => 1
31+
];
32+
}
33+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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:ObjectManager/etc/config.xsd">
9+
<type>
10+
<arguments>
11+
<argument name="prices" xsi:type="array">
12+
<item key="regular_price" xsi:type="string">Magento\Catalog\Pricing\Price\RegularPrice</item>
13+
</argument>
14+
</arguments>
15+
</type>
16+
<instance>
17+
<array key="params">
18+
<param name="default_value" new_attribute="0">
19+
<value new_attribute="5">scalar5</value>
20+
</param>
21+
</array>
22+
</instance>
23+
</config>

Magento2/ruleset.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<description>Magento Coding Standard</description>
44

55
<!-- File extensions to be checked. -->
6-
<arg name="extensions" value="php,phtml,graphqls/GraphQL,less/CSS,html/PHP"/>
6+
<arg name="extensions" value="php,phtml,graphqls/GraphQL,less/CSS,html/PHP,xml"/>
77

88
<!-- Severity 10 errors: Critical code issues. -->
99
<rule ref="Generic.Functions.CallTimePassByReference">
@@ -223,6 +223,11 @@
223223
<severity>8</severity>
224224
<type>warning</type>
225225
</rule>
226+
<rule ref="Magento2.Legacy.DiConfig">
227+
<include-pattern>*\/di.xml$</include-pattern>
228+
<severity>8</severity>
229+
<type>warning</type>
230+
</rule>
226231

227232
<!-- Severity 7 warnings: General code issues. -->
228233
<rule ref="Generic.Arrays.DisallowLongArraySyntax">
@@ -258,6 +263,7 @@
258263
<type>warning</type>
259264
</rule>
260265
<rule ref="Generic.PHP.DisallowShortOpenTag">
266+
<exclude-pattern>*\.xml$</exclude-pattern>
261267
<severity>7</severity>
262268
<type>warning</type>
263269
</rule>

0 commit comments

Comments
 (0)