Skip to content

Commit 77533d5

Browse files
authored
Merge pull request #264 from neildaniels/phpstan-level-bump
PHPStan level bump
2 parents 6254b64 + f359851 commit 77533d5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+315
-175
lines changed

composer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@
5454
"symfony/cache": "^4.4 || ^5 || ^6",
5555
"symfony/event-dispatcher": "^4.4 || ^5 || ^6",
5656
"phpstan/phpstan": "^1.8.1",
57+
"phpstan/phpstan-deprecation-rules": "^1.1",
58+
"spaze/phpstan-disallowed-calls": "^2.11",
5759
"phpunit/phpunit": "^9.6.3",
5860
"php-http/guzzle7-adapter": "^1.0",
5961
"monolog/monolog": "^2.9.1 || ^3.0",

lib/Tmdb/Api/Account.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function getAccount(array $parameters = [], array $headers = [])
3636
/**
3737
* Get the lists that you have created and marked as a favorite.
3838
*
39-
* @param integer $accountId
39+
* @param int|string $accountId
4040
* @param array $parameters
4141
* @param array $headers
4242
* @return mixed
@@ -49,7 +49,7 @@ public function getLists($accountId, array $parameters = [], array $headers = []
4949
/**
5050
* Get the list of favorite movies for an account.
5151
*
52-
* @param integer $accountId
52+
* @param int|string $accountId
5353
* @param array $parameters
5454
* @param array $headers
5555
* @return mixed
@@ -62,7 +62,7 @@ public function getFavoriteMovies($accountId, array $parameters = [], array $hea
6262
/**
6363
* Get the list of favorite TV series for an account.
6464
*
65-
* @param integer $accountId
65+
* @param int|string $accountId
6666
* @param array $parameters
6767
* @param array $headers
6868
* @return mixed
@@ -75,7 +75,7 @@ public function getFavoriteTvShows($accountId, array $parameters = [], array $he
7575
/**
7676
* Add or remove a movie to an accounts favorite list.
7777
*
78-
* @param integer $accountId
78+
* @param int|string $accountId
7979
* @param integer $mediaId
8080
* @param boolean $isFavorite
8181
* @param string $mediaType Either movie or tv
@@ -93,7 +93,7 @@ public function favorite($accountId, $mediaId, $isFavorite = true, $mediaType =
9393
/**
9494
* Get the list of rated movies (and associated rating) for an account.
9595
*
96-
* @param integer $accountId
96+
* @param int|string $accountId
9797
* @param array $parameters
9898
* @param array $headers
9999
* @return mixed
@@ -106,7 +106,7 @@ public function getRatedMovies($accountId, array $parameters = [], array $header
106106
/**
107107
* Get the list of rated TV shows (and associated rating) for an account.
108108
*
109-
* @param integer $accountId
109+
* @param int|string $accountId
110110
* @param array $parameters
111111
* @param array $headers
112112
* @return mixed
@@ -119,7 +119,7 @@ public function getRatedTvShows($accountId, array $parameters = [], array $heade
119119
/**
120120
* Get the list of movies on an accounts watchlist.
121121
*
122-
* @param integer $accountId
122+
* @param int|string $accountId
123123
* @param array $parameters
124124
* @param array $headers
125125
* @return mixed
@@ -132,7 +132,7 @@ public function getMovieWatchlist($accountId, array $parameters = [], array $hea
132132
/**
133133
* Get the list of TV series on an accounts watchlist.
134134
*
135-
* @param integer $accountId
135+
* @param int|string $accountId
136136
* @param array $parameters
137137
* @param array $headers
138138
* @return mixed
@@ -145,7 +145,7 @@ public function getTvWatchlist($accountId, array $parameters = [], array $header
145145
/**
146146
* Add or remove a movie to an accounts watch list.
147147
*
148-
* @param integer $accountId
148+
* @param int|string $accountId
149149
* @param integer $mediaId
150150
* @param boolean $isOnWatchlist
151151
* @param string $mediaType Either movie or tv

lib/Tmdb/Api/Authentication.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public function validateRequestTokenWithLogin($requestToken, $username, $passwor
112112
* This method is used to generate a session id for user based authentication.
113113
* A session id is required in order to use any of the write methods.
114114
*
115-
* @param string $requestToken
115+
* @param array|string $requestToken
116116
* @return mixed
117117
* @throws UnauthorizedRequestTokenException
118118
*/

