Skip to content

Commit 35eba03

Browse files
committedFeb 9, 2022
Merge branch 'develop' of github.com:magento-commerce/magento-coding-standard into development-config-for-tests
2 parents f2b9588 + e88b344 commit 35eba03

27 files changed

+5
-2632
lines changed
 

‎Magento2/Sniffs/Legacy/PhtmlTemplateSniff.php

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,7 @@
1313
class PhtmlTemplateSniff implements Sniff
1414
{
1515
private const WARNING_CODE_TEXT_JAVASCRIPT = 'TextJavascriptTypeFound';
16-
private const WARNING_CODE_THIS_USAGE = 'ThisUsageObsolete';
1716
private const WARNING_CODE_PROTECTED_PRIVATE_BLOCK_ACCESS = 'ProtectedPrivateBlockAccess';
18-
19-
private const OBSOLETE_REGEX = [
20-
'FoundJQueryUI' => [
21-
'pattern' => '/(["\'])jquery\/ui\1/',
22-
'message' => 'Please do not use "jquery/ui" library in templates. Use needed jquery ui widget instead'
23-
],
24-
'FoundDataMageInit' => [
25-
'pattern' => '/data-mage-init=(?:\'|")(?!\s*{\s*"[^"]+")/',
26-
'message' => 'Please do not initialize JS component in php. Do it in template'
27-
],
28-
'FoundXMagentoInit' => [
29-
'pattern' => '@x-magento-init.>(?!\s*+{\s*"[^"]+"\s*:\s*{\s*"[\w/-]+")@i',
30-
'message' => 'Please do not initialize JS component in php. Do it in template'
31-
],
32-
];
3317

3418
/**
3519
* @inheritdoc
@@ -51,18 +35,9 @@ public function process(File $phpcsFile, $stackPtr)
5135
$tokens = $phpcsFile->getTokens();
5236
if ($tokens[$stackPtr]['code'] === T_OBJECT_OPERATOR) {
5337
$this->checkBlockVariable($phpcsFile, $stackPtr, $tokens);
54-
$this->checkThisVariable($phpcsFile, $stackPtr, $tokens);
5538
}
5639
if ($tokens[$stackPtr]['code'] === T_INLINE_HTML || $tokens[$stackPtr]['code'] === T_HEREDOC) {
5740
$this->checkHtml($phpcsFile, $stackPtr);
58-
59-
$file = $phpcsFile->getFilename();
60-
61-
if (strpos($file, '/view/frontend/templates/') !== false
62-
|| strpos($file, '/view/base/templates/') !== false
63-
) {
64-
$this->checkHtmlSpecificFiles($phpcsFile, $stackPtr);
65-
}
6641
}
6742
}
6843

@@ -90,30 +65,6 @@ private function checkBlockVariable(File $phpcsFile, int $stackPtr, array $token
9065
}
9166
}
9267

93-
/**
94-
* Check access to members and methods of Block class through $this
95-
*
96-
* @param File $phpcsFile
97-
* @param int $stackPtr
98-
* @param array $tokens
99-
*/
100-
private function checkThisVariable(File $phpcsFile, int $stackPtr, array $tokens): void
101-
{
102-
$varPos = $phpcsFile->findPrevious(T_VARIABLE, $stackPtr - 1);
103-
if ($tokens[$varPos]['content'] !== '$this') {
104-
return;
105-
}
106-
$stringPos = $phpcsFile->findNext(T_STRING, $stackPtr + 1);
107-
if (strpos($tokens[$stringPos]['content'], 'helper') === false) {
108-
$phpcsFile->addWarning(
109-
'Access to members and methods of Block class through $this is ' .
110-
'obsolete in phtml templates. Use only $block instead of $this.',
111-
$stringPos,
112-
self::WARNING_CODE_THIS_USAGE
113-
);
114-
}
115-
}
116-
11768
/**
11869
* Check use of "text/javascript" type
11970
*
@@ -132,25 +83,4 @@ private function checkHtml(File $phpcsFile, int $stackPtr): void
13283
);
13384
}
13485
}
135-
136-
/**
137-
* Check of some obsoletes uses in specific files
138-
*
139-
* @param File $phpcsFile
140-
* @param int $stackPtr
141-
*/
142-
private function checkHtmlSpecificFiles(File $phpcsFile, int $stackPtr): void
143-
{
144-
$content = $phpcsFile->getTokensAsString($stackPtr, 1);
145-
146-
foreach (self::OBSOLETE_REGEX as $code => $data) {
147-
if (preg_match($data['pattern'], $content)) {
148-
$phpcsFile->addWarning(
149-
$data['message'],
150-
$stackPtr,
151-
$code
152-
);
153-
}
154-
}
155-
}
15686
}

