Skip to content

Commit e88b344

Browse files
authored
Merge pull request #152 from magento-commerce/imported-loginesta-magento-coding-standard-368
[Imported] AC-2224: Remove incorrect and outdated rules
2 parents 03d5751 + 7bc37f1 commit e88b344

27 files changed

+1
-2630
lines changed

Magento2/Sniffs/Legacy/PhtmlTemplateSniff.php

-70
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

-104
This file was deleted.

0 commit comments

Comments
 (0)