Skip to content

Commit 96f1b03

Browse files
committed
refactor: apply Rector modernizations + cs:fix followup
Applied by: vendor/bin/rector process --config=.kcode/rector.php src/Command/AbstractCommand.php - ForeachToArrayAnyRector: foreach over flags replaced by array_any() - AddArrowFunctionReturnTypeRector: arrow function return type added src/Command/InitCommand.php - FunctionLikeToFirstClassCallableRector - Inlined MigrationDetector import; removed unused $context param from scaffoldDevkitConfig() call src/Configuration/CsFixerConfigGenerator.php - FunctionLikeToFirstClassCallableRector src/Core/DevkitConfig.php - Rector modernization (type/return refinement) src/Core/ProjectContext.php - Rector modernization Followed by cs:fix to normalize style (trailing commas, spacing). All checks passing: PHPStan L9 0 errors, Psalm 0 errors, 41/41 tests.
1 parent 8ef9a93 commit 96f1b03

5 files changed

Lines changed: 11 additions & 17 deletions

File tree

src/Command/AbstractCommand.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,7 @@ protected function confirm(string $question, bool $default = false): bool
8181
/** @param list<string> $arguments */
8282
protected function hasFlag(array $arguments, string ...$flags): bool
8383
{
84-
foreach ($flags as $flag) {
85-
if (\in_array($flag, $arguments, true)) {
86-
return true;
87-
}
88-
}
89-
90-
return false;
84+
return array_any($flags, fn ($flag): bool => \in_array($flag, $arguments, true));
9185
}
9286

9387
/**

src/Command/InitCommand.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace KaririCode\Devkit\Command;
66

77
use KaririCode\Devkit\Core\Devkit;
8+
use KaririCode\Devkit\Core\MigrationDetector;
89

910
/**
1011
* Generates all config files inside `.kcode/`.
@@ -45,11 +46,11 @@ public function execute(Devkit $devkit, array $arguments): int
4546

4647
// Scaffold devkit.php if requested
4748
if ($this->hasFlag($arguments, '--config')) {
48-
$this->scaffoldDevkitConfig($context->projectRoot, $context);
49+
$this->scaffoldDevkitConfig($context->projectRoot);
4950
}
5051

5152
// Hint: detect redundant root-level configs and dev dependencies
52-
$detector = new \KaririCode\Devkit\Core\MigrationDetector();
53+
$detector = new MigrationDetector();
5354
$migration = $detector->detect($context->projectRoot);
5455

5556
if ($migration->hasRedundancies) {
@@ -64,7 +65,7 @@ public function execute(Devkit $devkit, array $arguments): int
6465
return 0;
6566
}
6667

67-
private function scaffoldDevkitConfig(string $projectRoot, \KaririCode\Devkit\Core\ProjectContext $context): void
68+
private function scaffoldDevkitConfig(string $projectRoot): void
6869
{
6970
$configPath = $projectRoot . \DIRECTORY_SEPARATOR . 'devkit.php';
7071

@@ -74,7 +75,7 @@ private function scaffoldDevkitConfig(string $projectRoot, \KaririCode\Devkit\Co
7475
return;
7576
}
7677

77-
$content = <<<'PHP'
78+
$content = <<<'PHP_WRAP'
7879
<?php
7980
8081
declare(strict_types=1);
@@ -146,7 +147,7 @@ private function scaffoldDevkitConfig(string $projectRoot, \KaririCode\Devkit\Co
146147
// 'psalm' => '^6.0',
147148
// ],
148149
];
149-
PHP;
150+
PHP_WRAP;
150151

151152
file_put_contents($configPath, $content . \PHP_EOL);
152153

src/Configuration/CsFixerConfigGenerator.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ private function exportRules(array $rules): string
7878
$export = (string) preg_replace('/^array \($/m', '[', $export);
7979
$export = (string) preg_replace('/^\)$/m', ']', $export);
8080
$export = str_replace('array (', '[', $export);
81-
$export = str_replace(')', ']', $export);
8281

83-
return $export;
82+
return str_replace(')', ']', $export);
8483
}
8584
}

src/Core/DevkitConfig.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public function toolVersions(): array
117117
/** @var array<string, string> $typed */
118118
$typed = array_filter(
119119
$tools,
120-
static fn (mixed $v): bool => \is_string($v),
120+
\is_string(...),
121121
);
122122

123123
return $typed;

src/Core/ProjectContext.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ public function buildPath(string $filename = ''): string
6262
/** @return list<string> Convert absolute source dirs to project-relative paths. */
6363
public function relativeSourceDirs(): array
6464
{
65-
return array_map(fn (string $dir): string => $this->relativize($dir), $this->sourceDirs);
65+
return array_map($this->relativize(...), $this->sourceDirs);
6666
}
6767

6868
/** @return list<string> Convert absolute test dirs to project-relative paths. */
6969
public function relativeTestDirs(): array
7070
{
71-
return array_map(fn (string $dir): string => $this->relativize($dir), $this->testDirs);
71+
return array_map($this->relativize(...), $this->testDirs);
7272
}
7373

7474
public function relativize(string $absolutePath): string

0 commit comments

Comments
 (0)