Thanks to visit codestin.com
Credit goes to github.com

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

Commit 6836da2

Browse files
Fix PHPStan issues
1 parent df82e81 commit 6836da2

3 files changed

Lines changed: 18 additions & 51 deletions

File tree

src/Entity/TweetRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class TweetRepository extends EntityRepository
1414
{
1515
private $nbTweets = 5;
1616

17-
public function getWithUsers($page = 1)
17+
public function getWithUsers(int $page = 1)
1818
{
1919
$firstResult = (($page - 1) * $this->nbTweets);
2020

src/Entity/User.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class User
3939
*/
4040
private $tweets;
4141

42-
public function __construct($id = null)
42+
public function __construct(?int $id = null)
4343
{
4444
if (!is_null($id)) {
4545
$this->setId($id);

src/Utils/PersistTweet.php

Lines changed: 16 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@
55
use AlexisLefebvre\Bundle\AsyncTweetsBundle\Entity\Media;
66
use AlexisLefebvre\Bundle\AsyncTweetsBundle\Entity\Tweet;
77
use AlexisLefebvre\Bundle\AsyncTweetsBundle\Entity\User;
8+
use Doctrine\ORM\EntityManagerInterface;
9+
use Symfony\Component\Console\Helper\Table;
810

911
class PersistTweet
1012
{
1113
private $em;
1214
private $displayTable;
1315
private $table;
1416

15-
public function __construct($em, $displayTable, $table)
17+
public function __construct(EntityManagerInterface $em, bool $displayTable, Table $table)
1618
{
1719
$this->em = $em;
1820
$this->displayTable = $displayTable;
@@ -28,7 +30,7 @@ protected function persistUser(\stdClass $userTmp)
2830
{
2931
$user = $this->em
3032
->getRepository('AsyncTweetsBundle:User')
31-
->findOneById($userTmp->id);
33+
->findOneBy(['id' => $userTmp->id]);
3234

3335
if (!$user) {
3436
// Only set the id when adding the User
@@ -44,10 +46,10 @@ protected function persistUser(\stdClass $userTmp)
4446
}
4547

4648
/**
47-
* @param array $medias
49+
* @param array<\stdClass> $medias
4850
* @param Tweet $tweet
4951
*/
50-
public function iterateMedias($medias, Tweet $tweet)
52+
public function iterateMedias($medias, Tweet $tweet): void
5153
{
5254
foreach ($medias as $mediaTmp) {
5355
if ($mediaTmp->type == 'photo') {
@@ -56,28 +58,15 @@ public function iterateMedias($medias, Tweet $tweet)
5658
}
5759
}
5860

59-
/**
60-
* @param \stdClass $tweetTmp
61-
* @param Tweet $tweet
62-
*/
63-
protected function addMedias(\stdClass $tweetTmp, Tweet $tweet)
61+
protected function addMedias(\stdClass $tweetTmp, Tweet $tweet): void
6462
{
6563
if ((isset($tweetTmp->entities))
6664
&& (isset($tweetTmp->entities->media))) {
6765
$this->iterateMedias($tweetTmp->entities->media, $tweet);
6866
}
6967
}
7068

71-
/**
72-
* Create a Tweet object and return it.
73-
*
74-
* @param \stdClass $tweetTmp
75-
* @param User $user
76-
* @param bool $inTimeline
77-
*
78-
* @return Tweet
79-
*/
80-
protected function createTweet(\stdClass $tweetTmp, $user, $inTimeline)
69+
protected function createTweet(\stdClass $tweetTmp, User $user, bool $inTimeline): Tweet
8170
{
8271
$tweet = new Tweet();
8372

@@ -92,21 +81,14 @@ protected function createTweet(\stdClass $tweetTmp, $user, $inTimeline)
9281
return $tweet;
9382
}
9483

95-
/**
96-
* @param \stdClass $tweetTmp
97-
* @param User $user
98-
* @param bool $inTimeline
99-
*
100-
* @return Tweet
101-
*/
10284
protected function persistTweet(
10385
\stdClass $tweetTmp,
10486
User $user,
105-
$inTimeline
106-
) {
87+
bool $inTimeline
88+
): Tweet {
10789
$tweet = $this->em
10890
->getRepository('AsyncTweetsBundle:Tweet')
109-
->findOneById($tweetTmp->id);
91+
->findOneBy(['id' => $tweetTmp->id]);
11092

11193
if (!$tweet) {
11294
$tweet = $this->createTweet($tweetTmp, $user, $inTimeline);
@@ -123,16 +105,11 @@ protected function persistTweet(
123105
return $tweet;
124106
}
125107

126-
/**
127-
* @param \stdClass $tweetTmp
128-
*
129-
* @return Tweet
130-
*/
131-
protected function persistRetweetedTweet(\stdClass $tweetTmp)
108+
protected function persistRetweetedTweet(\stdClass $tweetTmp): Tweet
132109
{
133110
$retweet = $this->em
134111
->getRepository('AsyncTweetsBundle:Tweet')
135-
->findOneById($tweetTmp->retweeted_status->id);
112+
->findOneBy(['id' => $tweetTmp->retweeted_status->id]);
136113

137114
if (!$retweet) {
138115
$retweet = $this->addTweet(
@@ -143,15 +120,11 @@ protected function persistRetweetedTweet(\stdClass $tweetTmp)
143120
return $retweet;
144121
}
145122

146-
/**
147-
* @param Tweet $tweet
148-
* @param \stdClass $mediaTmp
149-
*/
150-
protected function persistMedia(Tweet $tweet, \stdClass $mediaTmp)
123+
protected function persistMedia(Tweet $tweet, \stdClass $mediaTmp): void
151124
{
152125
$media = $this->em
153126
->getRepository('AsyncTweetsBundle:Media')
154-
->findOneById($mediaTmp->id);
127+
->findOneBy(['id' => $mediaTmp->id]);
155128

156129
if (!$media) {
157130
// Only set the id and values when adding the Media
@@ -164,13 +137,7 @@ protected function persistMedia(Tweet $tweet, \stdClass $mediaTmp)
164137
$tweet->addMedia($media);
165138
}
166139

167-
/**
168-
* @param \stdClass $tweetTmp
169-
* @param bool $inTimeline
170-
*
171-
* @return Tweet
172-
*/
173-
public function addTweet(\stdClass $tweetTmp, $inTimeline = false)
140+
public function addTweet(\stdClass $tweetTmp, bool $inTimeline = false): Tweet
174141
{
175142
$user = $this->persistUser($tweetTmp->user);
176143

0 commit comments

Comments
 (0)