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

Commit

Permalink
style: cs-fixer
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeKESTEMAN committed Aug 5, 2022
1 parent 6c618cd commit 693eaf2
Show file tree
Hide file tree
Showing 31 changed files with 311 additions and 267 deletions.
2 changes: 2 additions & 0 deletions api/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,5 @@ yarn-error.log
###> php/scripts ###
/mercureJWTGenerator.php
###< php/scripts ###

/.php-cs-fixer.cache
91 changes: 91 additions & 0 deletions api/.php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php

declare(strict_types=1);

$finder = PhpCsFixer\Finder::create()
->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);
50 changes: 21 additions & 29 deletions api/src/Command/TwitterApiRecentTweetsCommand.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Command;

use Abraham\TwitterOAuth\TwitterOAuthException;
Expand Down Expand Up @@ -49,34 +51,29 @@ protected function configure(): void
}

/**
* @param string $hashtag
* @return stdClass|null
* @throws TwitterOAuthException
*/
private function getRecentTweets(string $hashtag): ?stdClass
{
$params = [
'query' => $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) {
Expand All @@ -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;
}

Expand All @@ -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) {
Expand All @@ -115,9 +113,6 @@ private function following(string $userId): bool
}

/**
* @param stdClass $user
* @param stdClass $tweet
* @return void
* @throws NonUniqueResultException
* @throws TwitterOAuthException
*/
Expand All @@ -127,32 +122,28 @@ 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
{
$params = [
'text' => $message,
'reply' => [
'in_reply_to_tweet_id' => $tweetId
]
'in_reply_to_tweet_id' => $tweetId,
],
];

$this->twitterApi->post('tweets', $params);
Expand All @@ -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;
Expand All @@ -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;
}

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

Expand All @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions api/src/Controller/CreateMediaObjectActionController.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 Down
20 changes: 10 additions & 10 deletions api/src/DataFixtures/Processor/MediaObjectProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,34 @@
final class MediaObjectProcessor implements ProcessorInterface
{
/**
* @inheritdoc
* {@inheritdoc}
*/
public function preProcess(string $fixtureId, $object): void
{
if (!$object instanceof MediaObject) {
return;
}

if ($_ENV['APP_ENV'] !== 'test') {
if ('test' !== $_ENV['APP_ENV']) {
return;
}

$fs = new Filesystem();

$root = explode("/", __DIR__);
$root = array_slice($root, 0, -3);
$root = implode("/", $root);
$root = explode('/', __DIR__);
$root = \array_slice($root, 0, -3);
$root = implode('/', $root);

$originPath = $root . '/fixtures/test/files/image.jpg';
$targetPath = $root . '/fixtures/test/files/test_image.jpg';
$originPath = $root.'/fixtures/test/files/image.jpg';
$targetPath = $root.'/fixtures/test/files/test_image.jpg';
$fs->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
{
Expand Down
Loading

0 comments on commit 693eaf2

Please sign in to comment.