Skip to content

Commit b147d85

Browse files
committed
refactor: complete composer-command migration and cleanup for dev-tools
1 parent 5d4ee02 commit b147d85

51 files changed

Lines changed: 259 additions & 541 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

bin/dev-tools.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,10 @@
2020
namespace FastForward\DevTools;
2121

2222
use FastForward\DevTools\Console\DevTools;
23-
use FastForward\DevTools\Console\DevToolsComposer;
24-
use Symfony\Component\Console\Input\ArgvInput;
2523

2624
$projectVendorAutoload = \dirname(__DIR__, 4) . '/vendor/autoload.php';
2725
$pluginVendorAutoload = \dirname(__DIR__) . '/vendor/autoload.php';
2826

2927
require_once file_exists($projectVendorAutoload) ? $projectVendorAutoload : $pluginVendorAutoload;
3028

31-
$input = new ArgvInput([...$argv, '--no-plugins']);
32-
33-
$command = $input->getFirstArgument();
34-
$application = (null !== $command && DevTools::create()->has($command))
35-
? DevTools::create()
36-
: DevToolsComposer::create();
37-
38-
$application->run($input);
29+
DevTools::create()->run();

docs/commands/funding.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Options
3333

3434
``--composer-file`` (optional)
3535
Path to the Composer manifest to synchronize. Default:
36-
``Factory::getComposerFile()``.
36+
``composer.json``.
3737

3838
``--funding-file`` (optional)
3939
Path to the GitHub funding file to synchronize. Default:

src/Composer/Capability/DevToolsCommandProvider.php

Lines changed: 5 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@
2121

2222
use Composer\Command\BaseCommand;
2323
use Composer\Plugin\Capability\CommandProvider;
24-
use FastForward\DevTools\Console\Command\ProxyCommand;
24+
use FastForward\DevTools\Composer\Command\ProxyCommand;
2525
use FastForward\DevTools\Console\DevTools;
26-
use FastForward\DevTools\Console\DevToolsComposer;
2726
use Symfony\Component\Console\Command\Command;
2827

2928
/**
@@ -37,76 +36,9 @@ final class DevToolsCommandProvider implements CommandProvider
3736
*/
3837
public function getCommands()
3938
{
40-
$legacyCommands = DevToolsComposer::create()->all();
41-
$reservedCommandNames = $this->collectCommandNames($legacyCommands);
42-
$migratedCommands = DevTools::create()->all();
43-
44-
$commands = $legacyCommands;
45-
46-
foreach ($migratedCommands as $command) {
47-
if (! $command instanceof Command || $command instanceof BaseCommand) {
48-
continue;
49-
}
50-
51-
if ($this->hasReservedName($command, $reservedCommandNames)) {
52-
continue;
53-
}
54-
55-
$commands[] = new ProxyCommand($command);
56-
}
57-
58-
return array_values(array_filter(
59-
$commands,
60-
static fn(object $command): bool => $command instanceof BaseCommand,
61-
));
62-
}
63-
64-
/**
65-
* Collects command names and aliases that must remain mapped to legacy commands.
66-
*
67-
* @param array<int, BaseCommand> $commands
68-
*
69-
* @return array<string, true>
70-
*/
71-
private function collectCommandNames(array $commands): array
72-
{
73-
$commandNames = [];
74-
75-
foreach ($commands as $command) {
76-
if (! $command instanceof BaseCommand) {
77-
continue;
78-
}
79-
80-
if (null !== $command->getName()) {
81-
$commandNames[$command->getName()] = true;
82-
}
83-
84-
foreach ($command->getAliases() as $alias) {
85-
$commandNames[$alias] = true;
86-
}
87-
}
88-
89-
return $commandNames;
90-
}
91-
92-
/**
93-
* Verifies whether the command name or any aliases collide with legacy command names.
94-
*
95-
* @param Command $command
96-
* @param array<string, true> $reservedCommandNames
97-
*/
98-
private function hasReservedName(Command $command, array $reservedCommandNames): bool
99-
{
100-
if (null !== $command->getName() && isset($reservedCommandNames[$command->getName()])) {
101-
return true;
102-
}
103-
104-
foreach ($command->getAliases() as $alias) {
105-
if (isset($reservedCommandNames[$alias])) {
106-
return true;
107-
}
108-
}
109-
110-
return false;
39+
return array_map(
40+
static fn(Command $command): BaseCommand => new ProxyCommand($command),
41+
DevTools::create()->all(),
42+
);
11143
}
11244
}
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* @see https://datatracker.ietf.org/doc/html/rfc2119
1818
*/
1919

