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

Commit

Permalink
Make a clean with php-cs-fixer
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeKESTEMAN committed Aug 16, 2022
1 parent d7dc291 commit b02b566
Show file tree
Hide file tree
Showing 23 changed files with 134 additions and 126 deletions.
2 changes: 2 additions & 0 deletions api/config/bundles.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

return [
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
Expand Down
2 changes: 2 additions & 0 deletions api/config/preload.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

if (file_exists(dirname(__DIR__).'/var/cache/prod/App_KernelProdContainer.preload.php')) {
require dirname(__DIR__).'/var/cache/prod/App_KernelProdContainer.preload.php';
}
4 changes: 3 additions & 1 deletion api/public/index.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php

declare(strict_types=1);

use App\Kernel;

require_once dirname(__DIR__) . '/vendor/autoload_runtime.php';
require_once dirname(__DIR__).'/vendor/autoload_runtime.php';

return function (array $context) {
return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
Expand Down
95 changes: 50 additions & 45 deletions api/src/Command/TwitterApiRecentTweetsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,19 @@
)]
class TwitterApiRecentTweetsCommand extends Command
{
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 TwitterAccountToFollowRepository $twitterAccountToFollowRepository,
private readonly TwitterHashtagRepository $twitterHashtagRepository,
private readonly string $communicationWebsiteUrl,
private readonly LoggerInterface $logger,
private readonly ValidatorInterface $validator)
{
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 TwitterAccountToFollowRepository $twitterAccountToFollowRepository,
private readonly TwitterHashtagRepository $twitterHashtagRepository,
private readonly string $communicationWebsiteUrl,
private readonly LoggerInterface $logger,
private readonly ValidatorInterface $validator
) {
parent::__construct();
}

Expand All @@ -66,10 +67,10 @@ protected function configure(): void
}

private const DEFAULTS_TWEETS_REPLIES = [
['id' => 'on_new_game', 'reply' => 'Hey %nom% (%@joueur%), 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% (%@joueur%) 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% (%@joueur%) 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% (%@joueur%), 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% (%@joueur%) 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% (%@joueur%) 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 !'],
];

private function selectDefaultTweetReplieById(string $id): ?array
Expand All @@ -80,6 +81,7 @@ private function selectDefaultTweetReplieById(string $id): ?array
}
}
$this->logger->error("'$id' was not found in DEFAULTS_TWEETS_REPLIES");

return null;
}

Expand All @@ -98,7 +100,7 @@ private function getTweetReplyMessage(string $id, string $name, string $userhand
throw new TweetReplyNotFoundException();
}

return str_replace(array('%nom%', '%@joueur%', '%site_web%'), array($name, '@' . $userhandle, $this->communicationWebsiteUrl), $message['reply']);
return str_replace(['%nom%', '%@joueur%', '%site_web%'], [$name, '@'.$userhandle, $this->communicationWebsiteUrl], $message['reply']);
}

/**
Expand Down Expand Up @@ -128,7 +130,7 @@ private function getRecentTweets(string $hashtag): ?object
*/
private function setUser(object $tweets, object $tweet, int $index): ?object
{
$user = array_key_exists($index, $tweets->includes->users) && $tweets->includes->users[$index]->id === $tweet->author_id ? $tweets->includes->users[$index] : null;
$user = \array_key_exists($index, $tweets->includes->users) && $tweets->includes->users[$index]->id === $tweet->author_id ? $tweets->includes->users[$index] : null;

if (null !== $user) {
return $user;
Expand All @@ -146,25 +148,25 @@ private function setUser(object $tweets, object $tweet, int $index): ?object
}

try {
$user = $this->twitterApi->get('users/' . $tweet->author_id);
$user = $this->twitterApi->get('users/'.$tweet->author_id);
$user = $user->data ?? null;

if (null === $user) {
$this->logger->warning(
"Twitter user n°$tweet->author_id not found for the tweet n°$tweet->id",
[
'tweet' => $tweet
'tweet' => $tweet,
]
);
}

return $user;
} 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
'error' => $e,
]
);
}
Expand All @@ -189,9 +191,9 @@ 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
'error' => $e,
]
);
}
Expand Down Expand Up @@ -219,9 +221,9 @@ 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
'error' => $e,
]
);
}
Expand All @@ -242,19 +244,19 @@ 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
'Active Twitter accounts to follow for command' => $accountsToFollow,
]
);

if(count($hashtags) <= 0) {
if (\count($hashtags) <= 0) {
$io->error('No active hashtag for the TwitterApiRecentTweetsCommand');
throw new NoActiveHashtagException();
}

if(count($accountsToFollow) <= 0) {
if (\count($accountsToFollow) <= 0) {
$io->error('No active twitter account to follow for the TwitterApiRecentTweetsCommand');
throw new NoActiveTwitterAccountToFollowException();
}
Expand All @@ -268,22 +270,24 @@ 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
'error' => $e,
]
);

return Command::FAILURE;
}

if (!$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 @@ -303,7 +307,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$player = $this->playerRepository->findOneByTwitterAccountId($user->id);

if (null === $player || ($player->getUsername() !== '@' . $user->username || $player->getName() !== $user->name)) {
if (null === $player || ($player->getUsername() !== '@'.$user->username || $player->getName() !== $user->name)) {
if (null === $player) {
$player = new Player();
$player->setTwitterAccountId($user->id);
Expand Down Expand Up @@ -334,9 +338,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
"No tweet reply message found for 'need_to_follow_us' in TwitterApiRecentTweetsCommand",
[
'lot_id' => 'need_to_follow_us',
'error' => $e
'error' => $e,
]
);

return Command::FAILURE;
}
}
Expand All @@ -353,9 +358,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
"No tweet reply message found for 'game_already_generated_less_than_a_day_ago' in TwitterApiRecentTweetsCommand",
[
'lot_id' => 'game_already_generated_less_than_a_day_ago',
'error' => $e
'error' => $e,
]
);

