2121
2222use Composer \Command \BaseCommand ;
2323use Composer \Plugin \Capability \CommandProvider ;
24- use FastForward \DevTools \Console \Command \ProxyCommand ;
24+ use FastForward \DevTools \Composer \Command \ProxyCommand ;
2525use FastForward \DevTools \Console \DevTools ;
26- use FastForward \DevTools \Console \DevToolsComposer ;
2726use 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}
0 commit comments