‎Magento2/Sniffs/PHPCompatibility/AbstractPrivateMethodsSniff.php

Lines changed: 0 additions & 104 deletions
This file was deleted.

‎Magento2/Sniffs/PHPCompatibility/NewAttributesSniff.php

Lines changed: 0 additions & 234 deletions
This file was deleted.

‎Magento2/Sniffs/PHPCompatibility/NewInterpolatedStringDereferencingSniff.php

Lines changed: 0 additions & 93 deletions
This file was deleted.

‎Magento2/Sniffs/PHPCompatibility/NewMagicClassConstantSniff.php

Lines changed: 0 additions & 124 deletions
This file was deleted.

‎Magento2/Sniffs/PHPCompatibility/NewMagicConstantDereferencingSniff.php

Lines changed: 0 additions & 126 deletions
This file was deleted.

‎Magento2/Sniffs/PHPCompatibility/NewNestedStaticAccessSniff.php

Lines changed: 0 additions & 153 deletions
This file was deleted.

‎Magento2/Sniffs/PHPCompatibility/NewNonCapturingCatchSniff.php

Lines changed: 0 additions & 84 deletions
This file was deleted.

‎Magento2/Sniffs/PHPCompatibility/NewTrailingCommaSniff.php

Lines changed: 0 additions & 128 deletions
This file was deleted.

