Skip to content

Commit 1bd89ac

Browse files
committed
AC-1549: Create codes for each type of returned error / warning
1 parent 6451e34 commit 1bd89ac

13 files changed

+267
-81
lines changed

Magento2/Sniffs/Legacy/AbstractBlockSniff.php

+4-8
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,8 @@ class AbstractBlockSniff implements Sniff
1515
private const CHILD_HTML_METHOD = 'getChildHtml';
1616
private const CHILD_CHILD_HTML_METHOD = 'getChildChildHtml';
1717

18-
/**
19-
* Error violation code.
20-
*
21-
* @var string
22-
*/
23-
protected $errorCode = 'FoundCountOfParametersIncorrect';
18+
private const ERROR_CODE_THIRD_PARAMETER = 'ThirdParameterNotNeeded';
19+
private const ERROR_CODE_FOURTH_PARAMETER = 'FourthParameterNotNeeded';
2420

2521
/**
2622
* @inheritdoc
@@ -52,14 +48,14 @@ public function process(File $phpcsFile, $stackPtr)
5248
$phpcsFile->addError(
5349
'3rd parameter is not needed anymore for getChildHtml()',
5450
$stackPtr,
55-
$this->errorCode
51+
self::ERROR_CODE_THIRD_PARAMETER
5652
);
5753
}
5854
if ($content === self::CHILD_CHILD_HTML_METHOD && $paramsCount >= 4) {
5955
$phpcsFile->addError(
6056
'4th parameter is not needed anymore for getChildChildHtml()',
6157
$stackPtr,
62-
$this->errorCode
58+
self::ERROR_CODE_FOURTH_PARAMETER
6359
);
6460
}
6561
}

Magento2/Sniffs/Legacy/DiConfigSniff.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@
1111

1212
class DiConfigSniff implements Sniff
1313
{
14-
private const WARNING_CODE = 'FoundObsoleteAttribute';
14+
private $obsoleteDiNodesWarningCodes = [
15+
'<param' => 'FoundObsoleteParamNode',
16+
'<instance' => 'FoundObsoleteInstanceNode',
17+
'<array' => 'FoundObsoleteArrayNode',
18+
'<item key=' => 'FoundObsoleteItemNode',
19+
'<value' => 'FoundObsoleteValueNode',
20+
];
1521

1622
/**
1723
* @var string[] Associative array containing the obsolete nodes and the message to display when they are found.
@@ -46,7 +52,7 @@ public function process(File $phpcsFile, $stackPtr)
4652
$phpcsFile->addWarning(
4753
$message,
4854
$stackPtr,
49-
self::WARNING_CODE
55+
$this->obsoleteDiNodesWarningCodes[$element]
5056
);
5157
}
5258
}

Magento2/Sniffs/Legacy/EmailTemplateSniff.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ class EmailTemplateSniff implements Sniff
1919
'/\{\{escapehtml.*?\}\}/i' => 'Directive {{escapehtml}} is obsolete. Use {{var}} instead.',
2020
];
2121

22-
private const ERROR_CODE = 'FoundObsoleteEmailDirective';
22+
private $errorCodes = [
23+
'/\{\{htmlescape.*?\}\}/i' => 'FoundObsoleteHtmlescapeDirective',
24+
'/\{\{escapehtml.*?\}\}/i' => 'FoundObsoleteEscapehtmlDirective'
25+
];
2326

2427
/**
2528
* @inheritdoc
@@ -42,7 +45,7 @@ public function process(File $phpcsFile, $stackPtr)
4245
$phpcsFile->addError(
4346
$errorMessage,
4447
$stackPtr,
45-
self::ERROR_CODE
48+
$this->errorCodes[$directiveRegex]
4649
);
4750
}
4851
}

Magento2/Sniffs/Legacy/InstallUpgradeSniff.php

+18-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
class InstallUpgradeSniff implements Sniff
1515
{
16-
private const ERROR_CODE = 'obsoleteScript';
16+
private const ERROR_CODE = 'invalidDirectory';
1717

1818
/**
1919
* @var string[]
@@ -30,13 +30,28 @@ class InstallUpgradeSniff implements Sniff
3030
. 'Please use declarative schema approach in module\'s etc/db_schema.xml file',
3131
'UpgradeSchema' => 'UpgradeSchema scripts are obsolete. '
3232
. 'Please use declarative schema approach in module\'s etc/db_schema.xml file',
33-
'UpgradeData' => 'UpgradeSchema scripts are obsolete. '
33+
'UpgradeData' => 'UpgradeData scripts are obsolete. '
3434
. 'Please use data patches approach in module\'s Setup/Patch/Data dir',
3535
'data-upgrade-' => 'Upgrade scripts are obsolete. '
3636
. 'Please use data patches approach in module\'s Setup/Patch/Data dir',
3737
'recurring' => 'Recurring scripts are obsolete. Please create class Recurring in module\'s Setup folder',
3838
];
3939

40+
/**
41+
* @var string[]
42+
*/
43+
private $wrongPrefixesErrorCodes = [
44+
'install-' => 'obsoleteInstallScript',
45+
'InstallSchema' => 'obsoleteInstallSchemaScript',
46+
'InstallData' => 'obsoleteInstallDataScript',
47+
'data-install-' => 'obsoleteDataInstallScript',
48+
'upgrade-' => 'obsoleteUpgradeScript',
49+
'UpgradeSchema' => 'obsoleteUpgradeSchemaScript',
50+
'UpgradeData' => 'obsoleteUpgradeDataScript',
51+
'data-upgrade-' => 'obsoleteDataUpgradeScript',
52+
'recurring' => 'obsoleteRecurringScript',
53+
];
54+
4055
/**
4156
* @inheritdoc
4257
*/
@@ -60,7 +75,7 @@ public function process(File $phpcsFile, $stackPtr)
6075

