Skip to content

Commit 97b843c

Browse files
committed
AC-669: Create phpcs static check for InstallUpgradeTest
1 parent 6601b5b commit 97b843c

File tree

1 file changed

+23
-77
lines changed

1 file changed

+23
-77
lines changed

Magento2/Sniffs/Legacy/InstallUpgradeSniff.php

+23-77
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,25 @@ class InstallUpgradeSniff implements Sniff
1515
{
1616
private const ERROR_CODE = 'obsoleteScript';
1717

18+
private $wrongPrefixes = [
19+
'install-' => 'Install scripts are obsolete. '
20+
. 'Please use declarative schema approach in module\'s etc/db_schema.xml file',
21+
'InstallSchema' => 'InstallSchema scripts are obsolete. '
22+
. 'Please use declarative schema approach in module\'s etc/db_schema.xml file',
23+
'InstallData' => 'InstallData scripts are obsolete. '
24+
. 'Please use data patches approach in module\'s Setup/Patch/Data dir',
25+
'data-install-' => 'Install scripts are obsolete. Please create class InstallData in module\'s Setup folder',
26+
'upgrade-' => 'Upgrade scripts are obsolete. '
27+
. 'Please use declarative schema approach in module\'s etc/db_schema.xml file',
28+
'UpgradeSchema' => 'UpgradeSchema scripts are obsolete. '
29+
. 'Please use declarative schema approach in module\'s etc/db_schema.xml file',
30+
'UpgradeData' => 'UpgradeSchema scripts are obsolete. '
31+
. 'Please use data patches approach in module\'s Setup/Patch/Data dir',
32+
'data-upgrade-' => 'Upgrade scripts are obsolete. '
33+
. 'Please use data patches approach in module\'s Setup/Patch/Data dir',
34+
'recurring' => 'Recurring scripts are obsolete. Please create class Recurring in module\'s Setup folder',
35+
];
36+
1837
/**
1938
* @inheritdoc
2039
*/
@@ -36,83 +55,10 @@ public function process(File $phpcsFile, $stackPtr)
3655

3756
$fileInfo = new SplFileInfo($phpcsFile->getFilename());
3857

39-
if (strpos($fileInfo->getFilename(), 'install-') === 0) {
40-
$phpcsFile->addError(
41-
'Install scripts are obsolete. '
42-
. 'Please use declarative schema approach in module\'s etc/db_schema.xml file',
43-
0,
44-
self::ERROR_CODE
45-
);
46-
}
47-
48-
if (strpos($fileInfo->getFilename(), 'InstallSchema') === 0) {
49-
$phpcsFile->addError(
50-
'InstallSchema scripts are obsolete. '
51-
. 'Please use declarative schema approach in module\'s etc/db_schema.xml file',
52-
0,
53-
self::ERROR_CODE
54-
);
55-
}
56-
57-
if (strpos($fileInfo->getFilename(), 'InstallData') === 0) {
58-
$phpcsFile->addError(
59-
'InstallData scripts are obsolete. '
60-
. 'Please use data patches approach in module\'s Setup/Patch/Data dir',
61-
0,
62-
self::ERROR_CODE
63-
);
64-
}
65-
66-
if (strpos($fileInfo->getFilename(), 'data-install-') === 0) {
67-
$phpcsFile->addError(
68-
'Install scripts are obsolete. Please create class InstallData in module\'s Setup folder',
69-
0,
70-
self::ERROR_CODE
71-
);
72-
}
73-
74-
if (strpos($fileInfo->getFilename(), 'upgrade-') === 0) {
75-
$phpcsFile->addError(
76-
'Upgrade scripts are obsolete. '
77-
. 'Please use declarative schema approach in module\'s etc/db_schema.xml file',
78-
0,
79-
self::ERROR_CODE
80-
);
81-
}
82-
83-
if (strpos($fileInfo->getFilename(), 'UpgradeSchema') === 0) {
84-
$phpcsFile->addError(
85-
'UpgradeSchema scripts are obsolete. '
86-
. 'Please use declarative schema approach in module\'s etc/db_schema.xml file',
87-
0,
88-
self::ERROR_CODE
89-
);
90-
}
91-
92-
if (strpos($fileInfo->getFilename(), 'UpgradeData') === 0) {
93-
$phpcsFile->addError(
94-
'UpgradeSchema scripts are obsolete. '
95-
. 'Please use data patches approach in module\'s Setup/Patch/Data dir',
96-
0,
97-
self::ERROR_CODE
98-
);
99-
}
100-
101-
if (strpos($fileInfo->getFilename(), 'data-upgrade-') === 0) {
102-
$phpcsFile->addError(
103-
'Upgrade scripts are obsolete. '
104-
. 'Please use data patches approach in module\'s Setup/Patch/Data dir',
105-
0,
106-
self::ERROR_CODE
107-
);
108-
}
109-
110-
if (strpos($fileInfo->getFilename(), 'recurring') === 0) {
111-
$phpcsFile->addError(
112-
'Recurring scripts are obsolete. Please create class Recurring in module\'s Setup folder',
113-
0,
114-
self::ERROR_CODE
115-
);
58+
foreach ($this->wrongPrefixes as $prefix => $errorMessage) {
59+
if (strpos($fileInfo->getFilename(), $prefix) === 0) {
60+
$phpcsFile->addError($errorMessage, 0, self::ERROR_CODE);
61+
}
11662
}
11763

11864
if (preg_match('/(sql|data)/', $fileInfo->getPath()) === 1) {

0 commit comments

Comments
 (0)