diff --git a/composer-dependency-analyser.php b/composer-dependency-analyser.php index f8739d6..c7562fa 100644 --- a/composer-dependency-analyser.php +++ b/composer-dependency-analyser.php @@ -3,7 +3,8 @@ declare(strict_types=1); use ShipMonk\ComposerDependencyAnalyser\Config\Configuration; +use ShipMonk\ComposerDependencyAnalyser\Config\ErrorType; return (new Configuration()) // conditional use - ->ignoreErrorsOnExtension('ext-mbstring', [\ShipMonk\ComposerDependencyAnalyser\Config\ErrorType::SHADOW_DEPENDENCY]); + ->ignoreErrorsOnExtension('ext-mbstring', [ErrorType::SHADOW_DEPENDENCY]); diff --git a/composer.json b/composer.json index 563a2ca..84dbbbe 100644 --- a/composer.json +++ b/composer.json @@ -10,10 +10,9 @@ "composer/semver": "^3.4", "entropy/entropy": "dev-main", "nette/neon": "^3.4", - "symfony/filesystem": "^7.4|8.0.*", - "symfony/finder": "^7.4|8.0.*", - "symfony/process": "^7.4|8.0.*", - "webmozart/assert": "^1.12|^2.0" + "symfony/finder": "^7.4", + "symfony/process": "^7.4", + "webmozart/assert": "^1.12" }, "require-dev": { "phpecs/phpecs": "^2.3", diff --git a/phpstan.neon b/phpstan.neon index 3104771..6408921 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -21,6 +21,3 @@ parameters: # part of entropy magic contract - '#Public method "Rector\\(.*?)Command\:\:run\(\)" is never used#' - # too detailed - - '#Parameter (.*?) expects list, (.*?), int<0, max>> given#' - diff --git a/rector.php b/rector.php index deb230e..24685c8 100644 --- a/rector.php +++ b/rector.php @@ -3,27 +3,27 @@ declare(strict_types=1); use Rector\Config\RectorConfig; +use Rector\Naming\Rector\ClassMethod\RenameParamToMatchTypeRector; use Rector\TypeDeclaration\Rector\StmtsAwareInterface\DeclareStrictTypesRector; return RectorConfig::configure() ->withPaths([__DIR__ . '/bin', __DIR__ . '/src', __DIR__ . '/tests']) ->withPhpSets() ->withPreparedSets( - codeQuality: true, deadCode: true, + codeQuality: true, + codingStyle: true, typeDeclarations: true, privatization: true, - earlyReturn: true, - codingStyle: true, - instanceOf: true, naming: true, + instanceOf: true, + earlyReturn: true, rectorPreset: true, ) + ->withRootFiles() ->withSkip([ // some buggy glitch - \Rector\Naming\Rector\ClassMethod\RenameParamToMatchTypeRector::class => [ - __DIR__ . '/src/Composer/ComposerJsonResolver.php', - ], + RenameParamToMatchTypeRector::class => [__DIR__ . '/src/Composer/ComposerJsonResolver.php'], DeclareStrictTypesRector::class, ]) ->withImportNames(removeUnusedImports: true); diff --git a/src/Config/ConfigInitializer.php b/src/Config/ConfigInitializer.php index e370f0c..1269e6d 100644 --- a/src/Config/ConfigInitializer.php +++ b/src/Config/ConfigInitializer.php @@ -5,27 +5,26 @@ namespace Rector\Monitor\Config; use Entropy\Console\Output\OutputPrinter; -use Symfony\Component\Filesystem\Filesystem; +use Entropy\Utils\FileSystem; final readonly class ConfigInitializer { public function __construct( private OutputPrinter $outputPrinter, - private Filesystem $filesystem, ) { } public function createConfigIfMissing(string $projectDirectory): bool { - if ($this->filesystem->exists($projectDirectory . '/monitor.php')) { + if (file_exists($projectDirectory . '/monitor.php')) { // nothing to worry about return false; } - $templateFileContents = $this->filesystem->readFile(__DIR__ . '/../../templates/monitor.php.dist'); + $templateFileContents = FileSystem::read(__DIR__ . '/../../templates/monitor.php.dist'); // create the ecs.php file - $this->filesystem->dumpFile(getcwd() . '/monitor.php', $templateFileContents); + FileSystem::write(getcwd() . '/monitor.php', $templateFileContents); $this->outputPrinter->greenBackground( 'The monitor.php config was generated! Fill your repositories details and re-run the command again' ); diff --git a/src/Entropy/ConsoleTable.php b/src/Entropy/ConsoleTable.php index c61af9f..399f249 100644 --- a/src/Entropy/ConsoleTable.php +++ b/src/Entropy/ConsoleTable.php @@ -9,58 +9,33 @@ use Entropy\Attributes\RelatedTest; use Rector\Monitor\Entropy\Enum\ColumnAlign; use Rector\Monitor\Tests\Entropy\ConsoleTableTest; -use Stringable; use Webmozart\Assert\Assert; #[RelatedTest(testClass: ConsoleTableTest::class)] -final class ConsoleTable +final readonly class ConsoleTable { - /** - * @var list - */ - private readonly array $headers; - - /** - * @var list> - */ - private array $rows = []; - - /** - * @var list<'left'|'right'|'center'> - */ - private array $align; - /** * @param string[] $headers - * @param array> $rows - * @param array<'left'|'right'|'center'> $columnsAlign + * @param array> $rows + * @param array $columnsAlign */ - public function __construct(array $headers, array $rows, array $columnsAlign = []) - { + public function __construct( + private array $headers, + private array $rows, + private array $columnsAlign = [] + ) { Assert::notEmpty($headers); Assert::allString($headers); // nested arrays Assert::notEmpty($rows); Assert::allIsArray($rows); - - $this->headers = array_values($headers); - foreach ($rows as $row) { - $this->rows[] = array_values( - array_map( - static fn (float|int|TableCell|string|null $value): string => $value === null ? '' : (string) $value, - $row - ) - ); - } - - $this->align = array_values($columnsAlign); } public function render(): string { - $cols = max(count($this->headers), $this->maxRowColumns()); - $columnWidths = array_fill(0, $cols, 0); + $columns = max(count($this->headers), $this->maxRowColumns()); + $columnWidths = array_fill(0, $columns, 0); // headers foreach ($this->headers as $columId => $header) { @@ -108,7 +83,7 @@ private function maxRowColumns(): int } /** - * @param list $widths + * @param int[] $widths */ private function line(array $widths): string { @@ -124,8 +99,8 @@ private function line(array $widths): string /** * Paints full row line * - * @param list $row - * @param list $widths + * @param array $row + * @param int[] $widths */ private function rowLine(array $row, array $widths): string { @@ -134,14 +109,15 @@ private function rowLine(array $row, array $widths): string foreach ($widths as $columnKey => $width) { $value = $row[$columnKey] ?? ''; - $align = $this->align[$columnKey] ?? ColumnAlign::LEFT; - $result .= ' ' . $this->padVisible($value, $width, $align) . ' |'; + $columnAlign = $this->columnsAlign[$columnKey] ?? ColumnAlign::LEFT; + $result .= ' ' . $this->padVisible($value, $width, $columnAlign) . ' '; } - return $result; + // remove last trailing space + return rtrim($result); } - private function strlenVisible(string|Stringable $contents): int + private function strlenVisible(string|int|null|TableCell $contents): int { $string = (string) preg_replace('#\e\[[0-9;]*[A-Za-z]#', '', (string) $contents); @@ -155,7 +131,7 @@ private function strlenVisible(string|Stringable $contents): int /** * @param ColumnAlign::* $columnAllign */ - private function padVisible(string|TableCell $content, int $width, string $columnAllign): string + private function padVisible(string|int|null|TableCell $content, int $width, string $columnAllign): string { $length = $this->strlenVisible($content); diff --git a/tests/Entropy/ConsoleTableTest.php b/tests/Entropy/ConsoleTableTest.php index d3e882c..3b2e492 100644 --- a/tests/Entropy/ConsoleTableTest.php +++ b/tests/Entropy/ConsoleTableTest.php @@ -19,9 +19,9 @@ public function testBasic(): void $this->assertSame( <<assertSame( <<