lib/Tmdb/Api/Lists.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function getItemStatus($id, $movieId, array $parameters = [], array $head
7070
* This method lets users add new movies to a list that they created. A valid session id is required.
7171
*
7272
* @param string $id
73-
* @param string $mediaId
73+
* @param string|int $mediaId
7474
* @return mixed
7575
*/
7676
public function addMediaToList($id, $mediaId)
@@ -82,7 +82,7 @@ public function addMediaToList($id, $mediaId)
8282
* This method lets users delete movies from a list that they created. A valid session id is required.
8383
*
8484
* @param string $id
85-
* @param string $mediaId
85+
* @param string|int $mediaId
8686
* @return mixed
8787
*/
8888
public function removeMediaFromList($id, $mediaId)

lib/Tmdb/Event/Listener/Logger/LogHttpMessageListener.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,7 @@ public function __invoke(LoggableHttpEventInterface $event): void
6464
$this->logResponse($event);
6565
}
6666

67-
if (
68-
$event instanceof HttpClientExceptionEvent &&
69-
$event->getException() instanceof ClientExceptionInterface
70-
) {
67+
if ($event instanceof HttpClientExceptionEvent) {
7168
$this->logClientException($event);
7269
}
7370
}

lib/Tmdb/Event/Listener/Logger/LogHydrationListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function __invoke(BeforeHydrationEvent $event): void
6767

6868
if ($this->withData) {
6969
$context['data'] = $event->getData();
70-
$context['data_size'] = \mb_strlen(\GuzzleHttp\json_encode($event->getData()), 'UTF-8');
70+
$context['data_size'] = \mb_strlen(\GuzzleHttp\Utils::jsonEncode($event->getData()), 'UTF-8');
7171
}
7272

