Skip to content

Commit f4fb197

Browse files
committed
migrate to entropy/console
1 parent 41f884d commit f4fb197

File tree

5 files changed

+27
-54
lines changed

5 files changed

+27
-54
lines changed

composer-dependency-analyser.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@
66

77
return (new Configuration())
88
// conditional use
9-
->ignoreErrorsOnExtension('ext-mbstring', [\ShipMonk\ComposerDependencyAnalyser\Config\ErrorType::SHADOW_DEPENDENCY]);
9+
->ignoreErrorsOnExtension(
10+
'ext-mbstring',
11+
[\ShipMonk\ComposerDependencyAnalyser\Config\ErrorType::SHADOW_DEPENDENCY]
12+
);

composer.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@
1010
"composer/semver": "^3.4",
1111
"entropy/entropy": "dev-main",
1212
"nette/neon": "^3.4",
13-
"symfony/filesystem": "^7.4|8.0.*",
14-
"symfony/finder": "^7.4|8.0.*",
15-
"symfony/process": "^7.4|8.0.*",
16-
"webmozart/assert": "^1.12|^2.0"
13+
"symfony/finder": "^7.4",
14+
"symfony/process": "^7.4",
15+
"webmozart/assert": "^1.12"
1716
},
1817
"require-dev": {
1918
"phpecs/phpecs": "^2.3",

phpstan.neon

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,3 @@ parameters:
2121
# part of entropy magic contract
2222
- '#Public method "Rector\\(.*?)Command\:\:run\(\)" is never used#'
2323

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

src/Config/ConfigInitializer.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,26 @@
55
namespace Rector\Monitor\Config;
66

77
use Entropy\Console\Output\OutputPrinter;
8-
use Symfony\Component\Filesystem\Filesystem;
8+
use Entropy\Utils\FileSystem;
99

1010
final readonly class ConfigInitializer
1111
{
1212
public function __construct(
1313
private OutputPrinter $outputPrinter,
14-
private Filesystem $filesystem,
1514
) {
1615
}
1716

1817
public function createConfigIfMissing(string $projectDirectory): bool
1918
{
20-
if ($this->filesystem->exists($projectDirectory . '/monitor.php')) {
19+
if (file_exists($projectDirectory . '/monitor.php')) {
2120
// nothing to worry about
2221
return false;
2322
}
2423

25-
$templateFileContents = $this->filesystem->readFile(__DIR__ . '/../../templates/monitor.php.dist');
24+
$templateFileContents = FileSystem::read(__DIR__ . '/../../templates/monitor.php.dist');
2625

2726
// create the ecs.php file
28-
$this->filesystem->dumpFile(getcwd() . '/monitor.php', $templateFileContents);
27+
\Entropy\Utils\FileSystem::write(getcwd() . '/monitor.php', $templateFileContents);
2928
$this->outputPrinter->greenBackground(
3029
'The monitor.php config was generated! Fill your repositories details and re-run the command again'
3130
);

src/Entropy/ConsoleTable.php

Lines changed: 16 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,58 +9,33 @@
99
use Entropy\Attributes\RelatedTest;
1010
use Rector\Monitor\Entropy\Enum\ColumnAlign;
1111
use Rector\Monitor\Tests\Entropy\ConsoleTableTest;
12-
use Stringable;
1312
use Webmozart\Assert\Assert;
1413

1514
#[RelatedTest(testClass: ConsoleTableTest::class)]
1615
final class ConsoleTable
1716
{
18-
/**
19-
* @var list<string>
20-
*/
21-
private readonly array $headers;
22-
23-
/**
24-
* @var list<list<string>>
25-
*/
26-
private array $rows = [];
27-
28-
/**
29-
* @var list<'left'|'right'|'center'>
30-
*/
31-
private array $align;
32-
3317
/**
3418
* @param string[] $headers
35-
* @param array<array<string|int|float|TableCell|null>> $rows
36-
* @param array<'left'|'right'|'center'> $columnsAlign
19+
* @param array<array<string|int|TableCell|null>> $rows
20+
* @param array<int, ColumnAlign::*> $columnsAlign
3721
*/
38-
public function __construct(array $headers, array $rows, array $columnsAlign = [])
39-
{
22+
public function __construct(
23+
private array $headers,
24+
private array $rows,
25+
private array $columnsAlign = []
26+
) {
4027
Assert::notEmpty($headers);
4128
Assert::allString($headers);
4229

4330
// nested arrays
4431
Assert::notEmpty($rows);
4532
Assert::allIsArray($rows);
46-
47-
$this->headers = array_values($headers);
48-
foreach ($rows as $row) {
49-
$this->rows[] = array_values(
50-
array_map(
51-
static fn (float|int|TableCell|string|null $value): string => $value === null ? '' : (string) $value,
52-
$row
53-
)
54-
);
55-
}
56-
57-
$this->align = array_values($columnsAlign);
5833
}
5934

6035
public function render(): string
6136
{
62-
$cols = max(count($this->headers), $this->maxRowColumns());
63-
$columnWidths = array_fill(0, $cols, 0);
37+
$columns = max(count($this->headers), $this->maxRowColumns());
38+
$columnWidths = array_fill(0, $columns, 0);
6439

6540
// headers
6641
foreach ($this->headers as $columId => $header) {
@@ -108,7 +83,7 @@ private function maxRowColumns(): int
10883
}
10984

11085
/**
111-
* @param list<int> $widths
86+
* @param int[] $widths
11287
*/
11388
private function line(array $widths): string
11489
{
@@ -124,8 +99,8 @@ private function line(array $widths): string
12499
/**
125100
* Paints full row line
126101
*
127-
* @param list<string|TableCell> $row
128-
* @param list<int> $widths
102+
* @param array<string|int|null|TableCell> $row
103+
* @param int[] $widths
129104
*/
130105
private function rowLine(array $row, array $widths): string
131106
{
@@ -134,14 +109,14 @@ private function rowLine(array $row, array $widths): string
134109
foreach ($widths as $columnKey => $width) {
135110
$value = $row[$columnKey] ?? '';
136111

137-
$align = $this->align[$columnKey] ?? ColumnAlign::LEFT;
138-
$result .= ' ' . $this->padVisible($value, $width, $align) . ' |';
112+
$columnAlign = $this->columnsAlign[$columnKey] ?? ColumnAlign::LEFT;
113+
$result .= ' ' . $this->padVisible($value, $width, $columnAlign) . ' ';
139114
}
140115

141116
return $result;
142117
}
143118

144-
private function strlenVisible(string|Stringable $contents): int
119+
private function strlenVisible(string|int|null|TableCell $contents): int
145120
{
146121
$string = (string) preg_replace('#\e\[[0-9;]*[A-Za-z]#', '', (string) $contents);
147122

@@ -155,7 +130,7 @@ private function strlenVisible(string|Stringable $contents): int
155130
/**
156131
* @param ColumnAlign::* $columnAllign
157132
*/
158-
private function padVisible(string|TableCell $content, int $width, string $columnAllign): string
133+
private function padVisible(string|int|null|TableCell $content, int $width, string $columnAllign): string
159134
{
160135
$length = $this->strlenVisible($content);
161136

0 commit comments

Comments
 (0)