Skip to content

Commit

Permalink
Fix static checks (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
lruozzi9 committed Nov 27, 2023
1 parent b33d29e commit 60b2caf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Controller/WebhookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ public function postAction(Request $request): Response
return new Response('', Response::HTTP_UNAUTHORIZED);
}

/** @var string|resource $body on Symfony 5 the annotation is resource|string */

Check failure on line 85 in src/Controller/WebhookController.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.12, PHP 8.0, Symfony ^5.4, MySQL 8.0

UnnecessaryVarAnnotation

src/Controller/WebhookController.php:85:18: UnnecessaryVarAnnotation: The @var resource|string annotation for $body is unnecessary (see https://psalm.dev/212)

Check failure on line 85 in src/Controller/WebhookController.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.12, PHP 8.0, Symfony ^5.4, MySQL 8.0

UnnecessaryVarAnnotation

src/Controller/WebhookController.php:85:18: UnnecessaryVarAnnotation: The @var resource|string annotation for $body is unnecessary (see https://psalm.dev/212)
$body = $request->getContent();
$expectedSignature = hash_hmac('sha256', $timestamp . '.' . $body, $this->secret);
$expectedSignature = hash_hmac('sha256', $timestamp . '.' . (string) $body, $this->secret);
if (false === hash_equals($signature, $expectedSignature)) {
$this->logger->debug('The hash does not match! The request is not from Akeneo or the secret is wrong.');

Expand All @@ -100,7 +101,7 @@ public function postAction(Request $request): Response
*
* @var AkeneoEvents $akeneoEvents
*/
$akeneoEvents = json_decode($body, true, 512, JSON_THROW_ON_ERROR);
$akeneoEvents = json_decode((string) $body, true, 512, JSON_THROW_ON_ERROR);

foreach ($akeneoEvents['events'] as $akeneoEvent) {
$this->logger->debug(sprintf('Received event %s with id "%s"', $akeneoEvent['action'], $akeneoEvent['event_id']));
Expand Down
4 changes: 4 additions & 0 deletions src/DependencyInjection/WebgriffeSyliusAkeneoExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ final class WebgriffeSyliusAkeneoExtension extends AbstractResourceExtension imp

public function load(array $configs, ContainerBuilder $container): void
{
/** @var array{resources: array|mixed, api_client: array<array-key, ?string>, webhook: array{secret: ?string}, value_handlers: array} $config */
$config = $this->processConfiguration($this->getConfiguration([], $container), $configs);
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../../config'));

Expand Down Expand Up @@ -254,6 +255,9 @@ private function registerTemporaryDirectoryParameter(ContainerBuilder $container
$container->setParameter($parameterKey, sys_get_temp_dir());
}

/**
* @param array{secret: ?string} $webhook
*/
private function registerWebhookParameters(array $webhook, ContainerBuilder $container): void
{
$container->setParameter('webgriffe_sylius_akeneo.webhook.secret', $webhook['secret']);
Expand Down

0 comments on commit 60b2caf

Please sign in to comment.