diff --git a/Magento2/Sniffs/Legacy/AbstractBlockSniff.php b/Magento2/Sniffs/Legacy/AbstractBlockSniff.php
index de9884d2..705db1b0 100644
--- a/Magento2/Sniffs/Legacy/AbstractBlockSniff.php
+++ b/Magento2/Sniffs/Legacy/AbstractBlockSniff.php
@@ -15,12 +15,8 @@ class AbstractBlockSniff implements Sniff
private const CHILD_HTML_METHOD = 'getChildHtml';
private const CHILD_CHILD_HTML_METHOD = 'getChildChildHtml';
- /**
- * Error violation code.
- *
- * @var string
- */
- protected $errorCode = 'FoundCountOfParametersIncorrect';
+ private const ERROR_CODE_THIRD_PARAMETER = 'ThirdParameterNotNeeded';
+ private const ERROR_CODE_FOURTH_PARAMETER = 'FourthParameterNotNeeded';
/**
* @inheritdoc
@@ -52,14 +48,14 @@ public function process(File $phpcsFile, $stackPtr)
$phpcsFile->addError(
'3rd parameter is not needed anymore for getChildHtml()',
$stackPtr,
- $this->errorCode
+ self::ERROR_CODE_THIRD_PARAMETER
);
}
if ($content === self::CHILD_CHILD_HTML_METHOD && $paramsCount >= 4) {
$phpcsFile->addError(
'4th parameter is not needed anymore for getChildChildHtml()',
$stackPtr,
- $this->errorCode
+ self::ERROR_CODE_FOURTH_PARAMETER
);
}
}
diff --git a/Magento2/Sniffs/Legacy/DiConfigSniff.php b/Magento2/Sniffs/Legacy/DiConfigSniff.php
index 954c32e0..7495dd44 100644
--- a/Magento2/Sniffs/Legacy/DiConfigSniff.php
+++ b/Magento2/Sniffs/Legacy/DiConfigSniff.php
@@ -11,17 +11,27 @@
class DiConfigSniff implements Sniff
{
- private const WARNING_CODE = 'FoundObsoleteAttribute';
-
- /**
- * @var string[] Associative array containing the obsolete nodes and the message to display when they are found.
- */
- private $obsoleteDiNodes = [
- ' 'The node is obsolete. Instead, use the ',
- ' 'The node is obsolete. Instead, use the ',
- ' 'The node is obsolete. Instead, use the ',
- '- node is obsolete. Instead, use the
- ',
- ' 'The node is obsolete. Instead, provide the actual value as a text literal.'
+ private const OBSOLETE_NODES = [
+ 'FoundObsoleteParamNode' => [
+ 'pattern' => ' 'The node is obsolete. Instead, use the '
+ ],
+ 'FoundObsoleteInstanceNode' => [
+ 'pattern' => ' 'The node is obsolete. Instead, use the >'
+ ],
+ 'FoundObsoleteArrayNode' => [
+ 'pattern' => ' 'The node is obsolete. Instead, use the '
+ ],
+ 'FoundObsoleteItemNode' => [
+ 'pattern' => '
- 'The
- node is obsolete. Instead, use the
- '
+ ],
+ 'FoundObsoleteValueNode' => [
+ 'pattern' => ' 'The node is obsolete. Instead, provide the actual value as a text literal'
+ ],
];
/**
@@ -41,12 +51,12 @@ public function process(File $phpcsFile, $stackPtr)
{
$lineContent = $phpcsFile->getTokensAsString($stackPtr, 1);
- foreach ($this->obsoleteDiNodes as $element => $message) {
- if (strpos($lineContent, $element) !== false) {
+ foreach (self::OBSOLETE_NODES as $code => $data) {
+ if (strpos($lineContent, $data['pattern']) !== false) {
$phpcsFile->addWarning(
- $message,
+ $data['message'],
$stackPtr,
- self::WARNING_CODE
+ $code
);
}
}
diff --git a/Magento2/Sniffs/Legacy/EmailTemplateSniff.php b/Magento2/Sniffs/Legacy/EmailTemplateSniff.php
index 17ebbf08..85d6b9a0 100644
--- a/Magento2/Sniffs/Legacy/EmailTemplateSniff.php
+++ b/Magento2/Sniffs/Legacy/EmailTemplateSniff.php
@@ -15,12 +15,16 @@
class EmailTemplateSniff implements Sniff
{
private const OBSOLETE_EMAIL_DIRECTIVES = [
- '/\{\{htmlescape.*?\}\}/i' => 'Directive {{htmlescape}} is obsolete. Use {{var}} instead.',
- '/\{\{escapehtml.*?\}\}/i' => 'Directive {{escapehtml}} is obsolete. Use {{var}} instead.',
+ 'FoundObsoleteHtmlescapeDirective' => [
+ 'pattern' => '/\{\{htmlescape.*?\}\}/i',
+ 'message' => 'Directive {{htmlescape}} is obsolete. Use {{var}} instead.',
+ ],
+ 'FoundObsoleteEscapehtmlDirective' => [
+ 'pattern' => '/\{\{escapehtml.*?\}\}/i',
+ 'message' => 'Directive {{escapehtml}} is obsolete. Use {{var}} instead.',
+ ],
];
- private const ERROR_CODE = 'FoundObsoleteEmailDirective';
-
/**
* @inheritdoc
*/
@@ -37,12 +41,12 @@ public function register(): array
public function process(File $phpcsFile, $stackPtr)
{
$content = $phpcsFile->getTokens()[$stackPtr]['content'];
- foreach (self::OBSOLETE_EMAIL_DIRECTIVES as $directiveRegex => $errorMessage) {
- if (preg_match($directiveRegex, $content)) {
+ foreach (self::OBSOLETE_EMAIL_DIRECTIVES as $code => $data) {
+ if (preg_match($data['pattern'], $content)) {
$phpcsFile->addError(
- $errorMessage,
+ $data['message'],
$stackPtr,
- self::ERROR_CODE
+ $code
);
}
}
diff --git a/Magento2/Sniffs/Legacy/InstallUpgradeSniff.php b/Magento2/Sniffs/Legacy/InstallUpgradeSniff.php
index c7df570c..09dbedfb 100644
--- a/Magento2/Sniffs/Legacy/InstallUpgradeSniff.php
+++ b/Magento2/Sniffs/Legacy/InstallUpgradeSniff.php
@@ -13,28 +13,58 @@
class InstallUpgradeSniff implements Sniff
{
- private const ERROR_CODE = 'obsoleteScript';
+ private const WRONG_PREFIXES = [
+ 'ObsoleteInstallScript' => [
+ 'pattern' => 'install-',
+ 'message' => 'Install scripts are obsolete. '
+ . 'Please use declarative schema approach in module\'s etc/db_schema.xml file',
+ ],
+ 'ObsoleteInstallSchemaScript' => [
+ 'pattern' => 'InstallSchema',
+ 'message' => 'InstallSchema scripts are obsolete. '
+ . 'Please use declarative schema approach in module\'s etc/db_schema.xml file',
+ ],
+ 'ObsoleteInstallDataScript' => [
+ 'pattern' => 'InstallData',
+ 'message' => 'InstallData scripts are obsolete. '
+ . 'Please use data patches approach in module\'s Setup/Patch/Data dir',
+ ],
+ 'ObsoleteDataInstallScript' => [
+ 'pattern' => 'data-install-',
+ 'message' => 'Install scripts are obsolete. Please create class InstallData in module\'s Setup folder',
+ ],
+ 'ObsoleteUpgradeScript' => [
+ 'pattern' => 'upgrade-',
+ 'message' => 'Upgrade scripts are obsolete. '
+ . 'Please use declarative schema approach in module\'s etc/db_schema.xml file',
+ ],
+ 'ObsoleteUpgradeSchemaScript' => [
+ 'pattern' => 'UpgradeSchema',
+ 'message' => 'UpgradeSchema scripts are obsolete. '
+ . 'Please use declarative schema approach in module\'s etc/db_schema.xml file',
+ ],
+ 'ObsoleteUpgradeDataScript' => [
+ 'pattern' => 'UpgradeData',
+ 'message' => 'UpgradeData scripts are obsolete. '
+ . 'Please use data patches approach in module\'s Setup/Patch/Data dir',
+ ],
+ 'ObsoleteDataUpgradeScript' => [
+ 'pattern' => 'data-upgrade',
+ 'message' => 'Upgrade scripts are obsolete. '
+ . 'Please use data patches approach in module\'s Setup/Patch/Data dir',
+ ],
+ 'ObsoleteRecurringScript' => [
+ 'pattern' => 'recurring',
+ 'message' => 'Recurring scripts are obsolete. Please create class Recurring in module\'s Setup folder'
+ ]
+ ];
/**
* @var string[]
*/
- private $wrongPrefixes = [
- 'install-' => 'Install scripts are obsolete. '
- . 'Please use declarative schema approach in module\'s etc/db_schema.xml file',
- 'InstallSchema' => 'InstallSchema scripts are obsolete. '
- . 'Please use declarative schema approach in module\'s etc/db_schema.xml file',
- 'InstallData' => 'InstallData scripts are obsolete. '
- . 'Please use data patches approach in module\'s Setup/Patch/Data dir',
- 'data-install-' => 'Install scripts are obsolete. Please create class InstallData in module\'s Setup folder',
- 'upgrade-' => 'Upgrade scripts are obsolete. '
- . 'Please use declarative schema approach in module\'s etc/db_schema.xml file',
- 'UpgradeSchema' => 'UpgradeSchema scripts are obsolete. '
- . 'Please use declarative schema approach in module\'s etc/db_schema.xml file',
- 'UpgradeData' => 'UpgradeSchema scripts are obsolete. '
- . 'Please use data patches approach in module\'s Setup/Patch/Data dir',
- 'data-upgrade-' => 'Upgrade scripts are obsolete. '
- . 'Please use data patches approach in module\'s Setup/Patch/Data dir',
- 'recurring' => 'Recurring scripts are obsolete. Please create class Recurring in module\'s Setup folder',
+ private const INVALID_DIRECTORIES_ERROR_CODES = [
+ 'data' => 'DataInvalidDirectory',
+ 'sql' => 'SqlInvalidDirectory'
];
/**
@@ -58,9 +88,9 @@ public function process(File $phpcsFile, $stackPtr)
$fileInfo = new SplFileInfo($phpcsFile->getFilename());
- foreach ($this->wrongPrefixes as $prefix => $errorMessage) {
- if (strpos($fileInfo->getFilename(), $prefix) === 0) {
- $phpcsFile->addError($errorMessage, 0, self::ERROR_CODE);
+ foreach (self::WRONG_PREFIXES as $code => $data) {
+ if (strpos($fileInfo->getFilename(), $data['pattern']) === 0) {
+ $phpcsFile->addError($data['message'], 0, $code);
}
}
@@ -73,7 +103,7 @@ public function process(File $phpcsFile, $stackPtr)
. "- Create a data patch within module's Setup/Patch/Data folder for data upgrades.\n"
. "- Use declarative schema approach in module's etc/db_schema.xml file for schema changes.",
0,
- self::ERROR_CODE
+ self::INVALID_DIRECTORIES_ERROR_CODES[$folderName]
);
}
}
diff --git a/Magento2/Sniffs/Legacy/LayoutSniff.php b/Magento2/Sniffs/Legacy/LayoutSniff.php
index 3a2c2044..78b67b21 100644
--- a/Magento2/Sniffs/Legacy/LayoutSniff.php
+++ b/Magento2/Sniffs/Legacy/LayoutSniff.php
@@ -19,8 +19,9 @@ class LayoutSniff implements Sniff
{
private const ERROR_CODE_XML = 'WrongXML';
private const ERROR_CODE_NOT_ALLOWED = 'NotAllowed';
- private const ERROR_CODE_OBSOLETE = 'Obsolete';
+ private const ERROR_CODE_OBSOLETE_BLOCK = 'ObsoleteBlock';
private const ERROR_CODE_OBSOLETE_CLASS = 'ObsoleteClass';
+ private const ERROR_CODE_OBSOLETE_TOHTML_ATTRIBUTE = 'ObsoleteToHtmlAttribute';
private const ERROR_CODE_METHOD_NOT_ALLOWED = 'MethodNotAllowed';
private const ERROR_CODE_HELPER_ATTRIBUTE_CHARACTER_NOT_ALLOWED = 'CharacterNotAllowedInAttribute';
private const ERROR_CODE_HELPER_ATTRIBUTE_CHARACTER_EXPECTED = 'CharacterExpectedInAttribute';
@@ -254,7 +255,7 @@ private function testObsoleteReferences(SimpleXMLElement $layout, File $phpcsFil
$phpcsFile->addError(
'The block being referenced is removed.',
dom_import_simplexml($reference)->getLineNo()-1,
- self::ERROR_CODE_OBSOLETE
+ self::ERROR_CODE_OBSOLETE_BLOCK
);
}
}
@@ -317,7 +318,7 @@ private function testOutputAttribute(SimpleXMLElement $layout, File $phpcsFile):
$phpcsFile->addError(
'output="toHtml" is obsolete. Use output="1"',
dom_import_simplexml($elements[0])->getLineNo()-1,
- self::ERROR_CODE_OBSOLETE
+ self::ERROR_CODE_OBSOLETE_TOHTML_ATTRIBUTE
);
};
}
diff --git a/Magento2/Sniffs/Legacy/ObsoleteConnectionSniff.php b/Magento2/Sniffs/Legacy/ObsoleteConnectionSniff.php
index a1425cab..74a74394 100644
--- a/Magento2/Sniffs/Legacy/ObsoleteConnectionSniff.php
+++ b/Magento2/Sniffs/Legacy/ObsoleteConnectionSniff.php
@@ -12,8 +12,6 @@
class ObsoleteConnectionSniff implements Sniff
{
- private const ERROR_CODE_METHOD = 'FoundObsoleteMethod';
-
/**
* @var string[]
*/
@@ -28,6 +26,8 @@ class ObsoleteConnectionSniff implements Sniff
'getWriteAdapter',
];
+ private const OBSOLETE_METHOD_ERROR_CODE = 'ObsoleteMethodFound';
+
/**
* @inheritdoc
*/
@@ -63,7 +63,7 @@ private function validateObsoleteMethod(File $phpcsFile, int $stackPtr)
$phpcsFile->addWarning(
sprintf("Contains obsolete method: %s. Please use getConnection method instead.", $method),
$stackPtr,
- self::ERROR_CODE_METHOD
+ self::OBSOLETE_METHOD_ERROR_CODE
);
}
}
diff --git a/Magento2/Sniffs/Legacy/ObsoleteResponseSniff.php b/Magento2/Sniffs/Legacy/ObsoleteResponseSniff.php
index 725a8b15..765ae5f1 100644
--- a/Magento2/Sniffs/Legacy/ObsoleteResponseSniff.php
+++ b/Magento2/Sniffs/Legacy/ObsoleteResponseSniff.php
@@ -12,8 +12,6 @@
class ObsoleteResponseSniff implements Sniff
{
- private const WARNING_CODE_METHOD = 'FoundObsoleteResponseMethod';
-
/**
* @var string[]
*/
@@ -29,6 +27,22 @@ class ObsoleteResponseSniff implements Sniff
'_addJs' => 'Please use \Magento\Backend\Model\View\Result\Page::addJs instead.',
'_moveBlockToContainer' => 'Please use \Magento\Backend\Model\View\Result\Page::moveBlockToContainer instead.',
];
+
+ /**
+ * @var string[]
+ */
+ private $obsoleteResponseWarningCodes = [
+ 'loadLayout' => 'LoadLayoutResponseMethodFound',
+ 'renderLayout' => 'RenderLayoutResponseMethodFound',
+ '_redirect' => 'RedirectResponseMethodFound',
+ '_forward' => 'ForwardResponseMethodFound',
+ '_setActiveMenu' => 'SetActiveMenuResponseMethodFound',
+ '_addBreadcrumb' => 'AddBreadcrumbResponseMethodFound',
+ '_addContent' => 'AddContentResponseMethodFound',
+ '_addLeft' => 'AddLeftResponseMethodFound',
+ '_addJs' => 'AddJsResponseMethodFound',
+ '_moveBlockToContainer' => 'MoveBlockToContainerResponseMethodFound',
+ ];
/**
* @inheritdoc
@@ -54,7 +68,7 @@ public function process(File $phpcsFile, $stackPtr)
$phpcsFile->addWarning(
sprintf('%s method is deprecated. %s', $method, $errorMessage),
$stackPtr,
- self::WARNING_CODE_METHOD
+ $this->obsoleteResponseWarningCodes[$method]
);
}
}
diff --git a/Magento2/Sniffs/Legacy/PhtmlTemplateSniff.php b/Magento2/Sniffs/Legacy/PhtmlTemplateSniff.php
index 67d74575..4217ecda 100644
--- a/Magento2/Sniffs/Legacy/PhtmlTemplateSniff.php
+++ b/Magento2/Sniffs/Legacy/PhtmlTemplateSniff.php
@@ -12,15 +12,23 @@
class PhtmlTemplateSniff implements Sniff
{
- private const WARNING_CODE = 'PhtmlTemplateObsolete';
+ 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_IN_SPECIFIC_PHTML_TEMPLATES = [
- '/(["\'])jquery\/ui\1/' => 'Please do not use "jquery/ui" library in templates. Use needed jquery ' .
- 'ui widget instead.',
- '/data-mage-init=(?:\'|")(?!\s*{\s*"[^"]+")/' => 'Please do not initialize JS component in php. Do ' .
- 'it in template.',
- '@x-magento-init.>(?!\s*+{\s*"[^"]+"\s*:\s*{\s*"[\w/-]+")@i' => 'Please do not initialize JS component ' .
- 'in php. Do it in template.',
+ 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'
+ ],
];
/**
@@ -77,7 +85,7 @@ private function checkBlockVariable(File $phpcsFile, int $stackPtr, array $token
'Access to protected and private members of Block class is ' .
'obsolete in phtml templates. Use only public members.',
$stringPos,
- self::WARNING_CODE
+ self::WARNING_CODE_PROTECTED_PRIVATE_BLOCK_ACCESS
);
}
}
@@ -101,7 +109,7 @@ private function checkThisVariable(File $phpcsFile, int $stackPtr, array $tokens
'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
+ self::WARNING_CODE_THIS_USAGE
);
}
}
@@ -120,7 +128,7 @@ private function checkHtml(File $phpcsFile, int $stackPtr): void
$phpcsFile->addWarning(
'Please do not use "text/javascript" type attribute.',
$stackPtr,
- self::WARNING_CODE
+ self::WARNING_CODE_TEXT_JAVASCRIPT
);
}
}
@@ -135,12 +143,12 @@ private function checkHtmlSpecificFiles(File $phpcsFile, int $stackPtr): void
{
$content = $phpcsFile->getTokensAsString($stackPtr, 1);
- foreach (self::OBSOLETE_REGEX_IN_SPECIFIC_PHTML_TEMPLATES as $obsoleteRegex => $errorMessage) {
- if (preg_match($obsoleteRegex, $content)) {
+ foreach (self::OBSOLETE_REGEX as $code => $data) {
+ if (preg_match($data['pattern'], $content)) {
$phpcsFile->addWarning(
- $errorMessage,
+ $data['message'],
$stackPtr,
- self::WARNING_CODE
+ $code
);
}
}
diff --git a/Magento2/Sniffs/Legacy/RestrictedCodeSniff.php b/Magento2/Sniffs/Legacy/RestrictedCodeSniff.php
index 62ee2d4e..5b6c860c 100644
--- a/Magento2/Sniffs/Legacy/RestrictedCodeSniff.php
+++ b/Magento2/Sniffs/Legacy/RestrictedCodeSniff.php
@@ -16,7 +16,6 @@
class RestrictedCodeSniff implements Sniff
{
private const ERROR_MESSAGE = "Class '%s' is restricted in %s. Suggested replacement: %s";
- private const ERROR_CODE = "restrictedClass";
/**
* List of fixtures that contain restricted classes and should not be tested
@@ -76,7 +75,7 @@ public function process(File $phpcsFile, $stackPtr)
$this->classes[$token]['replacement']
),
$stackPtr,
- self::ERROR_CODE,
+ $this->classes[$token]['warning_code'],
);
}
}
diff --git a/Magento2/Sniffs/Legacy/WidgetXMLSniff.php b/Magento2/Sniffs/Legacy/WidgetXMLSniff.php
index efd62aee..aee84dc8 100644
--- a/Magento2/Sniffs/Legacy/WidgetXMLSniff.php
+++ b/Magento2/Sniffs/Legacy/WidgetXMLSniff.php
@@ -15,7 +15,8 @@
*/
class WidgetXMLSniff implements Sniff
{
- private const ERROR_CODE_OBSOLETE = 'FoundObsoleteNode';
+ private const ERROR_CODE_OBSOLETE_SUPPORTED_BLOCKS = 'FoundObsoleteNodeSupportedBlocks';
+ private const ERROR_CODE_OBSOLETE_BLOCK_NAME = 'FoundObsoleteNodeBlockName';
private const ERROR_CODE_FACTORY = 'FoundFactory';
private const ERROR_CODE_XML = 'WrongXML';
@@ -66,7 +67,7 @@ public function process(File $phpcsFile, $stackPtr)
$phpcsFile->addError(
"Obsolete node: . To be replaced with ",
dom_import_simplexml($element)->getLineNo() - 1,
- self::ERROR_CODE_OBSOLETE
+ self::ERROR_CODE_OBSOLETE_SUPPORTED_BLOCKS
);
}
@@ -75,7 +76,7 @@ public function process(File $phpcsFile, $stackPtr)
$phpcsFile->addError(
"Obsolete node: . To be replaced with ",
dom_import_simplexml($element)->getLineNo() - 1,
- self::ERROR_CODE_OBSOLETE
+ self::ERROR_CODE_OBSOLETE_BLOCK_NAME
);
}
}
diff --git a/Magento2/Sniffs/Legacy/_files/restricted_classes.php b/Magento2/Sniffs/Legacy/_files/restricted_classes.php
index 1052b994..ed6d2540 100644
--- a/Magento2/Sniffs/Legacy/_files/restricted_classes.php
+++ b/Magento2/Sniffs/Legacy/_files/restricted_classes.php
@@ -13,6 +13,7 @@
*/
return [
'Zend_Db_Select' => [
+ 'warning_code' => 'ZendDbSelect',
'replacement' => '\Magento\Framework\DB\Select',
'exclude' => [
'Magento/Framework/DB/Select.php',
@@ -22,12 +23,14 @@
]
],
'Zend_Db_Adapter_Pdo_Mysql' => [
+ 'warning_code' => 'ZendDbAdapterPdoMysqlIsRestricted',
'replacement' => '\Magento\Framework\DB\Adapter\Pdo\Mysql',
'exclude' => [
'Magento/Framework/DB/Adapter/Pdo/Mysql.php'
]
],
'Magento\Framework\Serialize\Serializer\Serialize' => [
+ 'warning_code' => 'SerializerSerializeIsRestricted',
'replacement' => 'Magento\Framework\Serialize\SerializerInterface',
'exclude' => [
'Magento/Framework/App/ObjectManager/ConfigLoader/Compiled.php',
@@ -56,6 +59,7 @@
]
],
'ArrayObject' => [
+ 'warning_code' => 'ArrayObjectIsRestricted',
'replacement' => 'Custom class, extended from ArrayObject with overwritten serialize/unserialize methods',
'exclude' => [
'Magento/Theme/Model/Indexer/Design/Config.php',
@@ -78,6 +82,7 @@
]
],
'Magento\Framework\View\Element\UiComponent\ArrayObjectFactory' => [
+ 'warning_code' => 'ArrayObjectFactoryIsRestricted',
'replacement' => 'Factory that creates custom class, extended from ArrayObject with overwritten '
. 'serialize/unserialize methods',
'exclude' => [
diff --git a/Magento2/Sniffs/NamingConvention/InterfaceNameSniff.php b/Magento2/Sniffs/NamingConvention/InterfaceNameSniff.php
index 2ad688ec..8daf5226 100644
--- a/Magento2/Sniffs/NamingConvention/InterfaceNameSniff.php
+++ b/Magento2/Sniffs/NamingConvention/InterfaceNameSniff.php
@@ -45,16 +45,16 @@ public function register()
/**
* @inheritdoc
*/
- public function process(File $sourceFile, $stackPtr)
+ public function process(File $phpcsFile, $stackPtr)
{
- $tokens = $sourceFile->getTokens();
+ $tokens = $phpcsFile->getTokens();
$declarationLine = $tokens[$stackPtr]['line'];
$suffixLength = strlen($this->interfaceSuffix);
// Find first T_STRING after 'interface' keyword in the line and verify it
while ($tokens[$stackPtr]['line'] === $declarationLine) {
if ($tokens[$stackPtr]['type'] === 'T_STRING') {
if (substr($tokens[$stackPtr]['content'], 0 - $suffixLength) !== $this->interfaceSuffix) {
- $sourceFile->addWarning($this->warningMessage, $stackPtr, $this->warningCode);
+ $phpcsFile->addWarning($this->warningMessage, $stackPtr, $this->warningCode);
}
break;
}
diff --git a/Magento2/Sniffs/NamingConvention/ReservedWordsSniff.php b/Magento2/Sniffs/NamingConvention/ReservedWordsSniff.php
index 23724a7c..13109c58 100644
--- a/Magento2/Sniffs/NamingConvention/ReservedWordsSniff.php
+++ b/Magento2/Sniffs/NamingConvention/ReservedWordsSniff.php
@@ -36,6 +36,9 @@ class ReservedWordsSniff implements Sniff
'numeric' => '7',
];
+ private const CLASS_ERROR_CODE = 'ForbiddenAsClassName';
+ private const NAMESPACE_ERROR_CODE = 'ForbiddenAsNameSpace';
+
/**
* @inheritdoc
*/
@@ -51,7 +54,7 @@ public function register()
* @param int $stackPtr
* @return void
*/
- protected function validateNamespace(File $sourceFile, $stackPtr)
+ protected function validateNamespace(File $sourceFile, int $stackPtr)
{
$stackPtr += 2;
$tokens = $sourceFile->getTokens();
@@ -65,7 +68,7 @@ protected function validateNamespace(File $sourceFile, $stackPtr)
$sourceFile->addError(
'Cannot use "%s" in namespace as it is reserved since PHP %s',
$stackPtr,
- 'Namespace',
+ self::NAMESPACE_ERROR_CODE,
[$namespacePart, $this->reservedWords[strtolower($namespacePart)]]
);
}
@@ -80,7 +83,7 @@ protected function validateNamespace(File $sourceFile, $stackPtr)
* @param int $stackPtr
* @return void
*/
- protected function validateClass(File $sourceFile, $stackPtr)
+ protected function validateClass(File $sourceFile, int $stackPtr)
{
$tokens = $sourceFile->getTokens();
$stackPtr += 2; //skip "class" and whitespace
@@ -89,7 +92,7 @@ protected function validateClass(File $sourceFile, $stackPtr)
$sourceFile->addError(
'Cannot use "%s" as class name as it is reserved since PHP %s',
$stackPtr,
- 'Class',
+ self::CLASS_ERROR_CODE,
[$className, $this->reservedWords[$className]]
);
}
@@ -98,17 +101,17 @@ protected function validateClass(File $sourceFile, $stackPtr)
/**
* @inheritdoc
*/
- public function process(File $sourceFile, $stackPtr)
+ public function process(File $phpcsFile, $stackPtr)
{
- $tokens = $sourceFile->getTokens();
+ $tokens = $phpcsFile->getTokens();
switch ($tokens[$stackPtr]['code']) {
case T_CLASS:
case T_INTERFACE:
case T_TRAIT:
- $this->validateClass($sourceFile, $stackPtr);
+ $this->validateClass($phpcsFile, $stackPtr);
break;
case T_NAMESPACE:
- $this->validateNamespace($sourceFile, $stackPtr);
+ $this->validateNamespace($phpcsFile, $stackPtr);
break;
}
}
diff --git a/Magento2/Sniffs/PHP/AutogeneratedClassNotInConstructorSniff.php b/Magento2/Sniffs/PHP/AutogeneratedClassNotInConstructorSniff.php
index f99346af..6c56d07e 100644
--- a/Magento2/Sniffs/PHP/AutogeneratedClassNotInConstructorSniff.php
+++ b/Magento2/Sniffs/PHP/AutogeneratedClassNotInConstructorSniff.php
@@ -15,7 +15,7 @@
*/
class AutogeneratedClassNotInConstructorSniff implements Sniff
{
- private const ERROR_CODE = 'AUTOGENERATED_CLASS_NOT_IN_CONSTRUCTOR';
+ private const ERROR_CODE = 'AutogeneratedClassNotInConstructor';
/**
* @var array
diff --git a/Magento2/Sniffs/PHP/LiteralNamespacesSniff.php b/Magento2/Sniffs/PHP/LiteralNamespacesSniff.php
index 705e154b..d76dae3e 100644
--- a/Magento2/Sniffs/PHP/LiteralNamespacesSniff.php
+++ b/Magento2/Sniffs/PHP/LiteralNamespacesSniff.php
@@ -37,11 +37,11 @@ public function register()
/**
* @inheritdoc
*/
- public function process(File $sourceFile, $stackPtr)
+ public function process(File $phpcsFile, $stackPtr)
{
- $tokens = $sourceFile->getTokens();
- if ($sourceFile->findPrevious(T_STRING_CONCAT, $stackPtr, $stackPtr - 3) ||
- $sourceFile->findNext(T_STRING_CONCAT, $stackPtr, $stackPtr + 3)
+ $tokens = $phpcsFile->getTokens();
+ if ($phpcsFile->findPrevious(T_STRING_CONCAT, $stackPtr, $stackPtr - 3) ||
+ $phpcsFile->findNext(T_STRING_CONCAT, $stackPtr, $stackPtr + 3)
) {
return;
}
@@ -53,7 +53,7 @@ public function process(File $sourceFile, $stackPtr)
}
if (preg_match($this->literalNamespacePattern, $content) === 1) {
- $sourceFile->addWarning(
+ $phpcsFile->addWarning(
"Use ::class notation instead.",
$stackPtr,
'LiteralClassUsage'