Skip to content

Commit 718975a

Browse files
committed
AC-669: Create phpcs static check for InstallUpgradeTest
1 parent b6bff95 commit 718975a

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

Magento2/Sniffs/Legacy/InstallUpgradeSniff.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use PHP_CodeSniffer\Files\File;
1111
use PHP_CodeSniffer\Sniffs\Sniff;
12+
use SplFileInfo;
1213

1314
class InstallUpgradeSniff implements Sniff
1415
{
@@ -32,8 +33,10 @@ public function process(File $phpcsFile, $stackPtr)
3233
if ($stackPtr > 0) {
3334
return;
3435
}
36+
37+
$fileInfo = new SplFileInfo($phpcsFile->getFilename());
3538

36-
if (strpos(basename($phpcsFile->getFilename()), 'install-') === 0) {
39+
if (strpos($fileInfo->getFilename(), 'install-') === 0) {
3740
$phpcsFile->addError(
3841
'Install scripts are obsolete. '
3942
. 'Please use declarative schema approach in module\'s etc/db_schema.xml file',
@@ -42,7 +45,7 @@ public function process(File $phpcsFile, $stackPtr)
4245
);
4346
}
4447

45-
if (strpos(basename($phpcsFile->getFilename()), 'InstallSchema') === 0) {
48+
if (strpos($fileInfo->getFilename(), 'InstallSchema') === 0) {
4649
$phpcsFile->addError(
4750
'InstallSchema scripts are obsolete. '
4851
. 'Please use declarative schema approach in module\'s etc/db_schema.xml file',
@@ -51,7 +54,7 @@ public function process(File $phpcsFile, $stackPtr)
5154
);
5255
}
5356

54-
if (strpos(basename($phpcsFile->getFilename()), 'InstallData') === 0) {
57+
if (strpos($fileInfo->getFilename(), 'InstallData') === 0) {
5558
$phpcsFile->addError(
5659
'InstallData scripts are obsolete. '
5760
. 'Please use data patches approach in module\'s Setup/Patch/Data dir',
@@ -60,15 +63,15 @@ public function process(File $phpcsFile, $stackPtr)
6063
);
6164
}
6265

63-
if (strpos(basename($phpcsFile->getFilename()), 'data-install-') === 0) {
66+
if (strpos($fileInfo->getFilename(), 'data-install-') === 0) {
6467
$phpcsFile->addError(
6568
'Install scripts are obsolete. Please create class InstallData in module\'s Setup folder',
6669
0,
6770
self::ERROR_CODE
6871
);
6972
}
7073

71-
if (strpos(basename($phpcsFile->getFilename()), 'upgrade-') === 0) {
74+
if (strpos($fileInfo->getFilename(), 'upgrade-') === 0) {
7275
$phpcsFile->addError(
7376
'Upgrade scripts are obsolete. '
7477
. 'Please use declarative schema approach in module\'s etc/db_schema.xml file',
@@ -77,7 +80,7 @@ public function process(File $phpcsFile, $stackPtr)
7780
);
7881
}
7982

80-
if (strpos(basename($phpcsFile->getFilename()), 'UpgradeSchema') === 0) {
83+
if (strpos($fileInfo->getFilename(), 'UpgradeSchema') === 0) {
8184
$phpcsFile->addError(
8285
'UpgradeSchema scripts are obsolete. '
8386
. 'Please use declarative schema approach in module\'s etc/db_schema.xml file',
@@ -86,7 +89,7 @@ public function process(File $phpcsFile, $stackPtr)
8689
);
8790
}
8891

89-
if (strpos(basename($phpcsFile->getFilename()), 'UpgradeData') === 0) {
92+
if (strpos($fileInfo->getFilename(), 'UpgradeData') === 0) {
9093
$phpcsFile->addError(
9194
'UpgradeSchema scripts are obsolete. '
9295
. 'Please use data patches approach in module\'s Setup/Patch/Data dir',
@@ -95,7 +98,7 @@ public function process(File $phpcsFile, $stackPtr)
9598
);
9699
}
97100

98-
if (strpos(basename($phpcsFile->getFilename()), 'data-upgrade-') === 0) {
101+
if (strpos($fileInfo->getFilename(), 'data-upgrade-') === 0) {
99102
$phpcsFile->addError(
100103
'Upgrade scripts are obsolete. '
101104
. 'Please use data patches approach in module\'s Setup/Patch/Data dir',
@@ -104,17 +107,17 @@ public function process(File $phpcsFile, $stackPtr)
104107
);
105108
}
106109

107-
if (strpos(basename($phpcsFile->getFilename()), 'recurring') === 0) {
110+
if (strpos($fileInfo->getFilename(), 'recurring') === 0) {
108111
$phpcsFile->addError(
109112
'Recurring scripts are obsolete. Please create class Recurring in module\'s Setup folder',
110113
0,
111114
self::ERROR_CODE
112115
);
113116
}
114117

115-
if (preg_match('/(sql|data)/', dirname($phpcsFile->getFilename())) === 1) {
118+
if (preg_match('/(sql|data)/', $fileInfo->getPath()) === 1) {
116119
$phpcsFile->addError(
117-
$phpcsFile->getFilename()." is in an invalid directory ".dirname($phpcsFile->getFilename()).":\n"
120+
$fileInfo->getFilename()." is in an invalid directory ".$fileInfo->getPath().":\n"
118121
. "- Create a data patch within module's Setup/Patch/Data folder for data upgrades.\n"
119122
. "- Use declarative schema approach in module's etc/db_schema.xml file for schema changes.",
120123
0,

0 commit comments

Comments
 (0)