33namespace AlexisLefebvre \Bundle \AsyncTweetsBundle \Command ;
44
55use Abraham \TwitterOAuth \TwitterOAuth ;
6+ use AlexisLefebvre \Bundle \AsyncTweetsBundle \Entity \Tweet ;
7+ use AlexisLefebvre \Bundle \AsyncTweetsBundle \Entity \TweetRepository ;
68use AlexisLefebvre \Bundle \AsyncTweetsBundle \Utils \PersistTweet ;
79use Symfony \Component \Console \Helper \ProgressBar ;
810use Symfony \Component \Console \Helper \Table ;
1214
1315class 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 ,
0 commit comments