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

Commit 1929d32

Browse files
Merge pull request #92 from alexislefebvre/update-phpqa-image
Update phpqa image
2 parents a589f86 + 21bed13 commit 1929d32

20 files changed

+257
-454
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
before_install:
3636
- make pull-docker-image
3737
script:
38-
- make php-cs-fixer
38+
- make php-cs-fixer-dry-run
3939
- name: "phpstan"
4040
before_install:
4141
- make pull-docker-image

Makefile

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
PHP = php
22

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

55
##
66
## Dependencies
@@ -38,10 +38,13 @@ tests: phpspec phpunit behat ## Run all tests
3838
##
3939

4040
php-cs-fixer: ## PHP-CS-Fixer
41+
$(DOCKER_RUN) php-cs-fixer fix src/
42+
43+
php-cs-fixer-dry-run: ## PHP-CS-Fixer
4144
$(DOCKER_RUN) php-cs-fixer fix src/ --dry-run
4245

4346
phpstan: ## PHPStan
44-
$(DOCKER_RUN) phpstan analyse --level 6 src/ --no-progress
47+
$(DOCKER_RUN) phpstan analyse --no-progress
4548

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

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
"phpspec/phpspec": "~4.2||~5.0||^6.2",
3939
"doctrine/data-fixtures": "^1.3",
4040
"nelmio/alice": "^3.4",
41-
"behatch/contexts": "^3.1"
41+
"behatch/contexts": "^3.1",
42+
"phpstan/phpstan-doctrine": "^0.12.17"
4243
},
4344
"autoload" : {
4445
"psr-4" : {

phpstan.neon

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
parameters:
2+
level: 8
3+
paths:
4+
- src
5+
# - tests
6+
excludes_analyse:
7+
- tests/App/var/
8+
# - tests/spec/
9+
10+
includes:
11+
- vendor/phpstan/phpstan-doctrine/extension.neon

src/Command/BaseCommand.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,21 @@
22

33
namespace AlexisLefebvre\Bundle\AsyncTweetsBundle\Command;
44

5+
use Doctrine\Persistence\ObjectManager;
56
use Symfony\Bridge\Doctrine\ManagerRegistry;
67
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
78
use Symfony\Component\Console\Input\InputInterface;
89
use Symfony\Component\Console\Output\OutputInterface;
10+
use Symfony\Component\DependencyInjection\ContainerInterface;
911

1012
class BaseCommand extends ContainerAwareCommand
1113
{
14+
/** @var ContainerInterface */
1215
protected $container;
16+
/** @var ObjectManager */
1317
protected $em;
1418

15-
protected function configure()
19+
protected function configure(): void
1620
{
1721
parent::configure();
1822

@@ -21,7 +25,7 @@ protected function configure()
2125
->setDescription('Base command');
2226
}
2327

24-
protected function initialize(InputInterface $input, OutputInterface $output)
28+
protected function initialize(InputInterface $input, OutputInterface $output): void
2529
{
2630
parent::initialize($input, $output); //initialize parent class method
2731

src/Command/StatusesHomeTimelineCommand.php

+33-41
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace AlexisLefebvre\Bundle\AsyncTweetsBundle\Command;
44

55
use Abraham\TwitterOAuth\TwitterOAuth;
6+
use AlexisLefebvre\Bundle\AsyncTweetsBundle\Entity\Tweet;
7+
use AlexisLefebvre\Bundle\AsyncTweetsBundle\Entity\TweetRepository;
68
use AlexisLefebvre\Bundle\AsyncTweetsBundle\Utils\PersistTweet;
79
use Symfony\Component\Console\Helper\ProgressBar;
810
use Symfony\Component\Console\Helper\Table;
@@ -12,17 +14,24 @@
1214

1315
class StatusesHomeTimelineCommand extends BaseCommand
1416
{
17+
/** @var bool */
1518
private $displayTable;
19+
/** @var Table */
1620
private $table;
21+
/** @var ProgressBar */
1722
private $progress;
1823

19-
/** @see https://dev.twitter.com/rest/reference/get/statuses/home_timeline */
24+
/**
25+
* @var array<bool|int>
26+
*
27+
* @see https://dev.twitter.com/rest/reference/get/statuses/home_timeline
28+
*/
2029
private $parameters = [
2130
'count' => 200,
2231
'exclude_replies' => true,
2332
];
2433

25-
protected function configure()
34+
protected function configure(): void
2635
{
2736
parent::configure();
2837

@@ -38,13 +47,7 @@ protected function configure()
3847
);
3948
}
4049

41-
/**
42-
* @param InputInterface $input
43-
* @param OutputInterface $output
44-
*
45-
* @return int|void
46-
*/
47-
protected function execute(InputInterface $input, OutputInterface $output)
50+
protected function execute(InputInterface $input, OutputInterface $output): int
4851
{
4952
$this->setAndDisplayLastTweet($output);
5053

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

6770
$this->addAndDisplayTweets($input, $output, $content, $numberOfTweets);
71+
72+
return 0;
6873
}
6974

70-
/**
71-
* @param OutputInterface $output
72-
*/
73-
protected function setAndDisplayLastTweet(OutputInterface $output)
75+
protected function setAndDisplayLastTweet(OutputInterface $output): void
7476
{
77+
/** @var TweetRepository $tweetRepository */
78+
$tweetRepository = $this->em
79+
->getRepository(Tweet::class);
80+
7581
// Get the last tweet
76-
$lastTweet = $this->em
77-
->getRepository('AsyncTweetsBundle:Tweet')
78-
->getLastTweet();
82+
$lastTweet = $tweetRepository->getLastTweet();
7983

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

9296
/**
93-
* @param InputInterface $input
97+
* @return array<\stdClass>|object
9498
*/
9599
protected function getContent(InputInterface $input)
96100
{
@@ -108,13 +112,12 @@ protected function getContent(InputInterface $input)
108112
}
109113

110114
/**
111-
* @param OutputInterface $output
112-
* @param null|object $content
115+
* @param array<string>|object $content
113116
*/
114117
protected function displayContentNotArrayError(
115118
OutputInterface $output,
116119
$content
117-
) {
120+
): void {
118121
$formatter = $this->getHelper('formatter');
119122

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

126129
/**
127-
* @param InputInterface $input
128-
* @param OutputInterface $output
129-
* @param array $content
130-
* @param int $numberOfTweets
130+
* @param array<\stdClass> $content
131131
*/
132132
protected function addAndDisplayTweets(
133133
InputInterface $input,
134134
OutputInterface $output,
135-
$content,
136-
$numberOfTweets
137-
) {
135+
array $content,
136+
int $numberOfTweets
137+
): void {
138138
$output->writeln('<comment>Number of tweets: '.$numberOfTweets.'</comment>');
139139

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

157-
/**
158-
* @param OutputInterface $output
159-
* @param int $numberOfTweets
160-
*/
161157
protected function setProgressBar(
162158
OutputInterface $output,
163-
$numberOfTweets
164-
) {
159+
int $numberOfTweets
160+
): void {
165161
$this->progress = new ProgressBar($output, $numberOfTweets);
166162
$this->progress->setBarCharacter('<comment>=</comment>');
167163
$this->progress->start();
168164
}
169165

170-
/**
171-
* @param InputInterface $input
172-
* @param OutputInterface $output
173-
*/
174166
protected function setTable(
175167
InputInterface $input,
176168
OutputInterface $output
177-
) {
178-
$this->displayTable = $input->getOption('table');
169+
): void {
170+
$this->displayTable = (bool) $input->getOption('table');
179171

180172
// Display
181173
if ($this->displayTable) {
@@ -186,9 +178,9 @@ protected function setTable(
186178
}
187179

188180
/**
189-
* @param array $tweets
181+
* @param array<\stdClass> $tweets
190182
*/
191-
protected function iterateTweets($tweets)
183+
protected function iterateTweets(array $tweets): void
192184
{
193185
$persistTweet = new PersistTweet(
194186
$this->em,

src/Command/StatusesReadCommand.php

+17-25
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@
22

33
namespace AlexisLefebvre\Bundle\AsyncTweetsBundle\Command;
44

5+
use AlexisLefebvre\Bundle\AsyncTweetsBundle\Entity\Tweet;
6+
use AlexisLefebvre\Bundle\AsyncTweetsBundle\Entity\TweetRepository;
57
use Symfony\Component\Console\Helper\Table;
68
use Symfony\Component\Console\Input\InputArgument;
79
use Symfony\Component\Console\Input\InputInterface;
810
use Symfony\Component\Console\Output\OutputInterface;
911

1012
class StatusesReadCommand extends BaseCommand
1113
{
14+
/** @var Table */
1215
private $table;
1316

14-
protected function configure()
17+
protected function configure(): void
1518
{
1619
parent::configure();
1720

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

24-
/**
25-
* @param InputInterface $input
26-
* @param OutputInterface $output
27-
*
28-
* @return int|void
29-
*/
30-
protected function execute(InputInterface $input, OutputInterface $output)
27+
protected function execute(InputInterface $input, OutputInterface $output): int
3128
{
32-
/** @var int|null $page */
29+
/** @var int $page */
3330
$page = $input->getArgument('page');
3431

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

41+
/** @var TweetRepository $tweetRepository */
42+
$tweetRepository = $this->em
43+
->getRepository(Tweet::class);
4444
// Get the tweets
45-
$tweets = $this->em
46-
->getRepository('AsyncTweetsBundle:Tweet')
47-
->getWithUsers($page);
45+
$tweets = $tweetRepository->getWithUsers($page);
4846

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

5553
$this->displayTweets($output, $tweets);
54+
55+
return 0;
5656
}
5757

5858
/**
59-
* @param OutputInterface $output
60-
* @param array $tweets
59+
* @param array<Tweet> $tweets
6160
*/
6261
protected function displayTweets(
6362
OutputInterface $output,
64-
$tweets
65-
) {
63+
array $tweets
64+
): void {
6665
$this->setTable($output);
6766

6867
foreach ($tweets as $tweet) {
@@ -90,7 +89,7 @@ protected function displayTweets(
9089
$this->table->render();
9190
}
9291

93-
protected function setTable(OutputInterface $output)
92+
protected function setTable(OutputInterface $output): void
9493
{
9594
$this->table = new Table($output);
9695
$this->table
@@ -103,14 +102,7 @@ protected function setTable(OutputInterface $output)
103102
]);
104103
}
105104

106-
/**
107-
* @param string $tag
108-
* @param string $content
109-
* @param int $length
110-
*
111-
* @return string
112-
*/
113-
protected function formatCell($tag, $content, $length)
105+
protected function formatCell(string $tag, string $content, int $length): string
114106
{
115107
return '<'.$tag.'>'.
116108
// Close and reopen the tag before each new line

src/Command/StatusesShowCommand.php

+4-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
class StatusesShowCommand extends BaseCommand
1111
{
12-
protected function configure()
12+
protected function configure(): void
1313
{
1414
parent::configure();
1515

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

22-
/**
23-
* @param InputInterface $input
24-
* @param OutputInterface $output
25-
*/
26-
protected function execute(InputInterface $input, OutputInterface $output)
22+
protected function execute(InputInterface $input, OutputInterface $output): int
2723
{
2824
/** @var int|null $tweet_id */
2925
$tweet_id = $input->getArgument('tweet_id');
@@ -42,5 +38,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
4238
)));
4339

4440
$output->writeln($json);
41+
42+
return 0;
4543
}
4644
}

0 commit comments

Comments
 (0)