From 728499822f8291465686e707819a502fe8016131 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sun, 3 Jul 2022 11:35:07 +0700 Subject: [PATCH] [Rector] Apply Rector run on utils/ directory --- rector.php | 2 +- ...onInstantiationViaNamedConstructorRule.php | 3 -- .../CheckUseStatementsAfterLicenseRule.php | 9 +----- utils/check_tabs_in_rst.php | 28 +++++++++---------- 4 files changed, 15 insertions(+), 27 deletions(-) diff --git a/rector.php b/rector.php index 9631fd97fd0d..5ee5b69f7243 100644 --- a/rector.php +++ b/rector.php @@ -64,7 +64,7 @@ $rectorConfig->parallel(); // paths to refactor; solid alternative to CLI arguments - $rectorConfig->paths([__DIR__ . '/app', __DIR__ . '/system', __DIR__ . '/tests', __DIR__ . '/utils/Rector']); + $rectorConfig->paths([__DIR__ . '/app', __DIR__ . '/system', __DIR__ . '/tests', __DIR__ . '/utils']); // do you need to include constants, class aliases or custom autoloader? files listed will be executed $rectorConfig->bootstrapFiles([ diff --git a/utils/PHPStan/CheckFrameworkExceptionInstantiationViaNamedConstructorRule.php b/utils/PHPStan/CheckFrameworkExceptionInstantiationViaNamedConstructorRule.php index a2cefaddfdd7..5cca5ec8f4d4 100644 --- a/utils/PHPStan/CheckFrameworkExceptionInstantiationViaNamedConstructorRule.php +++ b/utils/PHPStan/CheckFrameworkExceptionInstantiationViaNamedConstructorRule.php @@ -22,9 +22,6 @@ final class CheckFrameworkExceptionInstantiationViaNamedConstructorRule implements Rule { - /** - * @var string - */ private const ERROR_MESSAGE = 'FrameworkException instance creation via new expression is not allowed, use its named constructor instead'; public function getNodeType(): string diff --git a/utils/PHPStan/CheckUseStatementsAfterLicenseRule.php b/utils/PHPStan/CheckUseStatementsAfterLicenseRule.php index 2bcd0e20f9a9..a3ccaf215d6e 100644 --- a/utils/PHPStan/CheckUseStatementsAfterLicenseRule.php +++ b/utils/PHPStan/CheckUseStatementsAfterLicenseRule.php @@ -22,14 +22,7 @@ final class CheckUseStatementsAfterLicenseRule implements Rule { - /** - * @var string - */ - private const ERROR_MESSAGE = 'Use statement must be located after license docblock'; - - /** - * @var string - */ + private const ERROR_MESSAGE = 'Use statement must be located after license docblock'; private const COPYRIGHT_REGEX = '/\* \(c\) CodeIgniter Foundation /m'; public function getNodeType(): string diff --git a/utils/check_tabs_in_rst.php b/utils/check_tabs_in_rst.php index a660aebcdc32..e99d08bf7645 100644 --- a/utils/check_tabs_in_rst.php +++ b/utils/check_tabs_in_rst.php @@ -11,6 +11,8 @@ * the LICENSE file that was distributed with this source code. */ +namespace Utils; + require __DIR__ . '/../system/Test/bootstrap.php'; use CodeIgniter\CLI\CLI; @@ -18,7 +20,7 @@ $rstFilesWithTabs = (string) shell_exec('git grep -EIPn "\t" -- "*.rst"'); $rstFilesWithTabs = explode("\n", $rstFilesWithTabs); $rstFilesWithTabs = array_map(static function (string $line): array { - preg_match('/^(?P[^:]+):(?P[0-9]+):(?P.+)$/', $line, $matches); + preg_match('/^(?P[^:]+):(?P\d+):(?P.+)$/', $line, $matches); return [ 'file' => $matches['file'], @@ -44,20 +46,16 @@ "%s\n\n%s\n", CLI::color('Tabs in RST files were detected:', 'light_gray', 'red'), implode("\n", array_map( - static function (string $file, array $parts): string { - return sprintf( - "%s%s\n%s\n", - CLI::color('* in ', 'light_red'), - CLI::color($file, 'yellow'), - implode("\n", array_map(static function (array $line): string { - return sprintf( - '%s | %s', - str_pad($line['line'], 4, ' ', STR_PAD_LEFT), - str_replace("\t", CLI::color('....', 'light_gray', 'red'), $line['code']), - ); - }, $parts)), - ); - }, + static fn (string $file, array $parts): string => sprintf( + "%s%s\n%s\n", + CLI::color('* in ', 'light_red'), + CLI::color($file, 'yellow'), + implode("\n", array_map(static fn (array $line): string => sprintf( + '%s | %s', + str_pad($line['line'], 4, ' ', STR_PAD_LEFT), + str_replace("\t", CLI::color('....', 'light_gray', 'red'), $line['code']), + ), $parts)), + ), array_keys($normalizedRstFilesWithTabs), array_values($normalizedRstFilesWithTabs), )),