20-
namespace FastForward\DevTools\Console\Command;
20+
namespace FastForward\DevTools\Composer\Command;
2121

2222
use Composer\Command\BaseCommand;
2323
use Symfony\Component\Console\Command\Command;
@@ -29,17 +29,20 @@
2929
*/
3030
final class ProxyCommand extends BaseCommand
3131
{
32+
/**
33+
* @param Command $command the Symfony command adapted for Composer plugin execution
34+
*/
3235
public function __construct(
3336
private readonly Command $command,
3437
) {
35-
parent::__construct($command->getName());
36-
37-
$this->setAliases($command->getAliases());
38-
$this->setDescription($command->getDescription());
39-
$this->setHelp($command->getHelp());
40-
$this->setDefinition(clone $command->getDefinition());
41-
$this->setHidden($command->isHidden());
42-
$this->setIgnoreValidationErrors($command->ignoreValidationErrors());
38+
parent::__construct($this->command->getName());
39+
40+
$this
41+
->setAliases($this->command->getAliases())
42+
->setDescription($this->command->getDescription())
43+
->setHelp($this->command->getHelp())
44+
->setDefinition(clone $this->command->getDefinition())
45+
->setHidden($this->command->isHidden());
4346
}
4447

4548
/**
@@ -50,9 +53,6 @@ public function __construct(
5053
*/
5154
protected function execute(InputInterface $input, OutputInterface $output): int
5255
{
53-
$this->command->setApplication($this->getApplication());
54-
$this->command->setHelperSet($this->getHelperSet());
55-
5656
return $this->command->run($input, $output);
5757
}
5858
}

src/Composer/Json/ComposerJson.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
use FastForward\DevTools\Composer\Json\Schema\SupportInterface;
3030
use FastForward\DevTools\Path\WorkingProjectPathResolver;
3131
use UnderflowException;
32+
33+
use function Safe\file_get_contents;
3234
use function Safe\json_decode;
3335

