From 693eaf2950ad555574a46176c677b6acddf66596 Mon Sep 17 00:00:00 2001 From: Guillaume KESTEMAN Date: Fri, 5 Aug 2022 09:45:45 +0200 Subject: [PATCH] style: cs-fixer --- api/.gitignore | 2 + api/.php-cs-fixer.dist.php | 91 +++++++++++++++++++ .../Command/TwitterApiRecentTweetsCommand.php | 50 +++++----- .../CreateMediaObjectActionController.php | 2 + .../Processor/MediaObjectProcessor.php | 20 ++-- api/src/Entity/Game.php | 32 ++++--- api/src/Entity/Lot.php | 35 +++---- api/src/Entity/MediaObject.php | 41 +++------ api/src/Entity/Player.php | 34 +++---- api/src/Entity/Reward.php | 22 +++-- api/src/Entity/Tweet.php | 16 ++-- api/src/Entity/TweetReply.php | 47 ++++------ api/src/Entity/TwitterAccountToFollow.php | 60 ++++-------- api/src/Entity/TwitterHashtag.php | 42 ++++----- api/src/Kernel.php | 2 + api/src/Repository/CommonRepository.php | 1 + api/src/Repository/GameRepository.php | 6 +- api/src/Repository/LotRepository.php | 7 +- api/src/Repository/MediaObjectRepository.php | 2 + api/src/Repository/PlayerRepository.php | 5 +- api/src/Repository/RewardRepository.php | 2 + api/src/Repository/TweetReplyRepository.php | 2 + api/src/Repository/TweetRepository.php | 5 +- .../TwitterAccountToFollowRepository.php | 5 +- .../Repository/TwitterHashtagRepository.php | 5 +- api/src/Serializer/MediaObjectNormalizer.php | 2 + api/src/State/LotProcessor.php | 8 +- .../State/TwitterAccountToFollowProcessor.php | 9 +- api/src/Twitter/TwitterApi.php | 13 +-- api/src/Validator/ExistsInTwitter.php | 1 - .../Validator/ExistsInTwitterValidator.php | 9 +- 31 files changed, 311 insertions(+), 267 deletions(-) create mode 100644 api/.php-cs-fixer.dist.php diff --git a/api/.gitignore b/api/.gitignore index bcde55c..ce406fe 100644 --- a/api/.gitignore +++ b/api/.gitignore @@ -47,3 +47,5 @@ yarn-error.log ###> php/scripts ### /mercureJWTGenerator.php ###< php/scripts ### + +/.php-cs-fixer.cache diff --git a/api/.php-cs-fixer.dist.php b/api/.php-cs-fixer.dist.php new file mode 100644 index 0000000..709d1d6 --- /dev/null +++ b/api/.php-cs-fixer.dist.php @@ -0,0 +1,91 @@ +in(__DIR__.'/src'); + +return (new PhpCsFixer\Config()) + ->setRiskyAllowed(true) + ->setRules([ + '@DoctrineAnnotation' => true, + '@PHP71Migration' => true, + '@PHP71Migration:risky' => true, + '@PHPUnit60Migration:risky' => true, + '@Symfony' => true, + '@Symfony:risky' => true, + 'align_multiline_comment' => [ + 'comment_type' => 'phpdocs_like', + ], + 'array_indentation' => true, + 'compact_nullable_typehint' => true, + 'doctrine_annotation_array_assignment' => [ + 'operator' => '=', + ], + 'doctrine_annotation_spaces' => [ + 'after_array_assignments_equals' => false, + 'before_array_assignments_equals' => false, + ], + 'explicit_indirect_variable' => true, + 'fully_qualified_strict_types' => true, + 'logical_operators' => true, + 'multiline_comment_opening_closing' => true, + 'multiline_whitespace_before_semicolons' => [ + 'strategy' => 'no_multi_line', + ], + 'no_alternative_syntax' => true, + 'no_extra_blank_lines' => [ + 'tokens' => [ + 'break', + 'continue', + 'curly_brace_block', + 'extra', + 'parenthesis_brace_block', + 'return', + 'square_brace_block', + 'throw', + 'use', + ], + ], + 'no_superfluous_elseif' => true, + 'no_superfluous_phpdoc_tags' => [ + 'allow_mixed' => false, + ], + 'no_unset_cast' => true, + 'no_unset_on_property' => true, + 'no_useless_else' => true, + 'no_useless_return' => true, + 'ordered_imports' => [ + 'imports_order' => [ + 'class', + 'function', + 'const', + ], + 'sort_algorithm' => 'alpha', + ], + 'php_unit_method_casing' => [ + 'case' => 'camel_case', + ], + 'php_unit_set_up_tear_down_visibility' => true, + 'php_unit_test_annotation' => [ + 'style' => 'prefix', + ], + 'phpdoc_add_missing_param_annotation' => [ + 'only_untyped' => true, + ], + 'phpdoc_no_alias_tag' => true, + 'phpdoc_order' => true, + 'phpdoc_trim_consecutive_blank_line_separation' => true, + 'phpdoc_var_annotation_correct_order' => true, + 'return_assignment' => true, + 'strict_param' => true, + 'visibility_required' => [ + 'elements' => [ + 'const', + 'method', + 'property', + ], + ], + 'void_return' => true, + ]) + ->setFinder($finder); diff --git a/api/src/Command/TwitterApiRecentTweetsCommand.php b/api/src/Command/TwitterApiRecentTweetsCommand.php index c773b07..8af5cd7 100644 --- a/api/src/Command/TwitterApiRecentTweetsCommand.php +++ b/api/src/Command/TwitterApiRecentTweetsCommand.php @@ -1,5 +1,7 @@ $hashtag, 'expansions' => 'author_id', - 'tweet.fields' => 'created_at' + 'tweet.fields' => 'created_at', ]; $tweets = $this->twitterApi->get('tweets/search/recent', $params); + return $tweets->meta->result_count > 0 ? $tweets : null; } /** - * @param stdClass $tweets - * @param stdClass $tweet - * @param int $index - * @return stdClass|null * @throws TwitterOAuthException */ private function setUser(stdClass $tweets, stdClass $tweet, int $index): ?stdClass { $user = null; try { - $user = $tweets->includes->users[$index]->id === $tweet->author_id ? $tweets->includes->users[$index] : throw new Exception; + $user = $tweets->includes->users[$index]->id === $tweet->author_id ? $tweets->includes->users[$index] : throw new Exception(); } catch (Exception) { foreach ($tweets->includes->users as $tweetUser) { if ($tweetUser->id === $tweet->author_id) { @@ -86,10 +83,11 @@ private function setUser(stdClass $tweets, stdClass $tweet, int $index): ?stdCla } if (null === $user) { - $user = $this->twitterApi->get('users/' . $tweet->author_id); + $user = $this->twitterApi->get('users/'.$tweet->author_id); $user = $user->data ?? null; } } + return $user; } @@ -103,7 +101,7 @@ private function following(string $userId): bool foreach ($twitterAccountsToFollow as $twitterAccountToFollow) { $friendships = $this->twitterApi->get('friendships/show', [ 'source_id' => $userId, - 'target_id' => $twitterAccountToFollow->getTwitterAccountId() + 'target_id' => $twitterAccountToFollow->getTwitterAccountId(), ], '1.1'); if ($friendships->relationship->source->following) { @@ -115,9 +113,6 @@ private function following(string $userId): bool } /** - * @param stdClass $user - * @param stdClass $tweet - * @return void * @throws NonUniqueResultException * @throws TwitterOAuthException */ @@ -127,23 +122,19 @@ private function notFollowAccounts(stdClass $user, stdClass $tweet): void return $twitterAccountToFollow->getTwitterAccountUsername(); }, $this->twitterAccountToFollowRepository->getAllActive()); $twitterAccountsUsernamesToFollow = implode(', ', $twitterAccountsUsernamesToFollow); - $message = $this->tweetReplyRepository->findOneByName("need_to_follow_us")?->getMessage($user->getName(), $user->getUsername()) ?? 'Thanks ' . $user->getName() . ' to talk about us.' . PHP_EOL . 'But you are not yet eligible for the game, to be eligible you have to follow one of this accounts: ' . $twitterAccountsUsernamesToFollow; + $message = $this->tweetReplyRepository->findOneByName('need_to_follow_us')?->getMessage($user->getName(), $user->getUsername()) ?? 'Thanks '.$user->getName().' to talk about us.'.\PHP_EOL.'But you are not yet eligible for the game, to be eligible you have to follow one of this accounts: '.$twitterAccountsUsernamesToFollow; $params = [ 'text' => $message, 'reply' => [ - 'in_reply_to_tweet_id' => $tweet->id - ] + 'in_reply_to_tweet_id' => $tweet->id, + ], ]; $this->twitterApi->post('tweets', $params); } - /** - * @param string $tweetId - * @param string $message - * @return void * @throws TwitterOAuthException */ private function newReply(string $tweetId, string $message): void @@ -151,8 +142,8 @@ private function newReply(string $tweetId, string $message): void $params = [ 'text' => $message, 'reply' => [ - 'in_reply_to_tweet_id' => $tweetId - ] + 'in_reply_to_tweet_id' => $tweetId, + ], ]; $this->twitterApi->post('tweets', $params); @@ -174,11 +165,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int $tweets = $this->getRecentTweets($hashtag->getHashtag()); if (!$tweets) { - $io->success('Aucun tweet trouvé pour : ' . $hashtag->getHashtag()); + $io->success('Aucun tweet trouvé pour : '.$hashtag->getHashtag()); continue; } - $io->success('Tweets trouvés pour : ' . $hashtag->getHashtag()); + $io->success('Tweets trouvés pour : '.$hashtag->getHashtag()); if (!$input->getOption('update-db')) { continue; @@ -192,7 +183,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int } if (null === ($user = $this->setUser($tweets, $tweet, $index))) { - $io->error('User not found for the tweet n°' . $tweet->id); + $io->error('User not found for the tweet n°'.$tweet->id); continue; } @@ -217,9 +208,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int $lastGame = $this->gameRepository->findOneByPlayer($player); } - if (null !== $lastGame && null !== $lastGame->getPlayDate() && date_diff($lastGame->getPlayDate(), new \DateTime)->d < 1) { + if (null !== $lastGame && null !== $lastGame->getPlayDate() && date_diff($lastGame->getPlayDate(), new \DateTime())->d < 1) { if ($input->getOption('reply')) { - $message = $this->tweetReplyRepository->findOneByName("game_already_generated_less_than_a_day_ago")?->getMessage($player->getName(), $player->getUsername(), $this->communicationWebsiteUrl) ?? 'Thanks ' . $player->getName() . ' to talk about us.' . PHP_EOL . 'But you already got a game link less than a day ago ! (talk again about us tomorrow to get a new game url)' . PHP_EOL . 'This is your previous game link : ' . $this->communicationWebsiteUrl; + $message = $this->tweetReplyRepository->findOneByName('game_already_generated_less_than_a_day_ago')?->getMessage($player->getName(), $player->getUsername(), $this->communicationWebsiteUrl) ?? 'Thanks '.$player->getName().' to talk about us.'.\PHP_EOL.'But you already got a game link less than a day ago ! (talk again about us tomorrow to get a new game url)'.\PHP_EOL.'This is your previous game link : '.$this->communicationWebsiteUrl; $this->newReply($tweet->id, $message); } continue; @@ -236,12 +227,13 @@ 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'); $this->tweetRepository->removeAndFlush($recentTweet, true); $this->playerRepository->removeAndFlush($player, true); + return Command::FAILURE; } @@ -252,7 +244,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int if ($this->gameRepository->persistAndFlush($game, true)) { if ($input->getOption('reply')) { - $message = $this->tweetReplyRepository->findOneByName("on_new_game")?->getMessage($player->getName(), $player->getUsername(), $this->communicationWebsiteUrl) ?? 'Thanks ' . $player->getName() . ' to talk about us.' . PHP_EOL . 'We want to give you a little gift but to get it you must play a little game 😁' . PHP_EOL . $this->communicationWebsiteUrl; + $message = $this->tweetReplyRepository->findOneByName('on_new_game')?->getMessage($player->getName(), $player->getUsername(), $this->communicationWebsiteUrl) ?? 'Thanks '.$player->getName().' to talk about us.'.\PHP_EOL.'We want to give you a little gift but to get it you must play a little game 😁'.\PHP_EOL.$this->communicationWebsiteUrl; $this->newReply($tweet->id, $message); } } else { diff --git a/api/src/Controller/CreateMediaObjectActionController.php b/api/src/Controller/CreateMediaObjectActionController.php index 58bce9c..f0444af 100644 --- a/api/src/Controller/CreateMediaObjectActionController.php +++ b/api/src/Controller/CreateMediaObjectActionController.php @@ -1,5 +1,7 @@ copy($originPath, $targetPath, true); - $fs->touch($root . '/fixtures/test/files/invalid_file.txt'); - $fs->appendToFile($root . '/fixtures/test/files/invalid_file.txt', 'My invalid file !!!'); + $fs->touch($root.'/fixtures/test/files/invalid_file.txt'); + $fs->appendToFile($root.'/fixtures/test/files/invalid_file.txt', 'My invalid file !!!'); } /** - * @inheritdoc + * {@inheritdoc} */ public function postProcess(string $fixtureId, $object): void { diff --git a/api/src/Entity/Game.php b/api/src/Entity/Game.php index 8a57084..48b9650 100644 --- a/api/src/Entity/Game.php +++ b/api/src/Entity/Game.php @@ -1,15 +1,17 @@ true], - order: ["creationDate" => "DESC"], + mercure: ['private' => true], + order: ['creationDate' => 'DESC'], paginationClientItemsPerPage: true ) ] -#[ApiFilter(SearchFilter::class, properties: ["url" => "partial"])] -#[ApiFilter(DateFilter::class, properties: ["creationDate"])] +#[ApiFilter(SearchFilter::class, properties: ['url' => 'partial'])] +#[ApiFilter(DateFilter::class, properties: ['creationDate'])] #[ApiFilter(OrderFilter::class, properties: ['tweet', 'player.username', 'score', 'creationDate', 'playDate'])] class Game { #[ORM\Id] #[ORM\Column(name: 'id', type: 'uuid', unique: true)] - #[ORM\GeneratedValue(strategy: "CUSTOM")] - #[ORM\CustomIdGenerator(class: "doctrine.uuid_generator")] - #[ApiProperty(types: ["https://schema.org/identifier"])] + #[ORM\GeneratedValue(strategy: 'CUSTOM')] + #[ORM\CustomIdGenerator(class: 'doctrine.uuid_generator')] + #[ApiProperty(types: ['https://schema.org/identifier'])] private Uuid $id; #[ORM\OneToOne(targetEntity: Tweet::class, cascade: ['persist'])] #[ORM\JoinColumn(unique: true)] - #[ApiProperty(types: ["https://schema.org/SocialMediaPosting"])] + #[ApiProperty(types: ['https://schema.org/SocialMediaPosting'])] private ?Tweet $tweet = null; #[ORM\ManyToOne(targetEntity: Player::class)] private ?Player $player = null; #[ORM\Column(name: 'score', type: 'integer', nullable: true)] - #[ApiProperty(types: ["https://schema.org/Rating"])] + #[ApiProperty(types: ['https://schema.org/Rating'])] private ?int $score = null; #[ORM\Column(name: 'creation_date', type: 'datetime')] - #[ApiProperty(types: ["https://schema.org/dateCreated"])] + #[ApiProperty(types: ['https://schema.org/dateCreated'])] private ?\DateTime $creationDate = null; #[ORM\Column(name: 'play_date', type: 'datetime', nullable: true)] - #[ApiProperty(types: ["https://schema.org/DateTime"])] + #[ApiProperty(types: ['https://schema.org/DateTime'])] private ?\DateTime $playDate = null; #[ORM\OneToOne(targetEntity: Reward::class, cascade: ['persist', 'remove'])] diff --git a/api/src/Entity/Lot.php b/api/src/Entity/Lot.php index d0cd1c6..fdf1abc 100644 --- a/api/src/Entity/Lot.php +++ b/api/src/Entity/Lot.php @@ -1,17 +1,19 @@ ['deleteValidation']], processor: LotProcessor::class) + new Delete(validationContext: ['groups' => ['deleteValidation']], processor: LotProcessor::class), ], - mercure: ["private" => true], - order: ["name" => "ASC", "quantity" => "DESC"], + mercure: ['private' => true], + order: ['name' => 'ASC', 'quantity' => 'DESC'], paginationClientItemsPerPage: true )] -#[ApiFilter(SearchFilter::class, properties: ["name" => "ipartial"])] +#[ApiFilter(SearchFilter::class, properties: ['name' => 'ipartial'])] #[ApiFilter(OrderFilter::class, properties: ['name', 'quantity', 'message'])] class Lot { #[ORM\Id] #[ORM\Column(name: 'id', type: 'uuid', unique: true)] - #[ORM\GeneratedValue(strategy: "CUSTOM")] - #[ORM\CustomIdGenerator(class: "doctrine.uuid_generator")] - #[ApiProperty(types: ["https://schema.org/identifier"])] + #[ORM\GeneratedValue(strategy: 'CUSTOM')] + #[ORM\CustomIdGenerator(class: 'doctrine.uuid_generator')] + #[ApiProperty(types: ['https://schema.org/identifier'])] private Uuid $id; #[ORM\Column(name: 'name', type: 'string', length: 255)] #[Assert\NotBlank] - #[ApiProperty(types: ["https://schema.org/name"])] + #[ApiProperty(types: ['https://schema.org/name'])] private ?string $name = null; #[ORM\Column(name: 'quantity', type: 'integer')] #[Assert\NotBlank] #[Assert\PositiveOrZero] - #[ApiProperty(types: ["https://schema.org/Quantity"])] + #[ApiProperty(types: ['https://schema.org/Quantity'])] private ?int $quantity = null; #[ORM\Column(name: 'message', type: 'string')] #[Assert\NotBlank] - #[ApiProperty(description: 'Message that will be sent to players. To write the player name in the message, write : %player_name% and same for the userhandle to mention it : %@userhandle%', types: ["https://schema.org/Message"])] + #[ApiProperty(description: 'Message that will be sent to players. To write the player name in the message, write : %player_name% and same for the userhandle to mention it : %@userhandle%', types: ['https://schema.org/Message'])] private ?string $message = null; #[ORM\ManyToOne(targetEntity: MediaObject::class)] @@ -67,7 +69,7 @@ class Lot #[ApiProperty(types: ['https://schema.org/image'])] public ?MediaObject $image = null; - #[ORM\OneToMany(mappedBy: "lot", targetEntity: Reward::class)] + #[ORM\OneToMany(mappedBy: 'lot', targetEntity: Reward::class)] #[Assert\Count(exactly: 0, groups: ['deleteValidation'])] private Collection $rewards; @@ -104,12 +106,13 @@ public function setQuantity(int $quantity): void public function getMessage(?string $name = null, ?string $userhandle = null): ?string { if (null !== $name) { - return str_replace("%player_name%", $name, $this->message); + return str_replace('%player_name%', $name, $this->message); } if (null !== $userhandle) { - return str_replace("%@userhandle%", "@".$userhandle, $this->message); + return str_replace('%@userhandle%', '@'.$userhandle, $this->message); } + return $this->message; } diff --git a/api/src/Entity/MediaObject.php b/api/src/Entity/MediaObject.php index 6f4b6ae..bcd0cda 100644 --- a/api/src/Entity/MediaObject.php +++ b/api/src/Entity/MediaObject.php @@ -1,16 +1,18 @@ ['media_object:read']], - mercure: ["private" => true], - order: ["name" => "ASC"], + mercure: ['private' => true], + order: ['name' => 'ASC'], paginationClientItemsPerPage: true )] -#[ApiFilter(SearchFilter::class, properties: ["name" => "partial", "filePath" => "partial"])] +#[ApiFilter(SearchFilter::class, properties: ['name' => 'partial', 'filePath' => 'partial'])] #[ApiFilter(OrderFilter::class, properties: ['name', 'filePath'])] class MediaObject { #[ORM\Id] #[ORM\Column(name: 'id', type: 'uuid', unique: true)] - #[ORM\GeneratedValue(strategy: "CUSTOM")] - #[ORM\CustomIdGenerator(class: "doctrine.uuid_generator")] + #[ORM\GeneratedValue(strategy: 'CUSTOM')] + #[ORM\CustomIdGenerator(class: 'doctrine.uuid_generator')] private ?Uuid $id = null; #[ORM\Column(name: 'name', type: 'string', length: 255, unique: true)] @@ -90,15 +92,15 @@ class MediaObject #[Assert\NotNull(groups: ['media_object_create'])] #[Assert\NotBlank(groups: ['media_object_create'])] #[Assert\Image([ - 'maxSize' => "5M", + 'maxSize' => '5M', 'minWidth' => 100, 'maxWidth' => 2000, 'minHeight' => 100, 'maxHeight' => 2000, 'mimeTypes' => [ - "image/jpeg", - "image/jpg", - "image/png", + 'image/jpeg', + 'image/jpg', + 'image/png', ], ], groups: ['media_object_create'])] private ?File $file = null; @@ -121,36 +123,23 @@ public function setName(string $name): void $this->name = $name; } - /** - * @return File|null - */ public function getFile(): ?File { return $this->file; } - /** - * @param File|null $file - */ public function setFile(?File $file): void { $this->file = $file; } - /** - * @return string|null - */ public function getFilePath(): ?string { return $this->filePath; } - /** - * @param string|null $filePath - */ public function setFilePath(?string $filePath): void { $this->filePath = $filePath; } - } diff --git a/api/src/Entity/Player.php b/api/src/Entity/Player.php index 8d10131..c2a8f68 100644 --- a/api/src/Entity/Player.php +++ b/api/src/Entity/Player.php @@ -1,14 +1,16 @@ true], - order: ["name" => "ASC"], + mercure: ['private' => true], + order: ['name' => 'ASC'], paginationClientItemsPerPage: true )] -#[ApiFilter(SearchFilter::class, properties: ["username" => "ipartial", "name" => "ipartial"])] +#[ApiFilter(SearchFilter::class, properties: ['username' => 'ipartial', 'name' => 'ipartial'])] #[ApiFilter(OrderFilter::class, properties: ['name', 'username', 'lastPlayDate'])] class Player { #[ORM\Id] #[ORM\Column(name: 'id', type: 'uuid', unique: true)] - #[ORM\GeneratedValue(strategy: "CUSTOM")] - #[ORM\CustomIdGenerator(class: "doctrine.uuid_generator")] - #[ApiProperty(types: ["https://schema.org/identifier"])] + #[ORM\GeneratedValue(strategy: 'CUSTOM')] + #[ORM\CustomIdGenerator(class: 'doctrine.uuid_generator')] + #[ApiProperty(types: ['https://schema.org/identifier'])] private Uuid $id; #[ORM\Column(name: 'name', type: 'string', length: 255)] - #[ApiProperty(types: ["https://schema.org/name"])] + #[ApiProperty(types: ['https://schema.org/name'])] private ?string $name = null; #[ORM\Column(name: 'username', type: 'string', length: 255, unique: true)] private ?string $username = null; #[ORM\Column(name: 'twitter_account_id', type: 'string', length: 255, unique: true)] - #[ApiProperty(writable: false, types: ["https://schema.org/identifier"])] + #[ApiProperty(writable: false, types: ['https://schema.org/identifier'])] private ?string $twitterAccountId = null; #[ORM\Column(name: 'last_play_date', type: 'datetime', nullable: true)] - #[ApiProperty(writable: false, types: ["https://schema.org/DateTime"])] + #[ApiProperty(writable: false, types: ['https://schema.org/DateTime'])] private ?\DateTime $lastPlayDate = null; #[ORM\OneToMany(mappedBy: 'player', targetEntity: Tweet::class, orphanRemoval: true)] - #[ApiProperty(readable: false, writable: false, types: ["https://schema.org/Collection"])] + #[ApiProperty(readable: false, writable: false, types: ['https://schema.org/Collection'])] private Collection $tweets; public function __construct() @@ -68,17 +70,11 @@ public function getId(): Uuid return $this->id; } - /** - * @return string|null - */ public function getName(): ?string { return $this->name; } - /** - * @param string|null $name - */ public function setName(?string $name): void { $this->name = $name; diff --git a/api/src/Entity/Reward.php b/api/src/Entity/Reward.php index 2d0c1bf..da2762e 100644 --- a/api/src/Entity/Reward.php +++ b/api/src/Entity/Reward.php @@ -1,14 +1,16 @@ true], - order: ["distributed" => "ASC"], + mercure: ['private' => true], + order: ['distributed' => 'ASC'], paginationClientItemsPerPage: true )] -#[ApiFilter(BooleanFilter::class, properties: ["distributed" => "exact"])] +#[ApiFilter(BooleanFilter::class, properties: ['distributed' => 'exact'])] #[ApiFilter(OrderFilter::class, properties: ['distributed'])] class Reward { #[ORM\Id] #[ORM\Column(name: 'id', type: 'uuid', unique: true)] - #[ORM\GeneratedValue(strategy: "CUSTOM")] - #[ORM\CustomIdGenerator(class: "doctrine.uuid_generator")] - #[ApiProperty(types: ["https://schema.org/identifier"])] + #[ORM\GeneratedValue(strategy: 'CUSTOM')] + #[ORM\CustomIdGenerator(class: 'doctrine.uuid_generator')] + #[ApiProperty(types: ['https://schema.org/identifier'])] private Uuid $id; - #[ORM\ManyToOne(targetEntity: Lot::class, inversedBy: "rewards")] + #[ORM\ManyToOne(targetEntity: Lot::class, inversedBy: 'rewards')] #[ApiProperty(writable: false)] private ?Lot $lot = null; diff --git a/api/src/Entity/Tweet.php b/api/src/Entity/Tweet.php index b74f832..2f3d20d 100644 --- a/api/src/Entity/Tweet.php +++ b/api/src/Entity/Tweet.php @@ -1,5 +1,7 @@ true], + mercure: ['private' => true], paginationClientItemsPerPage: true )] class Tweet { #[ORM\Id] #[ORM\Column(name: 'id', type: 'uuid', unique: true)] - #[ORM\GeneratedValue(strategy: "CUSTOM")] - #[ORM\CustomIdGenerator(class: "doctrine.uuid_generator")] - #[ApiProperty(types: ["https://schema.org/identifier"])] + #[ORM\GeneratedValue(strategy: 'CUSTOM')] + #[ORM\CustomIdGenerator(class: 'doctrine.uuid_generator')] + #[ApiProperty(types: ['https://schema.org/identifier'])] private Uuid $id; #[ORM\ManyToOne(targetEntity: Player::class, inversedBy: 'tweets')] private ?Player $player = null; #[ORM\Column(name: 'tweet_id', type: 'string', length: 255, unique: true)] - #[ApiProperty(types: ["https://schema.org/identifier"])] + #[ApiProperty(types: ['https://schema.org/identifier'])] private ?string $tweetId = null; public function getId(): Uuid diff --git a/api/src/Entity/TweetReply.php b/api/src/Entity/TweetReply.php index abb443d..fca43ac 100644 --- a/api/src/Entity/TweetReply.php +++ b/api/src/Entity/TweetReply.php @@ -1,17 +1,19 @@ true], - order: ["name" => "ASC"], + mercure: ['private' => true], + order: ['name' => 'ASC'], paginationClientItemsPerPage: true )] -#[ApiFilter(SearchFilter::class, properties: ["name" => "partial"])] +#[ApiFilter(SearchFilter::class, properties: ['name' => 'partial'])] #[ApiFilter(OrderFilter::class, properties: ['name', 'message'])] class TweetReply { #[ORM\Id] #[ORM\Column(name: 'id', type: 'uuid', unique: true)] - #[ORM\GeneratedValue(strategy: "CUSTOM")] - #[ORM\CustomIdGenerator(class: "doctrine.uuid_generator")] - #[ApiProperty(types: ["https://schema.org/identifier"])] + #[ORM\GeneratedValue(strategy: 'CUSTOM')] + #[ORM\CustomIdGenerator(class: 'doctrine.uuid_generator')] + #[ApiProperty(types: ['https://schema.org/identifier'])] private Uuid $id; #[ORM\Column(name: 'name', type: 'string', length: 255, unique: true)] #[Assert\NotBlank] - #[ApiProperty(types: ["https://schema.org/name"])] + #[ApiProperty(types: ['https://schema.org/name'])] private ?string $name = null; #[ORM\Column(name: 'message', type: 'string')] #[Assert\NotBlank] - #[ApiProperty(description: 'Message that will be sent to players. To write the player name in the message, write : %player_name%, same for the userhandle mention : %@userhandle%, and same for communication website link : %website_url%', types: ["https://schema.org/Message"])] + #[ApiProperty(description: 'Message that will be sent to players. To write the player name in the message, write : %player_name%, same for the userhandle mention : %@userhandle%, and same for communication website link : %website_url%', types: ['https://schema.org/Message'])] private ?string $message = null; public function getId(): Uuid @@ -58,48 +60,33 @@ public function getId(): Uuid return $this->id; } - /** - * @return string|null - */ public function getName(): ?string { return $this->name; } - /** - * @param string|null $name - */ public function setName(?string $name): void { $this->name = $name; } - /** - * @param string|null $name - * @param string|null $userhandle - * @param string|null $gameLink - * @return string|null - */ public function getMessage(?string $name = null, ?string $userhandle = null, ?string $gameLink = null): ?string { if (null !== $name) { - return str_replace("%player_name%", $name, $this->message); + return str_replace('%player_name%', $name, $this->message); } if (null !== $userhandle) { - return str_replace("%@userhandle%", "@".$userhandle, $this->message); + return str_replace('%@userhandle%', '@'.$userhandle, $this->message); } if (null !== $gameLink) { - return str_replace("%website_url%", $gameLink ?? 'no_link', $this->message); + return str_replace('%website_url%', $gameLink ?? 'no_link', $this->message); } return $this->message; } - /** - * @param string|null $message - */ public function setMessage(?string $message): void { $this->message = $message; diff --git a/api/src/Entity/TwitterAccountToFollow.php b/api/src/Entity/TwitterAccountToFollow.php index 0ded77e..a38817f 100644 --- a/api/src/Entity/TwitterAccountToFollow.php +++ b/api/src/Entity/TwitterAccountToFollow.php @@ -1,25 +1,27 @@ true], - order: ["active" => "DESC", "twitterAccountName" => "ASC"], + mercure: ['private' => true], + order: ['active' => 'DESC', 'twitterAccountName' => 'ASC'], paginationClientItemsPerPage: true )] -#[ApiFilter(SearchFilter::class, properties: ["twitterAccountName" => "ipartial", "twitterAccountUsername" => "ipartial"])] -#[ApiFilter(BooleanFilter::class, properties: ["active" => "exact"])] +#[ApiFilter(SearchFilter::class, properties: ['twitterAccountName' => 'ipartial', 'twitterAccountUsername' => 'ipartial'])] +#[ApiFilter(BooleanFilter::class, properties: ['active' => 'exact'])] #[ApiFilter(OrderFilter::class, properties: ['twitterAccountName', 'twitterAccountUsername', 'active'])] class TwitterAccountToFollow { #[ORM\Id] #[ORM\Column(name: 'id', type: 'uuid', unique: true)] - #[ORM\GeneratedValue(strategy: "CUSTOM")] - #[ORM\CustomIdGenerator(class: "doctrine.uuid_generator")] - #[ApiProperty(types: ["https://schema.org/identifier"])] + #[ORM\GeneratedValue(strategy: 'CUSTOM')] + #[ORM\CustomIdGenerator(class: 'doctrine.uuid_generator')] + #[ApiProperty(types: ['https://schema.org/identifier'])] private Uuid $id; #[ORM\Column(name: 'twitter_account_name', type: 'string', length: 255)] - #[ApiProperty(writable: false, types: ["https://schema.org/name"])] + #[ApiProperty(writable: false, types: ['https://schema.org/name'])] private ?string $twitterAccountName = null; #[ORM\Column(name: 'twitter_account_username', type: 'string', length: 255, unique: true)] @@ -58,7 +60,7 @@ class TwitterAccountToFollow private ?string $twitterAccountUsername = null; #[ORM\Column(name: 'twitter_account_id', type: 'string', length: 255, unique: true)] - #[ApiProperty(writable: false, types: ["https://schema.org/identifier"])] + #[ApiProperty(writable: false, types: ['https://schema.org/identifier'])] private ?string $twitterAccountId = null; #[ORM\Column(name: 'active', type: 'boolean')] @@ -69,70 +71,46 @@ public function getId(): Uuid return $this->id; } - /** - * @return string|null - */ public function getTwitterAccountName(): ?string { return $this->twitterAccountName; } - /** - * @param string|null $twitterAccountName - */ public function setTwitterAccountName(?string $twitterAccountName): void { $this->twitterAccountName = $twitterAccountName; } - /** - * @return string|null - */ public function getTwitterAccountUsername(): ?string { return $this->twitterAccountUsername; } - /** - * @param string|null $twitterAccountUsername - */ public function setTwitterAccountUsername(?string $twitterAccountUsername): void { $twitterAccountUsername = str_replace(' ', '', $twitterAccountUsername); - if($twitterAccountUsername[0] !== '@') { - $twitterAccountUsername = '@' . $twitterAccountUsername; + if ('@' !== $twitterAccountUsername[0]) { + $twitterAccountUsername = '@'.$twitterAccountUsername; } $this->twitterAccountUsername = $twitterAccountUsername; } - /** - * @return string|null - */ public function getTwitterAccountId(): ?string { return $this->twitterAccountId; } - /** - * @param string|null $twitterAccountId - */ public function setTwitterAccountId(?string $twitterAccountId): void { $this->twitterAccountId = $twitterAccountId; } - /** - * @return bool - */ public function isActive(): bool { return $this->active; } - /** - * @param bool $active - */ public function setActive(bool $active): void { $this->active = $active; diff --git a/api/src/Entity/TwitterHashtag.php b/api/src/Entity/TwitterHashtag.php index 0ce5bb1..934531a 100644 --- a/api/src/Entity/TwitterHashtag.php +++ b/api/src/Entity/TwitterHashtag.php @@ -1,18 +1,20 @@ true], - order: ["active" => "DESC", "hashtag" => "ASC"], + mercure: ['private' => true], + order: ['active' => 'DESC', 'hashtag' => 'ASC'], paginationClientItemsPerPage: true )] -#[ApiFilter(SearchFilter::class, properties: ["hashtag" => "ipartial"])] -#[ApiFilter(BooleanFilter::class, properties: ["active" => "exact"])] +#[ApiFilter(SearchFilter::class, properties: ['hashtag' => 'ipartial'])] +#[ApiFilter(BooleanFilter::class, properties: ['active' => 'exact'])] #[ApiFilter(OrderFilter::class, properties: ['hashtag', 'active'])] class TwitterHashtag { #[ORM\Id] #[ORM\Column(name: 'id', type: 'uuid', unique: true)] - #[ORM\GeneratedValue(strategy: "CUSTOM")] - #[ORM\CustomIdGenerator(class: "doctrine.uuid_generator")] - #[ApiProperty(types: ["https://schema.org/identifier"])] + #[ORM\GeneratedValue(strategy: 'CUSTOM')] + #[ORM\CustomIdGenerator(class: 'doctrine.uuid_generator')] + #[ApiProperty(types: ['https://schema.org/identifier'])] private Uuid $id; #[ORM\Column(name: 'hashtag', type: 'string', length: 255, unique: true)] @@ -57,38 +59,26 @@ public function getId(): Uuid return $this->id; } - /** - * @return string|null - */ public function getHashtag(): ?string { return $this->hashtag; } - /** - * @param string|null $hashtag - */ public function setHashtag(?string $hashtag): void { $hashtag = str_replace(' ', '', $hashtag); - if($hashtag[0] !== '#') { - $hashtag = '#' . $hashtag; + if ('#' !== $hashtag[0]) { + $hashtag = '#'.$hashtag; } $this->hashtag = $hashtag; } - /** - * @return bool - */ public function isActive(): bool { return $this->active; } - /** - * @param bool $active - */ public function setActive(bool $active): void { $this->active = $active; diff --git a/api/src/Kernel.php b/api/src/Kernel.php index 779cd1f..ad0fb48 100644 --- a/api/src/Kernel.php +++ b/api/src/Kernel.php @@ -1,5 +1,7 @@ getEntityManager()->flush(); } + return null; } diff --git a/api/src/Repository/GameRepository.php b/api/src/Repository/GameRepository.php index a13cf01..185aef4 100644 --- a/api/src/Repository/GameRepository.php +++ b/api/src/Repository/GameRepository.php @@ -1,5 +1,7 @@ findOneByPlayer($entity->getPlayer()); - if (null !== $lastGame && date_diff($lastGame->getCreationDate(), new \DateTime)->d < 1) { + if (null !== $lastGame && date_diff($lastGame->getCreationDate(), new \DateTime())->d < 1) { return false; } - $entity->setCreationDate(new \DateTime); + $entity->setCreationDate(new \DateTime()); $this->getEntityManager()->persist($entity); if ($flush) { diff --git a/api/src/Repository/LotRepository.php b/api/src/Repository/LotRepository.php index 952c5c7..eca69ec 100644 --- a/api/src/Repository/LotRepository.php +++ b/api/src/Repository/LotRepository.php @@ -1,5 +1,7 @@ getQuantity() <= 0) { @@ -54,11 +56,12 @@ public function getRandom(int $numberOfLotReturn = 1): array $randomNumber = random_int(0, $totalQuantity - 1); - $filteredLots = array_filter($lots, static fn(Lot $lot) => $lot->min <= $randomNumber && $lot->max > $randomNumber); + $filteredLots = array_filter($lots, static fn (Lot $lot) => $lot->min <= $randomNumber && $lot->max > $randomNumber); $lot = reset($filteredLots); if (false === $lot) { $this->logger->warning('No Lot found during random Lot search !'); + return $dataReturn; } diff --git a/api/src/Repository/MediaObjectRepository.php b/api/src/Repository/MediaObjectRepository.php index f9a8554..b6868eb 100644 --- a/api/src/Repository/MediaObjectRepository.php +++ b/api/src/Repository/MediaObjectRepository.php @@ -1,5 +1,7 @@ setParameter('val', $value) ->setMaxResults(1) ->getQuery() - ->getOneOrNullResult() - ; + ->getOneOrNullResult(); } } diff --git a/api/src/Repository/RewardRepository.php b/api/src/Repository/RewardRepository.php index 64dd4aa..0209ee2 100644 --- a/api/src/Repository/RewardRepository.php +++ b/api/src/Repository/RewardRepository.php @@ -1,5 +1,7 @@ setParameter('val', $value) ->setMaxResults(1) ->getQuery() - ->getOneOrNullResult() - ; + ->getOneOrNullResult(); } } diff --git a/api/src/Repository/TwitterAccountToFollowRepository.php b/api/src/Repository/TwitterAccountToFollowRepository.php index eb57253..477eb61 100644 --- a/api/src/Repository/TwitterAccountToFollowRepository.php +++ b/api/src/Repository/TwitterAccountToFollowRepository.php @@ -1,5 +1,7 @@ andWhere('t.active = :active') ->setParameter('active', true) ->getQuery() - ->getResult() - ; + ->getResult(); } } diff --git a/api/src/Repository/TwitterHashtagRepository.php b/api/src/Repository/TwitterHashtagRepository.php index 0deff7c..afbb17b 100644 --- a/api/src/Repository/TwitterHashtagRepository.php +++ b/api/src/Repository/TwitterHashtagRepository.php @@ -1,5 +1,7 @@ andWhere('t.active = :active') ->setParameter('active', true) ->getQuery() - ->getResult() - ; + ->getResult(); } } diff --git a/api/src/Serializer/MediaObjectNormalizer.php b/api/src/Serializer/MediaObjectNormalizer.php index c7245f9..91e3b8c 100644 --- a/api/src/Serializer/MediaObjectNormalizer.php +++ b/api/src/Serializer/MediaObjectNormalizer.php @@ -1,5 +1,7 @@ getMethod() === 'DELETE') { - $violations = $this->validator->validate($data, null, $operation->getValidationContext()["groups"]); + if ($data instanceof Lot && 'DELETE' === $context['operation']->getMethod()) { + $violations = $this->validator->validate($data, null, $operation->getValidationContext()['groups']); if (0 !== \count($violations)) { throw new ValidationException($violations); } diff --git a/api/src/State/TwitterAccountToFollowProcessor.php b/api/src/State/TwitterAccountToFollowProcessor.php index f38ddd9..7cbb249 100644 --- a/api/src/State/TwitterAccountToFollowProcessor.php +++ b/api/src/State/TwitterAccountToFollowProcessor.php @@ -19,16 +19,13 @@ public function __construct(private readonly PersistProcessor $persistProcessor, /** * @param $data - * @param Operation $operation - * @param array $uriVariables - * @param array $context - * @return object + * * @throws TwitterOAuthException */ public function process($data, Operation $operation, array $uriVariables = [], array $context = []): object { - if ($data instanceof TwitterAccountToFollow && ($context['operation']->getMethod() === 'POST' || $context['operation']->getMethod() === 'PUT')) { - $user = $this->twitterApi->get('users/by/username/' . substr($data->getTwitterAccountUsername(), 1)); + if ($data instanceof TwitterAccountToFollow && ('POST' === $context['operation']->getMethod() || 'PUT' === $context['operation']->getMethod())) { + $user = $this->twitterApi->get('users/by/username/'.substr($data->getTwitterAccountUsername(), 1)); $data->setTwitterAccountId($user->data->id); $data->setTwitterAccountName($user->data->name); diff --git a/api/src/Twitter/TwitterApi.php b/api/src/Twitter/TwitterApi.php index 0ac23d8..1ffc0b7 100644 --- a/api/src/Twitter/TwitterApi.php +++ b/api/src/Twitter/TwitterApi.php @@ -17,13 +17,9 @@ public function __construct( private readonly string $twitterConsumerSecret, private readonly string $twitterAccessToken, private readonly string $twitterAccessTokenSecret - ) - { + ) { } - /** - * @return TwitterOAuth - */ private function getConnection(): TwitterOAuth { return new TwitterOAuth($this->twitterConsumerKey, $this->twitterConsumerSecret, $this->twitterAccessToken, $this->twitterAccessTokenSecret); @@ -36,7 +32,7 @@ public function get(string $url, array $params = [], string $apiVersion = '2'): { $request = serialize([$url, $params]); - if($response = $this->memoize[$request] ?? null) { + if ($response = $this->memoize[$request] ?? null) { return $response; } @@ -44,8 +40,9 @@ public function get(string $url, array $params = [], string $apiVersion = '2'): $connection->setApiVersion($apiVersion); $response = $connection->get($url, $params); - if ($connection->getLastHttpCode() === 200) { + if (200 === $connection->getLastHttpCode()) { $this->memoize[$request] = $response; + return $response; } @@ -61,7 +58,7 @@ public function post(string $url, array $params = [], bool $json = true, string $connection->setApiVersion($apiVersion); $response = $connection->post($url, $params, $json); - if ($connection->getLastHttpCode() === 201) { + if (201 === $connection->getLastHttpCode()) { return $response; } diff --git a/api/src/Validator/ExistsInTwitter.php b/api/src/Validator/ExistsInTwitter.php index be5f6a3..e749179 100644 --- a/api/src/Validator/ExistsInTwitter.php +++ b/api/src/Validator/ExistsInTwitter.php @@ -4,7 +4,6 @@ namespace App\Validator; -use Symfony\Component\Validator\Attribute\HasNamedArguments; use Symfony\Component\Validator\Constraint; #[\Attribute] diff --git a/api/src/Validator/ExistsInTwitterValidator.php b/api/src/Validator/ExistsInTwitterValidator.php index 223293f..b4cfd58 100644 --- a/api/src/Validator/ExistsInTwitterValidator.php +++ b/api/src/Validator/ExistsInTwitterValidator.php @@ -20,7 +20,7 @@ public function __construct(private TwitterApi $twitterApi) /** * @throws TwitterOAuthException */ - public function validate($username, Constraint $constraint) + public function validate($username, Constraint $constraint): void { if (!$constraint instanceof ExistsInTwitter) { throw new UnexpectedTypeException($constraint, ExistsInTwitter::class); @@ -32,17 +32,16 @@ public function validate($username, Constraint $constraint) return; } - if (!is_string($username)) { + if (!\is_string($username)) { // throw this exception if your validator cannot handle the passed type so that it can be marked as invalid throw new UnexpectedValueException($username, 'string'); - // separate multiple types using pipes // throw new UnexpectedValueException($username, 'string|int'); } - $user = $this->twitterApi->get('users/by/username/' . substr($username, 1)); + $user = $this->twitterApi->get('users/by/username/'.substr($username, 1)); - if (property_exists($user, "errors")) { + if (property_exists($user, 'errors')) { // the argument must be a string or an object implementing __toString() $this->context->buildViolation($constraint->message) ->setParameter('{{ username }}', $username)