Skip to content

Commit

Permalink
Update ConsoleExtension.php
Browse files Browse the repository at this point in the history
Lazy loading using the service tag does not work.
  • Loading branch information
janzarubadek authored Jan 4, 2024
1 parent e52267a commit ea29068
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions src/DI/ConsoleExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,27 @@ public function beforeCompile(): void

// Iterate over all commands and build commandMap
foreach ($commands as $serviceName => $service) {
$commandName = call_user_func([$service->getType(), 'getDefaultName']); // @phpstan-ignore-line

if ($commandName === null) {
throw new ServiceCreationException(
sprintf(
'Command "%s" missing #[AsCommand] attribute',
$service->getType(),
)
);
$tags = $service->getTags();
$commandDef = $tags['console.command'] ?? null;
$commandName = null;
if ($commandDef !== null) {

Check failure on line 150 in src/DI/ConsoleExtension.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.2)

Expected 1 line after "if", found 0.
if (is_string($commandDef)) {
$commandName = $commandDef;
} elseif (is_array($commandDef)) {
$commandName = Arrays::get($tags['console.command'], 'name', null);

Check failure on line 154 in src/DI/ConsoleExtension.php

View workflow job for this annotation

GitHub Actions / Phpstan / Phpstan (8.2)

Call to static method get() on an unknown class Contributte\Console\DI\Arrays.

Check warning on line 154 in src/DI/ConsoleExtension.php

View check run for this annotation

Codecov / codecov/patch

src/DI/ConsoleExtension.php#L151-L154

Added lines #L151 - L154 were not covered by tests
}
} else {
$commandName = call_user_func([$service->getType(), 'getDefaultName']); // @phpstan-ignore-line

if ($commandName === null) {
throw new ServiceCreationException(
sprintf(
'Command "%s" missing #[AsCommand] attribute',
$service->getType(),
)
);
}
}

// Append service to command map
$commandMap[$commandName] = $serviceName;
}
Expand Down

0 comments on commit ea29068

Please sign in to comment.