7373
$this->logger->debug(

lib/Tmdb/Event/Listener/Request/SessionTokenRequestListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
class SessionTokenRequestListener
2424
{
2525
/**
26-
* @var string
26+
* @var string|SessionBearerToken|GuestSessionToken
2727
*/
2828
private $token;
2929

lib/Tmdb/Event/RequestEvent.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ class RequestEvent extends StoppableEvent implements LoggableHttpEventInterface
3030
private $request;
3131

3232
/**
33-
* @var ResponseInterface
33+
* @var ?ResponseInterface
3434
*/
3535
private $response;
3636

3737
/**
38-
* @var SessionToken
38+
* @var ?SessionToken
3939
*/
4040
private $sessionToken;
4141

@@ -71,7 +71,7 @@ public function setRequest(RequestInterface $request): RequestEvent
7171
}
7272

7373
/**
74-
* @return ResponseInterface
74+
* @return ?ResponseInterface
7575
*/
7676
public function getResponse(): ?ResponseInterface
7777
{
@@ -98,9 +98,9 @@ public function hasResponse()
9898
}
9999

100100
/**
101-
* @return SessionToken
101+
* @return ?SessionToken
102102
*/
103-
public function getSessionToken(): SessionToken
103+
public function getSessionToken(): ?SessionToken
104104
{
105105
return $this->sessionToken;
106106
}

lib/Tmdb/Factory/AbstractFactory.php

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929

3030
/**
3131
* Class AbstractFactory
32+
*
33+
* @template T of AbstractModel
34+
*
3235
* @package Tmdb\Factory
3336
*/
3437
abstract class AbstractFactory
@@ -52,27 +55,28 @@ public function __construct(HttpClient $httpClient)
5255
* Convert an array to an hydrated object
5356
*
5457
* @param array $data
55-
* @return AbstractModel
58+
* @return T
5659
*/
5760
abstract public function create(array $data = []);
5861

5962
/**
6063
* Convert an array with an collection of items to an hydrated object collection
6164
*
6265
* @param array $data
63-
* @return GenericCollection
66+
* @return GenericCollection<T>
6467
*/
6568
abstract public function createCollection(array $data = []);
6669

6770
/**
6871
* Create a result collection
6972
*
70-
* @param array $data
73+
* @param null|array $data
7174
* @param string $method
72-
* @return ResultCollection
75+
* @return ResultCollection<T>
7376
*/
7477
public function createResultCollection($data = [], $method = 'create'): ResultCollection
7578
{
79+
/** @var ResultCollection<T> */
7680
$collection = new ResultCollection();
7781

7882
if (null === $data) {
@@ -106,7 +110,7 @@ public function createResultCollection($data = [], $method = 'create'): ResultCo
106110
* Create rating
107111
*
108112
* @param array $data
109-
* @return AbstractModel
113+
* @return Rating
110114
*/
111115
public function createRating(array $data = [])
112116
{
@@ -116,9 +120,11 @@ public function createRating(array $data = [])
116120
/**
117121
* Hydrate the object with data
118122
*
119-
* @param AbstractModel $subject
123+
* @template S of AbstractModel
124+
*
125+
* @param S $subject
120126
* @param array $data
121-
* @return AbstractModel
127+
* @return S
122128
*/
123129
protected function hydrate(AbstractModel $subject, $data = [])
124130
{
@@ -167,7 +173,7 @@ protected function getHttpClient()
167173
* Create the account states
168174
*
169175
* @param array $data
170-
* @return AbstractModel
176+
* @return AccountStates
171177
*/
172178
public function createAccountStates(array $data = [])
173179
{
@@ -190,7 +196,7 @@ public function createAccountStates(array $data = [])
190196
* Create result
191197
*
192198
* @param array $data
193-
* @return AbstractModel
199+
* @return Result
194200
*/
195201
public function createResult(array $data = [])
196202
{
@@ -200,12 +206,13 @@ public function createResult(array $data = [])
200206
/**
201207
* Create a generic collection of data and map it on the class by it's static parameter $properties
202208
*
209+
* @template S of AbstractModel
203210
* @param array $data
204-
* @param AbstractModel $class
211+
* @param S|string $class
205212
*
206-
* @return GenericCollection
213+
* @return GenericCollection<S>
207214
*/
208-
protected function createGenericCollection(array $data = [], AbstractModel $class = null): GenericCollection
215+
protected function createGenericCollection(array $data = [], $class = null): GenericCollection
209216
{
210217
if (!$class) {
211218
throw new \Tmdb\Exception\RuntimeException('Expected a class to be present.');
@@ -215,12 +222,9 @@ protected function createGenericCollection(array $data = [], AbstractModel $clas
215222
$class = get_class($class);
216223
}
217224

225+
/** @var GenericCollection<S> */
218226
$collection = new GenericCollection();
219227

220-
if (null === $data) {
221-
return $collection;
222-
}
223-
224228
foreach ($data as $item) {
225229
$collection->add(null, $this->hydrate(new $class(), $item));
226230
}
@@ -231,28 +235,26 @@ protected function createGenericCollection(array $data = [], AbstractModel $clas
231235
/**
232236
* Create a generic collection of data and map it on the class by it's static parameter $properties
233237
*
238+
* @template S of AbstractModel
239+
* @template SC of GenericCollection<S>
234240
* @param array $data
235-
* @param AbstractModel $class
236-
* @param GenericCollection $collection
237-
* @return GenericCollection
241+
* @param S|string $class
242+
* @param SC $collection
243+
* @return SC
238244
*/
239245
protected function createCustomCollection(
240246
array $data,
241-
AbstractModel $class,
247+
$class,
242248
GenericCollection $collection
243249
) {
244-
if (!$class || !$collection) {
245-
throw new \Tmdb\Exception\RuntimeException('Expected both an class and collection to be given.');
250+
if (!$class) {
251+
throw new \Tmdb\Exception\RuntimeException('Expected a class to be present.');
246252
}
247253

248254
if (is_object($class)) {
249255
$class = get_class($class);
250256
}
251257

252-
if (null === $data) {
253-
return $collection;
254-
}
255-
256258
foreach ($data as $item) {
257259
$collection->add(null, $this->hydrate(new $class(), $item));
258260
}
@@ -264,7 +266,7 @@ protected function createCustomCollection(
264266
* Create an generic collection of an array that consists out of a mix of movies and tv shows
265267
*
266268
* @param array $data
267-
* @return GenericCollection
269+
* @return GenericCollection<AbstractModel>
268270
*/
269271
protected function createGenericCollectionFromMediaTypes($data = [])
270272
{

lib/Tmdb/Factory/AccountFactory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
/**
2525
* Class AccountFactory
26+
* @extends AbstractFactory<Account>
2627
* @package Tmdb\Factory
2728
*/
2829
class AccountFactory extends AbstractFactory

lib/Tmdb/Factory/AuthenticationFactory.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
use DateTime;
1818
use RuntimeException;
19+
use Tmdb\Model\AbstractModel;
20+
use Tmdb\Model\Common\GenericCollection;
1921
use Tmdb\Token\Session\GuestSessionToken;
2022
use Tmdb\Token\Session\RequestToken;
2123
use Tmdb\Token\Session\SessionToken;
@@ -29,7 +31,7 @@ class AuthenticationFactory extends AbstractFactory
2931
/**
3032
* @param array $data
3133
*
32-
* @return void
34+
* @return AbstractModel
3335
* @throws RuntimeException
3436
*/
3537
public function create(array $data = [])
@@ -44,7 +46,7 @@ public function create(array $data = [])
4446
/**
4547
* @param array $data
4648
*
47-
* @return void
49+
* @return GenericCollection
4850
* @throws RuntimeException
4951
*/
5052
public function createCollection(array $data = [])
@@ -106,7 +108,7 @@ public function createSessionToken(array $data = [])
106108
* Create session token for guest
107109
*
108110
* @param array $data
109-
* @return SessionToken
111+
* @return GuestSessionToken
110112
*/
111113
public function createGuestSessionToken(array $data = [])
112114
{

0 commit comments

Comments
 (0)