[Rector] Apply Rector run on utils/ directory

This commit is contained in:
Abdul Malik Ikhsan 2022-07-03 11:35:07 +07:00
parent 7439b6ec51
commit 728499822f
No known key found for this signature in database
GPG Key ID: 69AC5BC354C89BE6
4 changed files with 15 additions and 27 deletions

View File

@ -64,7 +64,7 @@ return static function (RectorConfig $rectorConfig): void {
$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([

View File

@ -22,9 +22,6 @@ use PHPStan\Rules\Rule;
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

View File

@ -22,14 +22,7 @@ use PHPStan\Rules\Rule;
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 <admin@codeigniter\.com>/m';
public function getNodeType(): string

View File

@ -11,6 +11,8 @@ declare(strict_types=1);
* 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 @@ use CodeIgniter\CLI\CLI;
$rstFilesWithTabs = (string) shell_exec('git grep -EIPn "\t" -- "*.rst"');
$rstFilesWithTabs = explode("\n", $rstFilesWithTabs);
$rstFilesWithTabs = array_map(static function (string $line): array {
preg_match('/^(?P<file>[^:]+):(?P<line>[0-9]+):(?P<code>.+)$/', $line, $matches);
preg_match('/^(?P<file>[^:]+):(?P<line>\d+):(?P<code>.+)$/', $line, $matches);
return [
'file' => $matches['file'],
@ -44,20 +46,16 @@ if ($normalizedRstFilesWithTabs !== []) {
"%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),
)),