Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[make:*] use sorted use statements #1106

Merged
merged 21 commits into from
May 3, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[make:message] use sorted use statements
  • Loading branch information
jrushlow committed Apr 26, 2022
commit 56fefafea399bc2f6eed8d66bda82abcb377b5d7
19 changes: 13 additions & 6 deletions src/Maker/MakeMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
use Symfony\Bundle\MakerBundle\FileManager;
use Symfony\Bundle\MakerBundle\Generator;
use Symfony\Bundle\MakerBundle\InputConfiguration;
use Symfony\Bundle\MakerBundle\Util\TemplateComponentGenerator;
use Symfony\Bundle\MakerBundle\Util\YamlSourceManipulator;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
use Symfony\Component\Messenger\MessageBusInterface;

/**
Expand Down Expand Up @@ -47,15 +49,15 @@ public static function getCommandDescription(): string
return 'Creates a new message and handler';
}

public function configureCommand(Command $command, InputConfiguration $inputConf)
public function configureCommand(Command $command, InputConfiguration $inputConfig): void
{
$command
->addArgument('name', InputArgument::OPTIONAL, 'The name of the message class (e.g. <fg=yellow>SendEmailMessage</>)')
->setHelp(file_get_contents(__DIR__.'/../Resources/help/MakeMessage.txt'))
;
}

public function interact(InputInterface $input, ConsoleStyle $io, Command $command)
public function interact(InputInterface $input, ConsoleStyle $io, Command $command): void
{
$command->addArgument('chosen-transport', InputArgument::OPTIONAL);

Expand Down Expand Up @@ -83,7 +85,7 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma
}
}

public function generate(InputInterface $input, ConsoleStyle $io, Generator $generator)
public function generate(InputInterface $input, ConsoleStyle $io, Generator $generator): void
{
$messageClassNameDetails = $generator->createClassNameDetails(
$input->getArgument('name'),
Expand All @@ -101,11 +103,16 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
'message/Message.tpl.php'
);

$useStatements = [
MessageHandlerInterface::class,
$messageClassNameDetails->getFullName(),
];

$generator->generateClass(
$handlerClassNameDetails->getFullName(),
'message/MessageHandler.tpl.php',
[
'message_full_class_name' => $messageClassNameDetails->getFullName(),
'use_statements' => TemplateComponentGenerator::generateUseStatements($useStatements),
'message_class_name' => $messageClassNameDetails->getShortName(),
]
);
Expand All @@ -125,7 +132,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
]);
}

private function updateMessengerConfig(Generator $generator, string $chosenTransport, string $messageClass)
private function updateMessengerConfig(Generator $generator, string $chosenTransport, string $messageClass): void
{
$manipulator = new YamlSourceManipulator($this->fileManager->getFileContents($configFilePath = 'config/packages/messenger.yaml'));
$messengerData = $manipulator->getData();
Expand All @@ -140,7 +147,7 @@ private function updateMessengerConfig(Generator $generator, string $chosenTrans
$generator->dumpFile($configFilePath, $manipulator->getContents());
}

public function configureDependencies(DependencyBuilder $dependencies)
public function configureDependencies(DependencyBuilder $dependencies): void
{
$dependencies->addClassDependency(
MessageBusInterface::class,
Expand Down
3 changes: 1 addition & 2 deletions src/Resources/skeleton/message/MessageHandler.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

namespace <?= $namespace; ?>;

use <?= $message_full_class_name ?>;
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
<?= $use_statements; ?>

final class <?= $class_name ?> implements MessageHandlerInterface
{
Expand Down