Skip to content

Commit

Permalink
CS Fixer
Browse files Browse the repository at this point in the history
  • Loading branch information
maelanleborgne committed Mar 25, 2024
1 parent 31a06c0 commit 7889de5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
17 changes: 7 additions & 10 deletions src/Maker/MakeWebhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
*/
final class MakeWebhook extends AbstractMaker implements InputAwareMakerInterface
{

private const WEBHOOK_CONFIG_PATH = 'config/packages/webhook.yaml';
private YamlSourceManipulator $ysm;

Expand All @@ -77,8 +76,8 @@ public static function getCommandDescription(): string
public function configureCommand(Command $command, InputConfiguration $inputConfig): void
{
$command
->addArgument('name', InputArgument::OPTIONAL, sprintf('Name of the webhook to create (e.g. <fg=yellow>github, stripe, ...</>)'))
->setHelp(file_get_contents(__DIR__ . '/../Resources/help/MakeWebhook.txt'))
->addArgument('name', InputArgument::OPTIONAL, 'Name of the webhook to create (e.g. <fg=yellow>github, stripe, ...</>)')
->setHelp(file_get_contents(__DIR__.'/../Resources/help/MakeWebhook.txt'))
;

$inputConfig->setArgumentAsNonInteractive('name');
Expand Down Expand Up @@ -132,11 +131,11 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
{
$webhookName = $input->getArgument('name');
$requestParserDetails = $this->generator->createClassNameDetails(
Str::asClassName($webhookName . 'RequestParser'),
Str::asClassName($webhookName.'RequestParser'),
'Webhook\\'
);
$remoteEventHandlerDetails = $this->generator->createClassNameDetails(
Str::asClassName($webhookName . 'WebhookHandler'),
Str::asClassName($webhookName.'WebhookHandler'),
'RemoteEvent\\'
);

Expand Down Expand Up @@ -165,7 +164,7 @@ private function addToYamlConfig(string $webhookName, ClassNameDetails $requestP
}
$this->ysm = new YamlSourceManipulator($yamlConfig);
$arrayConfig = $this->ysm->getData();
if (key_exists($webhookName, $arrayConfig['framework']['webhook']['routing'] ?? [])) {
if (\array_key_exists($webhookName, $arrayConfig['framework']['webhook']['routing'] ?? [])) {
throw new \InvalidArgumentException('A webhook with this name already exists');
}

Expand All @@ -179,9 +178,6 @@ private function addToYamlConfig(string $webhookName, ClassNameDetails $requestP
}

/**
* @param ConsoleStyle $io
* @param ClassNameDetails $requestParserDetails
* @return void
* @throws \Exception
*/
public function generateRequestParser(ConsoleStyle $io, ClassNameDetails $requestParserDetails): void
Expand Down Expand Up @@ -234,7 +230,7 @@ public function generateRequestParser(ConsoleStyle $io, ClassNameDetails $reques
);
}

private function askForNextRequestMatcher(ConsoleStyle $io, array $addedMatchers, string $entityClass, bool $isFirstMatcher): string|null
private function askForNextRequestMatcher(ConsoleStyle $io, array $addedMatchers, string $entityClass, bool $isFirstMatcher): ?string
{
$io->writeln('');
$availableMatchers = $this->getAvailableRequestMatchers();
Expand All @@ -253,6 +249,7 @@ private function askForNextRequestMatcher(ConsoleStyle $io, array $addedMatchers
return null;
}
}

return $matcherName;
}

Expand Down
21 changes: 10 additions & 11 deletions tests/Maker/MakeWebhookTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,11 @@ public function getTestDetails(): \Generator
);
$this->assertStringContainsString(
<<<EOF
return new ChainRequestMatcher([
new IsJsonRequestMatcher(),
new PortRequestMatcher(443),
]);
EOF,
return new ChainRequestMatcher([
new IsJsonRequestMatcher(),
new PortRequestMatcher(443),
]);
EOF,
$requestParserSource
);
}),
Expand All @@ -156,7 +156,6 @@ public function getTestDetails(): \Generator
yield 'it_makes_webhook_with_expression_language_injection' => [$this->createMakerTest()
->addExtraDependencies('symfony/expression-language')
->run(function (MakerTestRunner $runner) {

$output = $runner->runMaker([
// webhook name
'remote_service',
Expand Down Expand Up @@ -190,11 +189,11 @@ public function getTestDetails(): \Generator
);
$this->assertStringContainsString(
<<<EOF
return new ChainRequestMatcher([
new IsJsonRequestMatcher(),
new ExpressionRequestMatcher(new ExpressionLanguage(), new Expression('expression')),
]);
EOF,
return new ChainRequestMatcher([
new IsJsonRequestMatcher(),
new ExpressionRequestMatcher(new ExpressionLanguage(), new Expression('expression')),
]);
EOF,
$requestParserSource
);
}),
Expand Down

0 comments on commit 7889de5

Please sign in to comment.