Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer-dependency-analyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
7 changes: 3 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 0 additions & 3 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,3 @@ parameters:
# part of entropy magic contract
- '#Public method "Rector\\(.*?)Command\:\:run\(\)" is never used#'

# too detailed
- '#Parameter (.*?) expects list<int>, (.*?)<int<0, max>, int<0, max>> given#'

14 changes: 7 additions & 7 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
9 changes: 4 additions & 5 deletions src/Config/ConfigInitializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);
Expand Down
62 changes: 19 additions & 43 deletions src/Entropy/ConsoleTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>
*/
private readonly array $headers;

/**
* @var list<list<string>>
*/
private array $rows = [];

/**
* @var list<'left'|'right'|'center'>
*/
private array $align;

/**
* @param string[] $headers
* @param array<array<string|int|float|TableCell|null>> $rows
* @param array<'left'|'right'|'center'> $columnsAlign
* @param array<array<string|int|TableCell|null>> $rows
* @param array<int, ColumnAlign::*> $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) {
Expand Down Expand Up @@ -108,7 +83,7 @@ private function maxRowColumns(): int
}

/**
* @param list<int> $widths
* @param int[] $widths
*/
private function line(array $widths): string
{
Expand All @@ -124,8 +99,8 @@ private function line(array $widths): string
/**
* Paints full row line
*
* @param list<string|TableCell> $row
* @param list<int> $widths
* @param array<string|int|null|TableCell> $row
* @param int[] $widths
*/
private function rowLine(array $row, array $widths): string
{
Expand All @@ -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);

Expand All @@ -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);

Expand Down
8 changes: 4 additions & 4 deletions tests/Entropy/ConsoleTableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public function testBasic(): void
$this->assertSame(
<<<TABLE
--------------
\e[32mkey\e[0m | \e[32mvalue\e[0m |
\e[32mkey\e[0m \e[32mvalue\e[0m
--------------
1 | 2 |
1 2
--------------

TABLE
Expand All @@ -40,9 +40,9 @@ public function testColors(): void
$this->assertSame(
<<<TABLE
------------------
\e[32mkey\e[0m | \e[32mvalue\e[0m |
\e[32mkey\e[0m \e[32mvalue\e[0m
------------------
\e[31mcontent\e[0m | 2 |
\e[31mcontent\e[0m 2
------------------

TABLE
Expand Down