6176
foreach ($this->wrongPrefixes as $prefix => $errorMessage) {
6277
if (strpos($fileInfo->getFilename(), $prefix) === 0) {
63-
$phpcsFile->addError($errorMessage, 0, self::ERROR_CODE);
78+
$phpcsFile->addError($errorMessage, 0, $this->wrongPrefixesErrorCodes[$prefix]);
6479
}
6580
}
6681

Magento2/Sniffs/Legacy/LayoutSniff.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ class LayoutSniff implements Sniff
1919
{
2020
private const ERROR_CODE_XML = 'WrongXML';
2121
private const ERROR_CODE_NOT_ALLOWED = 'NotAllowed';
22-
private const ERROR_CODE_OBSOLETE = 'Obsolete';
22+
private const ERROR_CODE_OBSOLETE_BLOCK = 'ObsoleteBlock';
2323
private const ERROR_CODE_OBSOLETE_CLASS = 'ObsoleteClass';
24+
private const ERROR_CODE_OBSOLETE_TOHTML_ATTRIBUTE = 'ObsoleteToHtmlAttribute';
2425
private const ERROR_CODE_METHOD_NOT_ALLOWED = 'MethodNotAllowed';
2526
private const ERROR_CODE_HELPER_ATTRIBUTE_CHARACTER_NOT_ALLOWED = 'CharacterNotAllowedInAttribute';
2627
private const ERROR_CODE_HELPER_ATTRIBUTE_CHARACTER_EXPECTED = 'CharacterExpectedInAttribute';
@@ -254,7 +255,7 @@ private function testObsoleteReferences(SimpleXMLElement $layout, File $phpcsFil
254255
$phpcsFile->addError(
255256
'The block being referenced is removed.',
256257
dom_import_simplexml($reference)->getLineNo()-1,
257-
self::ERROR_CODE_OBSOLETE
258+
self::ERROR_CODE_OBSOLETE_BLOCK
258259
);
259260
}
260261
}
@@ -317,7 +318,7 @@ private function testOutputAttribute(SimpleXMLElement $layout, File $phpcsFile):
317318
$phpcsFile->addError(
318319
'output="toHtml" is obsolete. Use output="1"',
319320
dom_import_simplexml($elements[0])->getLineNo()-1,
320-
self::ERROR_CODE_OBSOLETE
321+
self::ERROR_CODE_OBSOLETE_TOHTML_ATTRIBUTE
321322
);
322323
};
323324
}

0 commit comments

Comments
 (0)