Skip to content

AC-2224: Remove incorrect and outdated rules #368

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 0 additions & 70 deletions Magento2/Sniffs/Legacy/PhtmlTemplateSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,7 @@
class PhtmlTemplateSniff implements Sniff
{
private const WARNING_CODE_TEXT_JAVASCRIPT = 'TextJavascriptTypeFound';
private const WARNING_CODE_THIS_USAGE = 'ThisUsageObsolete';
private const WARNING_CODE_PROTECTED_PRIVATE_BLOCK_ACCESS = 'ProtectedPrivateBlockAccess';

private const OBSOLETE_REGEX = [
'FoundJQueryUI' => [
'pattern' => '/(["\'])jquery\/ui\1/',
'message' => 'Please do not use "jquery/ui" library in templates. Use needed jquery ui widget instead'
],
'FoundDataMageInit' => [
'pattern' => '/data-mage-init=(?:\'|")(?!\s*{\s*"[^"]+")/',
'message' => 'Please do not initialize JS component in php. Do it in template'
],
'FoundXMagentoInit' => [
'pattern' => '@x-magento-init.>(?!\s*+{\s*"[^"]+"\s*:\s*{\s*"[\w/-]+")@i',
'message' => 'Please do not initialize JS component in php. Do it in template'
],
];

/**
* @inheritdoc
Expand All @@ -51,18 +35,9 @@ public function process(File $phpcsFile, $stackPtr)
$tokens = $phpcsFile->getTokens();
if ($tokens[$stackPtr]['code'] === T_OBJECT_OPERATOR) {
$this->checkBlockVariable($phpcsFile, $stackPtr, $tokens);
$this->checkThisVariable($phpcsFile, $stackPtr, $tokens);
}
if ($tokens[$stackPtr]['code'] === T_INLINE_HTML || $tokens[$stackPtr]['code'] === T_HEREDOC) {
$this->checkHtml($phpcsFile, $stackPtr);

$file = $phpcsFile->getFilename();

if (strpos($file, '/view/frontend/templates/') !== false
|| strpos($file, '/view/base/templates/') !== false
) {
$this->checkHtmlSpecificFiles($phpcsFile, $stackPtr);
}
}
}

Expand Down Expand Up @@ -90,30 +65,6 @@ private function checkBlockVariable(File $phpcsFile, int $stackPtr, array $token
}
}

/**
* Check access to members and methods of Block class through $this
*
* @param File $phpcsFile
* @param int $stackPtr
* @param array $tokens
*/
private function checkThisVariable(File $phpcsFile, int $stackPtr, array $tokens): void
{
$varPos = $phpcsFile->findPrevious(T_VARIABLE, $stackPtr - 1);
if ($tokens[$varPos]['content'] !== '$this') {
return;
}
$stringPos = $phpcsFile->findNext(T_STRING, $stackPtr + 1);
if (strpos($tokens[$stringPos]['content'], 'helper') === false) {
$phpcsFile->addWarning(
'Access to members and methods of Block class through $this is ' .
'obsolete in phtml templates. Use only $block instead of $this.',
$stringPos,
self::WARNING_CODE_THIS_USAGE
);
}
}

/**
* Check use of "text/javascript" type
*
Expand All @@ -132,25 +83,4 @@ private function checkHtml(File $phpcsFile, int $stackPtr): void
);
}
}

/**
* Check of some obsoletes uses in specific files
*
* @param File $phpcsFile
* @param int $stackPtr
*/
private function checkHtmlSpecificFiles(File $phpcsFile, int $stackPtr): void
{
$content = $phpcsFile->getTokensAsString($stackPtr, 1);

foreach (self::OBSOLETE_REGEX as $code => $data) {
if (preg_match($data['pattern'], $content)) {
$phpcsFile->addWarning(
$data['message'],
$stackPtr,
$code
);
}
}
}
}
104 changes: 0 additions & 104 deletions Magento2/Sniffs/PHPCompatibility/AbstractPrivateMethodsSniff.php

This file was deleted.

Loading