Skip to content
This repository has been archived by the owner on Nov 30, 2023. It is now read-only.

Commit

Permalink
Run php-cs-fixer fix --ansi in ./api
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeKESTEMAN committed Aug 29, 2022
1 parent b3019ca commit 8e0f110
Show file tree
Hide file tree
Showing 17 changed files with 68 additions and 75 deletions.
61 changes: 30 additions & 31 deletions api/src/Command/TwitterApiRecentTweetsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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);
Expand All @@ -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']);
}

/**
Expand Down Expand Up @@ -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,
Expand All @@ -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,
]
Expand Down Expand Up @@ -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,
]
Expand All @@ -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,
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions api/src/Controller/CreateMediaObjectAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion api/src/Controller/ImageReaderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions api/src/DataFixtures/Processor/MediaObjectProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 !!!');
}

/**
Expand Down
1 change: 0 additions & 1 deletion api/src/Entity/Lot.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions api/src/Entity/Stat.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

declare(strict_types=1);

namespace App\Entity;

use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use App\State\StatGamesCountProvider;
Expand All @@ -22,7 +23,6 @@
]
class Stat
{

public int $nbrGames = 0;

public ?\DateTime $date = null;
Expand Down
1 change: 0 additions & 1 deletion api/src/Entity/TweetReply.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Put;
use App\Repository\TweetReplyRepository;
use App\Visitor\MessageNormalizer\MessageNormalizer;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Serializer\Annotation\Groups;
Expand Down
2 changes: 1 addition & 1 deletion api/src/Repository/LotRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function getRandom(int $numberOfLotReturn = 1): array
return $dataReturn;
}

$lot->quantity--;
--$lot->quantity;
$this->persistAndFlush($lot, true);

$dataReturn[] = $lot;
Expand Down
25 changes: 12 additions & 13 deletions api/src/State/GamePutProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {
}

/**
Expand All @@ -32,31 +31,31 @@ 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);

$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,
]
Expand Down
4 changes: 2 additions & 2 deletions api/src/State/StatGamesCountProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use DateTime;
use Exception;
use Psr\Log\LoggerInterface;
use RuntimeException;
use Symfony\Component\Serializer\SerializerInterface;

final class StatGamesCountProvider implements ProviderInterface
Expand All @@ -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.'[]');
}
}
23 changes: 11 additions & 12 deletions api/src/Twitter/TwitterApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
]
Expand All @@ -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,
]
Expand Down Expand Up @@ -105,15 +104,15 @@ 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);
}

/**
* @throws TwitterOAuthException
*/
public function getUserByUsername(string $username): array|object
{
return $this->get('users/by/username/' . $username);
return $this->get('users/by/username/'.$username);
}

/**
Expand All @@ -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;
}

Expand Down
3 changes: 1 addition & 2 deletions api/src/Validator/ExistsInTwitterValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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');
}

Expand Down
Loading

0 comments on commit 8e0f110

Please sign in to comment.