return Command::FAILURE;
}
}
Expand All @@ -367,7 +373,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$randomLot = $this->lotRepository->getRandom();

if (count($randomLot) > 0) {
if (\count($randomLot) > 0) {
$reward->setLot($randomLot[0]);
} else {
$io->error('No lot available');
Expand All @@ -380,17 +386,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
"No tweet reply message found for 'no_more_available_lots' in TwitterApiRecentTweetsCommand",
[
'lot_id' => 'no_more_available_lots',
'error' => $e
'error' => $e,
]

);
}
}

throw new NoLotAvailableException();
}


$game = new Game();
$game->setTweet($recentTweet);
$game->setPlayer($player);
Expand All @@ -401,7 +405,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 All @@ -417,9 +421,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
"No tweet reply message found for 'on_new_game' in TwitterApiRecentTweetsCommand",
[
'lot_id' => 'on_new_game',
'error' => $e
'error' => $e,
]
);

return Command::FAILURE;
}
}
Expand Down
5 changes: 4 additions & 1 deletion api/src/Controller/ImageReaderController.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Controller;

use App\Entity\MediaObject;
Expand All @@ -15,7 +17,8 @@ public function indexReader(MediaObject $image): BinaryFileResponse
$root = explode('/', __DIR__);
$root = \array_slice($root, 0, -2);
$root = implode('/', $root);
$filename = "/public/media/" . $image->getFilePath();
$filename = '/public/media/'.$image->getFilePath();

return new BinaryFileResponse($root.$filename);
}
}
2 changes: 1 addition & 1 deletion api/src/Entity/Game.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
security: 'object.getScore() === null',
validationContext: ['groups' => ['putValidation']],
processor: GamePutProcessor::class
)
),
],
mercure: ['private' => true],
order: ['playDate' => 'DESC'],
Expand Down
2 changes: 1 addition & 1 deletion api/src/Entity/Lot.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function getMessage(?string $name = null, ?string $userhandle = null, ?in
}

if (null !== $score) {
$returnMessage = str_replace('%score%', (string)$score, $returnMessage);
$returnMessage = str_replace('%score%', (string) $score, $returnMessage);
}

return $returnMessage;
Expand Down
6 changes: 2 additions & 4 deletions api/src/Entity/Player.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

namespace App\Entity;

use ApiPlatform\Doctrine\Common\Filter\DateFilterInterface;
use ApiPlatform\Doctrine\Common\Filter\OrderFilterInterface;
use ApiPlatform\Doctrine\Orm\Filter\DateFilter;
use ApiPlatform\Doctrine\Orm\Filter\ExistsFilter;
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
Expand Down Expand Up @@ -53,14 +51,14 @@ class Player

#[ORM\Column(name: 'username', type: 'string', length: 255, unique: true)]
#[Assert\Regex(
pattern: "/^[@]?[A-Za-z0-9_]+$/",
pattern: '/^[@]?[A-Za-z0-9_]+$/',
message: "Le pseudo ne doit contenir que des lettres, des chiffres et des '_' (il est possible de mettre un @ au début)"
)]
private ?string $username = null;

#[ORM\Column(name: 'twitter_account_id', type: 'string', length: 255, unique: true)]
#[Assert\Regex(
pattern: "/^[0-9]+$/",
pattern: '/^[0-9]+$/',
message: "L'id ne doit contenir que des chiffres"
)]
#[ApiProperty(writable: false, types: ['https://schema.org/identifier'])]
Expand Down
2 changes: 1 addition & 1 deletion api/src/Entity/Tweet.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Tweet

#[ORM\Column(name: 'tweet_id', type: 'string', length: 255, unique: true)]
#[Assert\Regex(
pattern: "/^[0-9]+$/",
pattern: '/^[0-9]+$/',
message: "L'id ne doit contenir que des chiffres"
)]
#[ApiProperty(types: ['https://schema.org/identifier'])]
Expand Down
6 changes: 3 additions & 3 deletions api/src/Entity/TwitterAccountToFollow.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class TwitterAccountToFollow
groups: ['firstPostValidation']
)]
#[Assert\Regex(
pattern: "/^[@]?[A-Za-z0-9_]+$/",
pattern: '/^[@]?[A-Za-z0-9_]+$/',
message: "Le pseudo ne doit contenir que des lettres, des chiffres et des '_' (il est possible de mettre un @ au début)",
groups: ['firstPostValidation']
)]
Expand All @@ -76,7 +76,7 @@ class TwitterAccountToFollow

#[ORM\Column(name: 'twitter_account_id', type: 'string', length: 255, unique: true)]
#[Assert\Regex(
pattern: "/^[0-9]+$/",
pattern: '/^[0-9]+$/',
message: "L'id ne doit contenir que des chiffres"
)]
#[ApiProperty(writable: false, types: ['https://schema.org/identifier'])]
Expand Down Expand Up @@ -109,7 +109,7 @@ public function getUsername(): ?string
public function setUsername(?string $username): void
{
if ('@' !== $username[0]) {
$username = '@' . $username;
$username = '@'.$username;
}

$this->username = $username;
Expand Down
Loading

0 comments on commit b02b566

Please sign in to comment.