diff --git a/api/src/Command/TwitterApiRecentTweetsCommand.php b/api/src/Command/TwitterApiRecentTweetsCommand.php index edd92dd..f595d83 100644 --- a/api/src/Command/TwitterApiRecentTweetsCommand.php +++ b/api/src/Command/TwitterApiRecentTweetsCommand.php @@ -46,27 +46,26 @@ final class TwitterApiRecentTweetsCommand extends Command { private const DEFAULTS_TWEETS_REPLIES = [ - ['id' => 'on_new_game', 'reply' => 'Hey %nom% (%@username%), merci de participer à notre jeu ! ' . \PHP_EOL . 'Pour avoir plus d\'informations sur le jeu voici notre site web : %site_web%'], - ['id' => 'game_already_generated_less_than_a_day_ago', 'reply' => 'Merci %nom% (%@username%) de parler de nous.' . \PHP_EOL . 'Malheureusement tu as déjà joué il y a moins de 24h, tu pourras rejouer une fois que cela fera plus d\'une journée ! ' . \PHP_EOL . 'Pour plus d\'informations tu peux consulter notre site web : %site_web%'], - ['id' => 'need_to_follow_us', 'reply' => 'Merci %nom% (%@username%) de parler de nous. ' . \PHP_EOL . 'Malheureusement tu n\'es pas encore éligible pour pouvoir participer au jeu. Pour l\'être tu dois suivre les comptes nécessaires. ' . \PHP_EOL . 'Pour plus d\'informations tu peux consulter notre site web : %site_web%'], - ['id' => 'no_more_available_lots', 'reply' => 'Nous n\'avons malheureusement plus aucun lot de disponible... ' . \PHP_EOL . 'Retente ta chance un autre jour !'], + ['id' => 'on_new_game', 'reply' => 'Hey %nom% (%@username%), merci de participer à notre jeu ! '.\PHP_EOL.'Pour avoir plus d\'informations sur le jeu voici notre site web : %site_web%'], + ['id' => 'game_already_generated_less_than_a_day_ago', 'reply' => 'Merci %nom% (%@username%) de parler de nous.'.\PHP_EOL.'Malheureusement tu as déjà joué il y a moins de 24h, tu pourras rejouer une fois que cela fera plus d\'une journée ! '.\PHP_EOL.'Pour plus d\'informations tu peux consulter notre site web : %site_web%'], + ['id' => 'need_to_follow_us', 'reply' => 'Merci %nom% (%@username%) de parler de nous. '.\PHP_EOL.'Malheureusement tu n\'es pas encore éligible pour pouvoir participer au jeu. Pour l\'être tu dois suivre les comptes nécessaires. '.\PHP_EOL.'Pour plus d\'informations tu peux consulter notre site web : %site_web%'], + ['id' => 'no_more_available_lots', 'reply' => 'Nous n\'avons malheureusement plus aucun lot de disponible... '.\PHP_EOL.'Retente ta chance un autre jour !'], ]; public function __construct( - private readonly TwitterApi $twitterApi, - private readonly PlayerRepository $playerRepository, - private readonly TweetRepository $tweetRepository, - private readonly GameRepository $gameRepository, - private readonly LotRepository $lotRepository, - private readonly TweetReplyRepository $tweetReplyRepository, + private readonly TwitterApi $twitterApi, + private readonly PlayerRepository $playerRepository, + private readonly TweetRepository $tweetRepository, + private readonly GameRepository $gameRepository, + private readonly LotRepository $lotRepository, + private readonly TweetReplyRepository $tweetReplyRepository, private readonly TwitterAccountToFollowRepository $twitterAccountToFollowRepository, - private readonly TwitterHashtagRepository $twitterHashtagRepository, - private readonly string $communicationWebsiteUrl, - private readonly LoggerInterface $logger, - private readonly ValidatorInterface $validator, - private readonly MessageNormalizer $messageNormalizer - ) - { + private readonly TwitterHashtagRepository $twitterHashtagRepository, + private readonly string $communicationWebsiteUrl, + private readonly LoggerInterface $logger, + private readonly ValidatorInterface $validator, + private readonly MessageNormalizer $messageNormalizer + ) { parent::__construct(); } @@ -100,7 +99,7 @@ private function getTweetReplyMessage(string $id, string $name, string $userhand $params = [ 'nom' => $name, 'username' => $userhandle, - 'site_web' => $this->communicationWebsiteUrl + 'site_web' => $this->communicationWebsiteUrl, ]; return $this->messageNormalizer->normalize($message, $params); @@ -111,7 +110,7 @@ private function getTweetReplyMessage(string $id, string $name, string $userhand throw new TweetReplyNotFoundException(); } - return str_replace(['%nom%', '%@username%', '%site_web%'], [$name, '@' . $userhandle, $this->communicationWebsiteUrl], $message['reply']); + return str_replace(['%nom%', '%@username%', '%site_web%'], [$name, '@'.$userhandle, $this->communicationWebsiteUrl], $message['reply']); } /** @@ -156,7 +155,7 @@ private function setUser(object $tweets, object $tweet, int $index): ?object } } catch (BadRequestHttpException $e) { $this->logger->critical( - 'Twitter API get request (users/) error : ' . $e->getMessage(), + 'Twitter API get request (users/) error : '.$e->getMessage(), [ 'tweet' => $tweet, 'error' => $e, @@ -181,7 +180,7 @@ private function following(string $userId, array $accountsToFollow): bool } } catch (BadRequestHttpException $e) { $this->logger->critical( - 'Twitter API get request (friendships/show) error : ' . $e->getMessage(), + 'Twitter API get request (friendships/show) error : '.$e->getMessage(), [ 'error' => $e, ] @@ -210,7 +209,7 @@ private function newReply(string $message, string $tweetId): void $this->twitterApi->reply($message, $tweetId); } catch (BadRequestHttpException $e) { $this->logger->critical( - 'Twitter API post request (tweets) error : ' . $e->getMessage(), + 'Twitter API post request (tweets) error : '.$e->getMessage(), [ 'error' => $e, ] @@ -233,7 +232,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $databaseUpdated = false; $this->logger->notice( - 'Command state: update-db: ' . $input->getOption('update-db') . ', reply: ' . $input->getOption('reply'), + 'Command state: update-db: '.$input->getOption('update-db').', reply: '.$input->getOption('reply'), [ 'Active hashtags for command' => $hashtags, 'Active Twitter accounts to follow for command' => $accountsToFollow, @@ -259,26 +258,26 @@ protected function execute(InputInterface $input, OutputInterface $output): int $tweets = $this->getRecentTweets($stringHashtags); } catch (BadRequestHttpException $e) { $this->logger->critical( - 'Twitter API get request (tweets/search/recent) error : ' . $e->getMessage(), + 'Twitter API get request (tweets/search/recent) error : '.$e->getMessage(), [ 'error' => $e, ] ); - $io->error('Twitter API get request (tweets/search/recent) error : ' . $e->getMessage()); + $io->error('Twitter API get request (tweets/search/recent) error : '.$e->getMessage()); return Command::FAILURE; } if (null === $tweets) { - $io->success('Aucun tweet trouvé pour : ' . $stringHashtags); - $this->logger->notice('Aucun tweet trouvé pour : ' . $stringHashtags); + $io->success('Aucun tweet trouvé pour : '.$stringHashtags); + $this->logger->notice('Aucun tweet trouvé pour : '.$stringHashtags); return Command::SUCCESS; } - $io->success('Tweets trouvés pour : ' . $stringHashtags); - $this->logger->notice('Tweets trouvés pour : ' . $stringHashtags); + $io->success('Tweets trouvés pour : '.$stringHashtags); + $this->logger->notice('Tweets trouvés pour : '.$stringHashtags); if (!$input->getOption('update-db')) { return Command::SUCCESS; @@ -298,7 +297,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $player = $this->playerRepository->findOneByTwitterAccountId($user->id); - if (null === $player || ($player->getUsername() !== '@' . $user->username || $player->name !== $user->name)) { + if (null === $player || ($player->getUsername() !== '@'.$user->username || $player->name !== $user->name)) { if (null === $player) { $player = new Player(); $player->twitterAccountId = $user->id; @@ -396,7 +395,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->gameRepository->persistAndFlush($game, true); } catch (ValidationException $e) { $io->error($e->getMessage()); - $this->logger->error($e->getMessage(), (array)$e); + $this->logger->error($e->getMessage(), (array) $e); continue; } diff --git a/api/src/Controller/CreateMediaObjectAction.php b/api/src/Controller/CreateMediaObjectAction.php index ae75f1d..7e7602a 100644 --- a/api/src/Controller/CreateMediaObjectAction.php +++ b/api/src/Controller/CreateMediaObjectAction.php @@ -5,12 +5,12 @@ namespace App\Controller; use ApiPlatform\Symfony\Validator\Exception\ValidationException; +use ApiPlatform\Validator\ValidatorInterface; use App\Entity\MediaObject; use Psr\Log\LoggerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Attribute\AsController; -use ApiPlatform\Validator\ValidatorInterface; #[AsController] final class CreateMediaObjectAction extends AbstractController @@ -26,7 +26,7 @@ public function __invoke(Request $request, ValidatorInterface $validator, Logger try { $validator->validate($mediaObject); } catch (ValidationException $e) { - $logger->error($e->getMessage(), (array)$e); + $logger->error($e->getMessage(), (array) $e); throw $e; } diff --git a/api/src/Controller/ImageReaderController.php b/api/src/Controller/ImageReaderController.php index db737d9..f92dda8 100644 --- a/api/src/Controller/ImageReaderController.php +++ b/api/src/Controller/ImageReaderController.php @@ -31,7 +31,7 @@ public function indexReader(MediaObject $image): Response try { $imageContent = $this->defaultMedia->read($image->filePath); $imageMimeType = $this->defaultMedia->mimeType($image->filePath); - } catch (FilesystemException | UnableToReadFile $e) { + } catch (FilesystemException|UnableToReadFile $e) { $this->logger->error('Error on /image/'.$image->filePath.' : "'.$e->getMessage().'"', (array) $e); throw $e; } diff --git a/api/src/DataFixtures/Processor/MediaObjectProcessor.php b/api/src/DataFixtures/Processor/MediaObjectProcessor.php index 4cfdaca..9a5c120 100644 --- a/api/src/DataFixtures/Processor/MediaObjectProcessor.php +++ b/api/src/DataFixtures/Processor/MediaObjectProcessor.php @@ -29,8 +29,8 @@ public function preProcess(string $id, $object): void $fs = new Filesystem(); - $fs->touch($this->kernelDir . '/fixtures/test/files/invalid_file.txt'); - $fs->appendToFile($this->kernelDir . '/fixtures/test/files/invalid_file.txt', 'My invalid file !!!'); + $fs->touch($this->kernelDir.'/fixtures/test/files/invalid_file.txt'); + $fs->appendToFile($this->kernelDir.'/fixtures/test/files/invalid_file.txt', 'My invalid file !!!'); } /** diff --git a/api/src/Entity/Lot.php b/api/src/Entity/Lot.php index b400dd8..2bc834d 100644 --- a/api/src/Entity/Lot.php +++ b/api/src/Entity/Lot.php @@ -16,7 +16,6 @@ use ApiPlatform\Metadata\Put; use App\Repository\LotRepository; use App\State\LotProcessor; -use App\Visitor\MessageNormalizer\MessageNormalizer; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; diff --git a/api/src/Entity/Stat.php b/api/src/Entity/Stat.php index a7b95ad..2afae15 100644 --- a/api/src/Entity/Stat.php +++ b/api/src/Entity/Stat.php @@ -1,8 +1,9 @@ quantity--; + --$lot->quantity; $this->persistAndFlush($lot, true); $dataReturn[] = $lot; diff --git a/api/src/State/GamePutProcessor.php b/api/src/State/GamePutProcessor.php index 38e21d5..d4c9d8b 100644 --- a/api/src/State/GamePutProcessor.php +++ b/api/src/State/GamePutProcessor.php @@ -16,13 +16,12 @@ final class GamePutProcessor implements ProcessorInterface { - public function __construct(private readonly PersistProcessor $persistProcessor, - private readonly TwitterApi $twitterApi, - private readonly string $appEnv, - private readonly LoggerInterface $logger, - private readonly MessageNormalizer $messageNormalizer - ) - { + public function __construct(private readonly PersistProcessor $persistProcessor, + private readonly TwitterApi $twitterApi, + private readonly string $appEnv, + private readonly LoggerInterface $logger, + private readonly MessageNormalizer $messageNormalizer + ) { } /** @@ -32,23 +31,23 @@ public function process($data, Operation $operation, array $uriVariables = [], a { if ('test' !== $this->appEnv && $data instanceof Game && null !== $data->score && 'PUT' === $context['operation']->getMethod()) { if (null === $data->reward) { - throw new \LogicException('Reward of the game n°' . $data->getId() . ' not exists during game PUT request'); + throw new \LogicException('Reward of the game n°'.$data->getId().' not exists during game PUT request'); } if (null === $data->reward->lot) { - throw new \LogicException('Lot of the reward n°' . $data->reward->getId() . ' not exists during game PUT request'); + throw new \LogicException('Lot of the reward n°'.$data->reward->getId().' not exists during game PUT request'); } if (null === $data->tweet) { - throw new \LogicException('Tweet of the game n°' . $data->getId() . ' not exists during game PUT request'); + throw new \LogicException('Tweet of the game n°'.$data->getId().' not exists during game PUT request'); } if (null === $data->player) { - throw new \LogicException('Player of the game n°' . $data->getId() . ' not exists during game PUT request'); + throw new \LogicException('Player of the game n°'.$data->getId().' not exists during game PUT request'); } try { $params = [ 'nom' => $data->player->name, 'username' => $data->player->getUsername(), - 'score' => $data->score + 'score' => $data->score, ]; $message = $this->messageNormalizer->normalize($data->reward->lot->message, $params); @@ -56,7 +55,7 @@ public function process($data, Operation $operation, array $uriVariables = [], a $this->twitterApi->reply($message, $data->tweet->tweetId); } catch (BadRequestHttpException $e) { $this->logger->critical( - 'Twitter API post request (tweets) error' . $e->getMessage(), + 'Twitter API post request (tweets) error'.$e->getMessage(), [ 'error' => $e, ] diff --git a/api/src/State/StatGamesCountProvider.php b/api/src/State/StatGamesCountProvider.php index d7dbfba..32c0251 100644 --- a/api/src/State/StatGamesCountProvider.php +++ b/api/src/State/StatGamesCountProvider.php @@ -11,7 +11,6 @@ use DateTime; use Exception; use Psr\Log\LoggerInterface; -use RuntimeException; use Symfony\Component\Serializer\SerializerInterface; final class StatGamesCountProvider implements ProviderInterface @@ -22,10 +21,11 @@ public function __construct(private readonly GameRepository $gameRepository, pri /** * {@inheritDoc} + * * @throws Exception */ public function provide(Operation $operation, array $uriVariables = [], array $context = []): array { - return $this->serializer->denormalize($this->gameRepository->getDaysCount(new DateTime($uriVariables['id'])), Stat::class . '[]'); + return $this->serializer->denormalize($this->gameRepository->getDaysCount(new DateTime($uriVariables['id'])), Stat::class.'[]'); } } diff --git a/api/src/Twitter/TwitterApi.php b/api/src/Twitter/TwitterApi.php index bc23711..c24ad5a 100644 --- a/api/src/Twitter/TwitterApi.php +++ b/api/src/Twitter/TwitterApi.php @@ -16,15 +16,14 @@ final class TwitterApi private array $memoize = []; public function __construct( - private readonly string $twitterConsumerKey, - private readonly string $twitterConsumerSecret, - private readonly string $twitterAccessToken, - private readonly string $twitterAccessTokenSecret, + private readonly string $twitterConsumerKey, + private readonly string $twitterConsumerSecret, + private readonly string $twitterAccessToken, + private readonly string $twitterAccessTokenSecret, private readonly TweetRepository $tweetRepository, - private readonly string $appEnv, + private readonly string $appEnv, private readonly LoggerInterface $logger - ) - { + ) { } private function getConnection(): TwitterOAuth @@ -54,7 +53,7 @@ public function get(string $url, array $params = [], string $apiVersion = '2'): } $this->logger->critical( - 'Twitter API get request error : ' . $response->detail, + 'Twitter API get request error : '.$response->detail, [ 'response' => $response, ] @@ -76,7 +75,7 @@ public function post(string $url, array $params = [], bool $json = true, string } $this->logger->critical( - 'Twitter API post request error : ' . $response->detail, + 'Twitter API post request error : '.$response->detail, [ 'response' => $response, ] @@ -105,7 +104,7 @@ public function reply(string $message, string $tweetId): array|object */ public function getUser(string $authorId): array|object { - return $this->get('users/' . $authorId); + return $this->get('users/'.$authorId); } /** @@ -113,7 +112,7 @@ public function getUser(string $authorId): array|object */ public function getUserByUsername(string $username): array|object { - return $this->get('users/by/username/' . $username); + return $this->get('users/by/username/'.$username); } /** @@ -140,7 +139,7 @@ public function getRecentTweets(string $query = ''): array|object ]; $tweet = $this->tweetRepository->findLastTweet(); - if ($this->appEnv !== 'test' && null !== $tweet) { + if ('test' !== $this->appEnv && null !== $tweet) { $params['since_id'] = $tweet->tweetId; } diff --git a/api/src/Validator/ExistsInTwitterValidator.php b/api/src/Validator/ExistsInTwitterValidator.php index 9ece63f..dd9ed0b 100644 --- a/api/src/Validator/ExistsInTwitterValidator.php +++ b/api/src/Validator/ExistsInTwitterValidator.php @@ -10,7 +10,6 @@ use Symfony\Component\Validator\ConstraintValidator; use Symfony\Component\Validator\Exception\UnexpectedTypeException; use Symfony\Component\Validator\Exception\UnexpectedValueException; -use function is_string; final class ExistsInTwitterValidator extends ConstraintValidator { @@ -31,7 +30,7 @@ public function validate($username, Constraint $constraint): void return; } - if (!is_string($username)) { + if (!\is_string($username)) { throw new UnexpectedValueException($username, 'string'); } diff --git a/api/src/Visitor/MessageNormalizer/MessageNormalizer.php b/api/src/Visitor/MessageNormalizer/MessageNormalizer.php index 7585352..c859808 100644 --- a/api/src/Visitor/MessageNormalizer/MessageNormalizer.php +++ b/api/src/Visitor/MessageNormalizer/MessageNormalizer.php @@ -31,5 +31,4 @@ public function normalize(string $message, array $params = []): string return $message; } - } diff --git a/api/src/Visitor/MessageNormalizer/Visitors/NameVisitor.php b/api/src/Visitor/MessageNormalizer/Visitors/NameVisitor.php index 2c51150..01266f2 100644 --- a/api/src/Visitor/MessageNormalizer/Visitors/NameVisitor.php +++ b/api/src/Visitor/MessageNormalizer/Visitors/NameVisitor.php @@ -10,7 +10,7 @@ class NameVisitor implements MessageNormalizerVisitor { public function accept(string $message, array $params = []): bool { - return str_contains($message, '%nom%') && array_key_exists('nom', $params) && is_string($params['nom']) && trim($params['nom']) !== ''; + return str_contains($message, '%nom%') && \array_key_exists('nom', $params) && \is_string($params['nom']) && '' !== trim($params['nom']); } public function normalize(string $message, array $params): string diff --git a/api/src/Visitor/MessageNormalizer/Visitors/ScoreVisitor.php b/api/src/Visitor/MessageNormalizer/Visitors/ScoreVisitor.php index 4ef171b..4bb0a7d 100644 --- a/api/src/Visitor/MessageNormalizer/Visitors/ScoreVisitor.php +++ b/api/src/Visitor/MessageNormalizer/Visitors/ScoreVisitor.php @@ -10,7 +10,7 @@ class ScoreVisitor implements MessageNormalizerVisitor { public function accept(string $message, array $params = []): bool { - return str_contains($message, '%score%') && array_key_exists('score', $params) && is_int($params['score']) && $params['score'] >= 0; + return str_contains($message, '%score%') && \array_key_exists('score', $params) && \is_int($params['score']) && $params['score'] >= 0; } public function normalize(string $message, array $params): string diff --git a/api/src/Visitor/MessageNormalizer/Visitors/UsernameVisitor.php b/api/src/Visitor/MessageNormalizer/Visitors/UsernameVisitor.php index 793ca80..b86de7e 100644 --- a/api/src/Visitor/MessageNormalizer/Visitors/UsernameVisitor.php +++ b/api/src/Visitor/MessageNormalizer/Visitors/UsernameVisitor.php @@ -10,7 +10,7 @@ class UsernameVisitor implements MessageNormalizerVisitor { public function accept(string $message, array $params = []): bool { - return str_contains($message, '%@username%') && array_key_exists('username', $params) && is_string($params['username']) && trim($params['username']) !== ''; + return str_contains($message, '%@username%') && \array_key_exists('username', $params) && \is_string($params['username']) && '' !== trim($params['username']); } public function normalize(string $message, array $params): string diff --git a/api/src/Visitor/MessageNormalizer/Visitors/WebsiteVisitor.php b/api/src/Visitor/MessageNormalizer/Visitors/WebsiteVisitor.php index 0b41ade..7fe7b6c 100644 --- a/api/src/Visitor/MessageNormalizer/Visitors/WebsiteVisitor.php +++ b/api/src/Visitor/MessageNormalizer/Visitors/WebsiteVisitor.php @@ -10,7 +10,7 @@ class WebsiteVisitor implements MessageNormalizerVisitor { public function accept(string $message, array $params = []): bool { - return str_contains($message, '%site_web%') && array_key_exists('site_web', $params) && is_string($params['site_web']) && trim($params['site_web']) !== ''; + return str_contains($message, '%site_web%') && \array_key_exists('site_web', $params) && \is_string($params['site_web']) && '' !== trim($params['site_web']); } public function normalize(string $message, array $params): string