3436
/**
@@ -592,9 +594,7 @@ public function getComments(): array
592594
private function readComposerJsonFile(string $path): array
593595
{
594596
if (! file_exists($path)) {
595-
throw new RuntimeException(
596-
\sprintf('Unable to read composer manifest file at path: %s', $path),
597-
);
597+
throw new RuntimeException(\sprintf('Unable to read composer manifest file at path: %s', $path));
598598
}
599599

600600
return $this->decodeJson($path);
@@ -628,9 +628,7 @@ private function decodeJson(string $path): array
628628
$contents = file_get_contents($path);
629629

630630
if (false === $contents) {
631-
throw new RuntimeException(
632-
\sprintf('Unable to read composer manifest file at path: %s', $path),
633-
);
631+
throw new RuntimeException(\sprintf('Unable to read composer manifest file at path: %s', $path));
634632
}
635633

636634
$data = json_decode($contents, true, 512, \JSON_THROW_ON_ERROR);

src/Console/Command/AgentsCommand.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9898
$this->logger->info('Created .agents/agents directory.');
9999
}
100100

101-
$this->synchronizer->setLogger($this->logger);
102-
103101
$result = $this->synchronizer->synchronize($agentsDir, $packageAgentsPath, self::AGENTS_DIRECTORY);
104102

105103
if ($result->failed()) {

src/Console/Command/ChangelogCheckCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
namespace FastForward\DevTools\Console\Command;
2121

2222
use FastForward\DevTools\Console\Command\Traits\LogsCommandResults;
23-
use Composer\Command\BaseCommand;
2423
use FastForward\DevTools\Changelog\Checker\UnreleasedEntryCheckerInterface;
2524
use FastForward\DevTools\Console\Input\HasJsonOption;
2625
use FastForward\DevTools\Filesystem\FilesystemInterface;
2726
use Psr\Log\LoggerInterface;
2827
use Symfony\Component\Console\Attribute\AsCommand;
28+
use Symfony\Component\Console\Command\Command;
2929
use Symfony\Component\Console\Input\InputInterface;
3030
use Symfony\Component\Console\Input\InputOption;
3131
use Symfony\Component\Console\Output\OutputInterface;
@@ -37,7 +37,7 @@
3737
name: 'changelog:check',
3838
description: 'Checks whether a changelog file contains meaningful unreleased entries.'
3939
)]
40-
final class ChangelogCheckCommand extends BaseCommand implements LoggerAwareCommandInterface
40+
final class ChangelogCheckCommand extends Command implements LoggerAwareCommandInterface
4141
{
4242
use HasJsonOption;
4343
use LogsCommandResults;

src/Console/Command/ChangelogEntryCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020
namespace FastForward\DevTools\Console\Command;
2121

2222
use FastForward\DevTools\Console\Command\Traits\LogsCommandResults;
23-
use Composer\Command\BaseCommand;
2423
use FastForward\DevTools\Changelog\Document\ChangelogDocument;
2524
use FastForward\DevTools\Changelog\Entry\ChangelogEntryType;
2625
use FastForward\DevTools\Changelog\Manager\ChangelogManagerInterface;
2726
use FastForward\DevTools\Console\Input\HasJsonOption;
2827
use FastForward\DevTools\Filesystem\FilesystemInterface;
2928
use Psr\Log\LoggerInterface;
3029
use Symfony\Component\Console\Attribute\AsCommand;
30+
use Symfony\Component\Console\Command\Command;
3131
use Symfony\Component\Console\Input\InputArgument;
3232
use Symfony\Component\Console\Input\InputInterface;
3333
use Symfony\Component\Console\Input\InputOption;
@@ -40,7 +40,7 @@
4040
name: 'changelog:entry',
4141
description: 'Adds a changelog entry to Unreleased or a specific version section.'
4242
)]
43-
final class ChangelogEntryCommand extends BaseCommand implements LoggerAwareCommandInterface
43+
final class ChangelogEntryCommand extends Command implements LoggerAwareCommandInterface
4444
{
4545
use HasJsonOption;
4646
use LogsCommandResults;

src/Console/Command/ChangelogNextVersionCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121

2222
use FastForward\DevTools\Console\Command\Traits\LogsCommandResults;
2323
use Throwable;
24-
use Composer\Command\BaseCommand;
2524
use FastForward\DevTools\Changelog\Manager\ChangelogManagerInterface;
2625
use FastForward\DevTools\Console\Input\HasJsonOption;
2726
use FastForward\DevTools\Filesystem\FilesystemInterface;
2827
use Psr\Log\LoggerInterface;
2928
use Symfony\Component\Console\Attribute\AsCommand;
29+
use Symfony\Component\Console\Command\Command;
3030
use Symfony\Component\Console\Input\InputInterface;
3131
use Symfony\Component\Console\Input\InputOption;
3232
use Symfony\Component\Console\Output\OutputInterface;
@@ -38,7 +38,7 @@
3838
name: 'changelog:next-version',
3939
description: 'Infers the next semantic version from the Unreleased changelog section.'
4040
)]
41-
final class ChangelogNextVersionCommand extends BaseCommand implements LoggerAwareCommandInterface
41+
final class ChangelogNextVersionCommand extends Command implements LoggerAwareCommandInterface
4242
{
4343
use HasJsonOption;
4444
use LogsCommandResults;

src/Console/Command/ChangelogPromoteCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121

2222
use FastForward\DevTools\Console\Command\Traits\LogsCommandResults;
2323
use Throwable;
24-
use Composer\Command\BaseCommand;
2524
use FastForward\DevTools\Changelog\Manager\ChangelogManagerInterface;
2625
use FastForward\DevTools\Console\Input\HasJsonOption;
2726
use FastForward\DevTools\Filesystem\FilesystemInterface;
2827
use Psr\Clock\ClockInterface;
2928
use Psr\Log\LoggerInterface;
3029
use Symfony\Component\Console\Attribute\AsCommand;
30+
use Symfony\Component\Console\Command\Command;
3131
use Symfony\Component\Console\Input\InputArgument;
3232
use Symfony\Component\Console\Input\InputInterface;
3333
use Symfony\Component\Console\Input\InputOption;
@@ -40,7 +40,7 @@
4040
name: 'changelog:promote',
4141
description: 'Promotes Unreleased entries into a published changelog version.'
4242
)]
43-
final class ChangelogPromoteCommand extends BaseCommand implements LoggerAwareCommandInterface
43+
final class ChangelogPromoteCommand extends Command implements LoggerAwareCommandInterface
4444
{
4545
use HasJsonOption;
4646
use LogsCommandResults;

0 commit comments

Comments
 (0)