Skip to content
This repository was archived by the owner on Dec 14, 2024. It is now read-only.

Update phpqa image #92

Merged
merged 4 commits into from
Jul 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
before_install:
- make pull-docker-image
script:
- make php-cs-fixer
- make php-cs-fixer-dry-run
- name: "phpstan"
before_install:
- make pull-docker-image
Expand Down
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PHP = php

DOCKER_RUN = docker run --volume $(PWD):/app --workdir /app jakzal/phpqa:1.25-php7.2-alpine
DOCKER_RUN = docker run --rm --interactive --tty --volume $(PWD):/app --workdir /app jakzal/phpqa:php7.3-alpine

##
## Dependencies
Expand Down Expand Up @@ -38,10 +38,13 @@ tests: phpspec phpunit behat ## Run all tests
##

php-cs-fixer: ## PHP-CS-Fixer
$(DOCKER_RUN) php-cs-fixer fix src/

php-cs-fixer-dry-run: ## PHP-CS-Fixer
$(DOCKER_RUN) php-cs-fixer fix src/ --dry-run

phpstan: ## PHPStan
$(DOCKER_RUN) phpstan analyse --level 6 src/ --no-progress
$(DOCKER_RUN) phpstan analyse --no-progress

qa: php-cs-fixer phpstan ## Run all QA tasks

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
"phpspec/phpspec": "~4.2||~5.0||^6.2",
"doctrine/data-fixtures": "^1.3",
"nelmio/alice": "^3.4",
"behatch/contexts": "^3.1"
"behatch/contexts": "^3.1",
"phpstan/phpstan-doctrine": "^0.12.17"
},
"autoload" : {
"psr-4" : {
Expand Down
11 changes: 11 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
parameters:
level: 8
paths:
- src
# - tests
excludes_analyse:
- tests/App/var/
# - tests/spec/

includes:
- vendor/phpstan/phpstan-doctrine/extension.neon
8 changes: 6 additions & 2 deletions src/Command/BaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@

namespace AlexisLefebvre\Bundle\AsyncTweetsBundle\Command;

use Doctrine\Persistence\ObjectManager;
use Symfony\Bridge\Doctrine\ManagerRegistry;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

class BaseCommand extends ContainerAwareCommand
{
/** @var ContainerInterface */
protected $container;
/** @var ObjectManager */
protected $em;

protected function configure()
protected function configure(): void
{
parent::configure();

Expand All @@ -21,7 +25,7 @@ protected function configure()
->setDescription('Base command');
}

protected function initialize(InputInterface $input, OutputInterface $output)
protected function initialize(InputInterface $input, OutputInterface $output): void
{
parent::initialize($input, $output); //initialize parent class method

Expand Down
74 changes: 33 additions & 41 deletions src/Command/StatusesHomeTimelineCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace AlexisLefebvre\Bundle\AsyncTweetsBundle\Command;

use Abraham\TwitterOAuth\TwitterOAuth;
use AlexisLefebvre\Bundle\AsyncTweetsBundle\Entity\Tweet;
use AlexisLefebvre\Bundle\AsyncTweetsBundle\Entity\TweetRepository;
use AlexisLefebvre\Bundle\AsyncTweetsBundle\Utils\PersistTweet;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Helper\Table;
Expand All @@ -12,17 +14,24 @@

class StatusesHomeTimelineCommand extends BaseCommand
{
/** @var bool */
private $displayTable;
/** @var Table */
private $table;
/** @var ProgressBar */
private $progress;

/** @see https://dev.twitter.com/rest/reference/get/statuses/home_timeline */
/**
* @var array<bool|int>
*
* @see https://dev.twitter.com/rest/reference/get/statuses/home_timeline
*/
private $parameters = [
'count' => 200,
'exclude_replies' => true,
];

protected function configure()
protected function configure(): void
{
parent::configure();

Expand All @@ -38,13 +47,7 @@ protected function configure()
);
}

/**
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int|void
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->setAndDisplayLastTweet($output);

Expand All @@ -65,17 +68,18 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

$this->addAndDisplayTweets($input, $output, $content, $numberOfTweets);

return 0;
}

/**
* @param OutputInterface $output
*/
protected function setAndDisplayLastTweet(OutputInterface $output)
protected function setAndDisplayLastTweet(OutputInterface $output): void
{
/** @var TweetRepository $tweetRepository */
$tweetRepository = $this->em
->getRepository(Tweet::class);

// Get the last tweet
$lastTweet = $this->em
->getRepository('AsyncTweetsBundle:Tweet')
->getLastTweet();
$lastTweet = $tweetRepository->getLastTweet();

// And use it in the request if it exists
if ($lastTweet) {
Expand All @@ -90,7 +94,7 @@ protected function setAndDisplayLastTweet(OutputInterface $output)
}

/**
* @param InputInterface $input
* @return array<\stdClass>|object
*/
protected function getContent(InputInterface $input)
{
Expand All @@ -108,13 +112,12 @@ protected function getContent(InputInterface $input)
}

/**
* @param OutputInterface $output
* @param null|object $content
* @param array<string>|object $content
*/
protected function displayContentNotArrayError(
OutputInterface $output,
$content
) {
): void {
$formatter = $this->getHelper('formatter');

$errorMessages = ['Error!', 'Something went wrong, $content is not an array.'];
Expand All @@ -124,17 +127,14 @@ protected function displayContentNotArrayError(
}

/**
* @param InputInterface $input
* @param OutputInterface $output
* @param array $content
* @param int $numberOfTweets
* @param array<\stdClass> $content
*/
protected function addAndDisplayTweets(
InputInterface $input,
OutputInterface $output,
$content,
$numberOfTweets
) {
array $content,
int $numberOfTweets
): void {
$output->writeln('<comment>Number of tweets: '.$numberOfTweets.'</comment>');

// Iterate through $content in order to add the oldest tweet first,
Expand All @@ -154,28 +154,20 @@ protected function addAndDisplayTweets(
}
}

/**
* @param OutputInterface $output
* @param int $numberOfTweets
*/
protected function setProgressBar(
OutputInterface $output,
$numberOfTweets
) {
int $numberOfTweets
): void {
$this->progress = new ProgressBar($output, $numberOfTweets);
$this->progress->setBarCharacter('<comment>=</comment>');
$this->progress->start();
}

/**
* @param InputInterface $input
* @param OutputInterface $output
*/
protected function setTable(
InputInterface $input,
OutputInterface $output
) {
$this->displayTable = $input->getOption('table');
): void {
$this->displayTable = (bool) $input->getOption('table');

// Display
if ($this->displayTable) {
Expand All @@ -186,9 +178,9 @@ protected function setTable(
}

/**
* @param array $tweets
* @param array<\stdClass> $tweets
*/
protected function iterateTweets($tweets)
protected function iterateTweets(array $tweets): void
{
$persistTweet = new PersistTweet(
$this->em,
Expand Down
42 changes: 17 additions & 25 deletions src/Command/StatusesReadCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@

namespace AlexisLefebvre\Bundle\AsyncTweetsBundle\Command;

use AlexisLefebvre\Bundle\AsyncTweetsBundle\Entity\Tweet;
use AlexisLefebvre\Bundle\AsyncTweetsBundle\Entity\TweetRepository;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class StatusesReadCommand extends BaseCommand
{
/** @var Table */
private $table;

protected function configure()
protected function configure(): void
{
parent::configure();

Expand All @@ -21,15 +24,9 @@ protected function configure()
->addArgument('page', InputArgument::OPTIONAL, 'Page');
}

/**
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int|void
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
/** @var int|null $page */
/** @var int $page */
$page = $input->getArgument('page');

if ($page < 1) {
Expand All @@ -41,10 +38,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
$page
));

/** @var TweetRepository $tweetRepository */
$tweetRepository = $this->em
->getRepository(Tweet::class);
// Get the tweets
$tweets = $this->em
->getRepository('AsyncTweetsBundle:Tweet')
->getWithUsers($page);
$tweets = $tweetRepository->getWithUsers($page);

if (!$tweets) {
$output->writeln('<info>No tweet to display.</info>');
Expand All @@ -53,16 +51,17 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

$this->displayTweets($output, $tweets);

return 0;
}

/**
* @param OutputInterface $output
* @param array $tweets
* @param array<Tweet> $tweets
*/
protected function displayTweets(
OutputInterface $output,
$tweets
) {
array $tweets
): void {
$this->setTable($output);

foreach ($tweets as $tweet) {
Expand Down Expand Up @@ -90,7 +89,7 @@ protected function displayTweets(
$this->table->render();
}

protected function setTable(OutputInterface $output)
protected function setTable(OutputInterface $output): void
{
$this->table = new Table($output);
$this->table
Expand All @@ -103,14 +102,7 @@ protected function setTable(OutputInterface $output)
]);
}

/**
* @param string $tag
* @param string $content
* @param int $length
*
* @return string
*/
protected function formatCell($tag, $content, $length)
protected function formatCell(string $tag, string $content, int $length): string
{
return '<'.$tag.'>'.
// Close and reopen the tag before each new line
Expand Down
10 changes: 4 additions & 6 deletions src/Command/StatusesShowCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class StatusesShowCommand extends BaseCommand
{
protected function configure()
protected function configure(): void
{
parent::configure();

Expand All @@ -19,11 +19,7 @@ protected function configure()
->addArgument('tweet_id', InputArgument::REQUIRED, 'Tweet ID');
}

/**
* @param InputInterface $input
* @param OutputInterface $output
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
/** @var int|null $tweet_id */
$tweet_id = $input->getArgument('tweet_id');
Expand All @@ -42,5 +38,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
)));

$output->writeln($json);

return 0;
}
}
Loading