‎Magento2/Tests/Legacy/PhtmlTemplateUnitTest.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,16 @@ public function getWarningList($testFile = '')
5656
{
5757
if ($testFile === 'PhtmlTemplateUnitTest.1.phtml' || $testFile === 'PhtmlTemplateUnitTest.2.phtml') {
5858
return [
59-
7 => 1,
6059
9 => 1,
61-
13 => 1,
6260
20 => 1,
63-
22 => 1,
6461
23 => 1,
65-
27 => 1,
66-
33 => 1,
67-
39 => 1
62+
27 => 1
6863
];
6964
}
7065
if ($testFile === 'PhtmlTemplateUnitTest.3.phtml') {
7166
return [
7267
9 => 1,
7368
20 => 1,
74-
22 => 1,
7569
23 => 1,
7670
27 => 1,
7771
];

‎Magento2/Tests/PHPCompatibility/AbstractPrivateMethodsUnitTest.inc

Lines changed: 0 additions & 44 deletions
This file was deleted.

‎Magento2/Tests/PHPCompatibility/AbstractPrivateMethodsUnitTest.php

Lines changed: 0 additions & 139 deletions
This file was deleted.

‎Magento2/Tests/PHPCompatibility/NewAttributesUnitTest.inc

Lines changed: 0 additions & 112 deletions
This file was deleted.

‎Magento2/Tests/PHPCompatibility/NewAttributesUnitTest.php

Lines changed: 0 additions & 154 deletions
This file was deleted.

‎Magento2/Tests/PHPCompatibility/NewInterpolatedStringDereferencingUnitTest.inc

Lines changed: 0 additions & 30 deletions
This file was deleted.

‎Magento2/Tests/PHPCompatibility/NewInterpolatedStringDereferencingUnitTest.php

Lines changed: 0 additions & 112 deletions
This file was deleted.

‎Magento2/Tests/PHPCompatibility/NewMagicClassConstantUnitTest.inc

Lines changed: 0 additions & 52 deletions
This file was deleted.

‎Magento2/Tests/PHPCompatibility/NewMagicClassConstantUnitTest.php

Lines changed: 0 additions & 146 deletions
This file was deleted.

‎Magento2/Tests/PHPCompatibility/NewMagicConstantDereferencingUnitTest.inc

Lines changed: 0 additions & 40 deletions
This file was deleted.

‎Magento2/Tests/PHPCompatibility/NewMagicConstantDereferencingUnitTest.php

Lines changed: 0 additions & 110 deletions
This file was deleted.

‎Magento2/Tests/PHPCompatibility/NewNestedStaticAccessUnitTest.inc

Lines changed: 0 additions & 38 deletions
This file was deleted.

‎Magento2/Tests/PHPCompatibility/NewNestedStaticAccessUnitTest.php

Lines changed: 0 additions & 144 deletions
This file was deleted.

‎Magento2/Tests/PHPCompatibility/NewNonCapturingCatchUnitTest.inc

Lines changed: 0 additions & 34 deletions
This file was deleted.

‎Magento2/Tests/PHPCompatibility/NewNonCapturingCatchUnitTest.php

Lines changed: 0 additions & 101 deletions
This file was deleted.

‎Magento2/Tests/PHPCompatibility/NewTrailingCommaUnitTest.inc

Lines changed: 0 additions & 101 deletions
This file was deleted.

‎Magento2/Tests/PHPCompatibility/NewTrailingCommaUnitTest.php

Lines changed: 0 additions & 138 deletions
This file was deleted.

‎Magento2/ruleset.xml

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66
<arg name="extensions" value="php,phtml,graphqls/GraphQL,less/CSS,html/PHP,xml,js/PHP"/>
77

88
<!-- Severity 10 errors: Critical code issues. -->
9-
<rule ref="Generic.Functions.CallTimePassByReference">
10-
<severity>10</severity>
11-
<type>error</type>
12-
</rule>
139
<rule ref="Generic.PHP.CharacterBeforePHPOpeningTag">
1410
<severity>10</severity>
1511
<type>error</type>
@@ -761,9 +757,13 @@
761757
<exclude-pattern>*Test.php</exclude-pattern>
762758
<exclude-pattern>*/PHPCSUtils/*</exclude-pattern>
763759
</rule>
760+
764761
<rule ref="Internal.NoCodeFound">
765762
<severity>0</severity>
766763
</rule>
764+
765+
<!-- PHPCompatibility configuration. -->
766+
<config name="testVersion" value="7.4-"/>
767767
<rule ref="PHPCompatibility">
768768
<exclude name="PHPCompatibility.Miscellaneous.RemovedAlternativePHPTags.MaybeASPOpenTagFound" />
769769
<!-- Following sniffs have been updated or renamed in PHPCompatibility 10 -->
@@ -772,26 +772,16 @@
772772
<!-- Following sniffs have an equivalent in PHPCS -->
773773
<exclude name="PHPCompatibility.Syntax.ForbiddenCallTimePassByReference" />
774774
<exclude name="PHPCompatibility.Keywords.ForbiddenNamesAsDeclared" />
775-
<!-- Check for cross-version support for stated PHP version and higher. -->
776-
<config name="testVersion" value="7.4-"/>
777775
</rule>
778776
<!--
779777
All these rules belong to the unreleased PhpCompatibility 10. Remove them once PHPCompatibility is
780778
updated to version 10
781779
-->
782-
<rule ref="Magento2.PHPCompatibility.NewAttributes" />
783-
<rule ref="Magento2.PHPCompatibility.NewMagicClassConstant" />
784-
<rule ref="Magento2.PHPCompatibility.NewNonCapturingCatch" />
785-
<rule ref="Magento2.PHPCompatibility.AbstractPrivateMethods" />
786780
<rule ref="Magento2.PHPCompatibility.ForbiddenFinalPrivateMethods" />
787-
<rule ref="Magento2.PHPCompatibility.NewTrailingComma" />
788781
<rule ref="Magento2.PHPCompatibility.RemovedCallingDestructAfterConstructorExit" />
789782
<rule ref="Magento2.PHPCompatibility.RemovedOptionalBeforeRequiredParam" />
790783
<rule ref="Magento2.PHPCompatibility.ChangedIntToBoolParamType" />
791784
<rule ref="Magento2.PHPCompatibility.RemovedAssertStringAssertion" />
792785
<rule ref="Magento2.PHPCompatibility.RemovedGetDefinedFunctionsExcludeDisabledFalse" />
793786
<rule ref="Magento2.PHPCompatibility.RemovedSplAutoloadRegisterThrowFalse" />
794-
<rule ref="Magento2.PHPCompatibility.NewInterpolatedStringDereferencing" />
795-
<rule ref="Magento2.PHPCompatibility.NewMagicConstantDereferencing" />
796-
<rule ref="Magento2.PHPCompatibility.NewNestedStaticAccess" />
797787
</ruleset>

0 commit comments

Comments
 (0)
Please sign in to comment.