Skip to content

Commit

Permalink
Merge pull request #264 from neildaniels/phpstan-level-bump
Browse files Browse the repository at this point in the history
PHPStan level bump
  • Loading branch information
wtfzdotnet authored Feb 25, 2023
2 parents 6254b64 + f359851 commit 77533d5
Show file tree
Hide file tree
Showing 58 changed files with 315 additions and 175 deletions.
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
"symfony/cache": "^4.4 || ^5 || ^6",
"symfony/event-dispatcher": "^4.4 || ^5 || ^6",
"phpstan/phpstan": "^1.8.1",
"phpstan/phpstan-deprecation-rules": "^1.1",
"spaze/phpstan-disallowed-calls": "^2.11",
"phpunit/phpunit": "^9.6.3",
"php-http/guzzle7-adapter": "^1.0",
"monolog/monolog": "^2.9.1 || ^3.0",
Expand Down
18 changes: 9 additions & 9 deletions lib/Tmdb/Api/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function getAccount(array $parameters = [], array $headers = [])
/**
* Get the lists that you have created and marked as a favorite.
*
* @param integer $accountId
* @param int|string $accountId
* @param array $parameters
* @param array $headers
* @return mixed
Expand All @@ -49,7 +49,7 @@ public function getLists($accountId, array $parameters = [], array $headers = []
/**
* Get the list of favorite movies for an account.
*
* @param integer $accountId
* @param int|string $accountId
* @param array $parameters
* @param array $headers
* @return mixed
Expand All @@ -62,7 +62,7 @@ public function getFavoriteMovies($accountId, array $parameters = [], array $hea
/**
* Get the list of favorite TV series for an account.
*
* @param integer $accountId
* @param int|string $accountId
* @param array $parameters
* @param array $headers
* @return mixed
Expand All @@ -75,7 +75,7 @@ public function getFavoriteTvShows($accountId, array $parameters = [], array $he
/**
* Add or remove a movie to an accounts favorite list.
*
* @param integer $accountId
* @param int|string $accountId
* @param integer $mediaId
* @param boolean $isFavorite
* @param string $mediaType Either movie or tv
Expand All @@ -93,7 +93,7 @@ public function favorite($accountId, $mediaId, $isFavorite = true, $mediaType =
/**
* Get the list of rated movies (and associated rating) for an account.
*
* @param integer $accountId
* @param int|string $accountId
* @param array $parameters
* @param array $headers
* @return mixed
Expand All @@ -106,7 +106,7 @@ public function getRatedMovies($accountId, array $parameters = [], array $header
/**
* Get the list of rated TV shows (and associated rating) for an account.
*
* @param integer $accountId
* @param int|string $accountId
* @param array $parameters
* @param array $headers
* @return mixed
Expand All @@ -119,7 +119,7 @@ public function getRatedTvShows($accountId, array $parameters = [], array $heade
/**
* Get the list of movies on an accounts watchlist.
*
* @param integer $accountId
* @param int|string $accountId
* @param array $parameters
* @param array $headers
* @return mixed
Expand All @@ -132,7 +132,7 @@ public function getMovieWatchlist($accountId, array $parameters = [], array $hea
/**
* Get the list of TV series on an accounts watchlist.
*
* @param integer $accountId
* @param int|string $accountId
* @param array $parameters
* @param array $headers
* @return mixed
Expand All @@ -145,7 +145,7 @@ public function getTvWatchlist($accountId, array $parameters = [], array $header
/**
* Add or remove a movie to an accounts watch list.
*
* @param integer $accountId
* @param int|string $accountId
* @param integer $mediaId
* @param boolean $isOnWatchlist
* @param string $mediaType Either movie or tv
Expand Down
2 changes: 1 addition & 1 deletion lib/Tmdb/Api/Authentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function validateRequestTokenWithLogin($requestToken, $username, $passwor
* This method is used to generate a session id for user based authentication.
* A session id is required in order to use any of the write methods.
*
* @param string $requestToken
* @param array|string $requestToken
* @return mixed
* @throws UnauthorizedRequestTokenException
*/
Expand Down
4 changes: 2 additions & 2 deletions lib/Tmdb/Api/Lists.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function getItemStatus($id, $movieId, array $parameters = [], array $head
* This method lets users add new movies to a list that they created. A valid session id is required.
*
* @param string $id
* @param string $mediaId
* @param string|int $mediaId
* @return mixed
*/
public function addMediaToList($id, $mediaId)
Expand All @@ -82,7 +82,7 @@ public function addMediaToList($id, $mediaId)
* This method lets users delete movies from a list that they created. A valid session id is required.
*
* @param string $id
* @param string $mediaId
* @param string|int $mediaId
* @return mixed
*/
public function removeMediaFromList($id, $mediaId)
Expand Down
5 changes: 1 addition & 4 deletions lib/Tmdb/Event/Listener/Logger/LogHttpMessageListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,7 @@ public function __invoke(LoggableHttpEventInterface $event): void
$this->logResponse($event);
}

if (
$event instanceof HttpClientExceptionEvent &&
$event->getException() instanceof ClientExceptionInterface
) {
if ($event instanceof HttpClientExceptionEvent) {
$this->logClientException($event);
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Tmdb/Event/Listener/Logger/LogHydrationListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function __invoke(BeforeHydrationEvent $event): void

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

$this->logger->debug(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
class SessionTokenRequestListener
{
/**
* @var string
* @var string|SessionBearerToken|GuestSessionToken
*/
private $token;

Expand Down
10 changes: 5 additions & 5 deletions lib/Tmdb/Event/RequestEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ class RequestEvent extends StoppableEvent implements LoggableHttpEventInterface
private $request;

/**
* @var ResponseInterface
* @var ?ResponseInterface
*/
private $response;

/**
* @var SessionToken
* @var ?SessionToken
*/
private $sessionToken;

Expand Down Expand Up @@ -71,7 +71,7 @@ public function setRequest(RequestInterface $request): RequestEvent
}

/**
* @return ResponseInterface
* @return ?ResponseInterface
*/
public function getResponse(): ?ResponseInterface
{
Expand All @@ -98,9 +98,9 @@ public function hasResponse()
}

/**
* @return SessionToken
* @return ?SessionToken
*/
public function getSessionToken(): SessionToken
public function getSessionToken(): ?SessionToken
{
return $this->sessionToken;
}
Expand Down
56 changes: 29 additions & 27 deletions lib/Tmdb/Factory/AbstractFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@

/**
* Class AbstractFactory
*
* @template T of AbstractModel
*
* @package Tmdb\Factory
*/
abstract class AbstractFactory
Expand All @@ -52,27 +55,28 @@ public function __construct(HttpClient $httpClient)
* Convert an array to an hydrated object
*
* @param array $data
* @return AbstractModel
* @return T
*/
abstract public function create(array $data = []);

/**
* Convert an array with an collection of items to an hydrated object collection
*
* @param array $data
* @return GenericCollection
* @return GenericCollection<T>
*/
abstract public function createCollection(array $data = []);

/**
* Create a result collection
*
* @param array $data
* @param null|array $data
* @param string $method
* @return ResultCollection
* @return ResultCollection<T>
*/
public function createResultCollection($data = [], $method = 'create'): ResultCollection
{
/** @var ResultCollection<T> */
$collection = new ResultCollection();

if (null === $data) {
Expand Down Expand Up @@ -106,7 +110,7 @@ public function createResultCollection($data = [], $method = 'create'): ResultCo
* Create rating
*
* @param array $data
* @return AbstractModel
* @return Rating
*/
public function createRating(array $data = [])
{
Expand All @@ -116,9 +120,11 @@ public function createRating(array $data = [])
/**
* Hydrate the object with data
*
* @param AbstractModel $subject
* @template S of AbstractModel
*
* @param S $subject
* @param array $data
* @return AbstractModel
* @return S
*/
protected function hydrate(AbstractModel $subject, $data = [])
{
Expand Down Expand Up @@ -167,7 +173,7 @@ protected function getHttpClient()
* Create the account states
*
* @param array $data
* @return AbstractModel
* @return AccountStates
*/
public function createAccountStates(array $data = [])
{
Expand All @@ -190,7 +196,7 @@ public function createAccountStates(array $data = [])
* Create result
*
* @param array $data
* @return AbstractModel
* @return Result
*/
public function createResult(array $data = [])
{
Expand All @@ -200,12 +206,13 @@ public function createResult(array $data = [])
/**
* Create a generic collection of data and map it on the class by it's static parameter $properties
*
* @template S of AbstractModel
* @param array $data
* @param AbstractModel $class
* @param S|string $class
*
* @return GenericCollection
* @return GenericCollection<S>
*/
protected function createGenericCollection(array $data = [], AbstractModel $class = null): GenericCollection
protected function createGenericCollection(array $data = [], $class = null): GenericCollection
{
if (!$class) {
throw new \Tmdb\Exception\RuntimeException('Expected a class to be present.');
Expand All @@ -215,12 +222,9 @@ protected function createGenericCollection(array $data = [], AbstractModel $clas
$class = get_class($class);
}

/** @var GenericCollection<S> */
$collection = new GenericCollection();

if (null === $data) {
return $collection;
}

foreach ($data as $item) {
$collection->add(null, $this->hydrate(new $class(), $item));
}
Expand All @@ -231,28 +235,26 @@ protected function createGenericCollection(array $data = [], AbstractModel $clas
/**
* Create a generic collection of data and map it on the class by it's static parameter $properties
*
* @template S of AbstractModel
* @template SC of GenericCollection<S>
* @param array $data
* @param AbstractModel $class
* @param GenericCollection $collection
* @return GenericCollection
* @param S|string $class
* @param SC $collection
* @return SC
*/
protected function createCustomCollection(
array $data,
AbstractModel $class,
$class,
GenericCollection $collection
) {
if (!$class || !$collection) {
throw new \Tmdb\Exception\RuntimeException('Expected both an class and collection to be given.');
if (!$class) {
throw new \Tmdb\Exception\RuntimeException('Expected a class to be present.');
}

if (is_object($class)) {
$class = get_class($class);
}

if (null === $data) {
return $collection;
}

foreach ($data as $item) {
$collection->add(null, $this->hydrate(new $class(), $item));
}
Expand All @@ -264,7 +266,7 @@ protected function createCustomCollection(
* Create an generic collection of an array that consists out of a mix of movies and tv shows
*
* @param array $data
* @return GenericCollection
* @return GenericCollection<AbstractModel>
*/
protected function createGenericCollectionFromMediaTypes($data = [])
{
Expand Down
1 change: 1 addition & 0 deletions lib/Tmdb/Factory/AccountFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

/**
* Class AccountFactory
* @extends AbstractFactory<Account>
* @package Tmdb\Factory
*/
class AccountFactory extends AbstractFactory
Expand Down
8 changes: 5 additions & 3 deletions lib/Tmdb/Factory/AuthenticationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

use DateTime;
use RuntimeException;
use Tmdb\Model\AbstractModel;
use Tmdb\Model\Common\GenericCollection;
use Tmdb\Token\Session\GuestSessionToken;
use Tmdb\Token\Session\RequestToken;
use Tmdb\Token\Session\SessionToken;
Expand All @@ -29,7 +31,7 @@ class AuthenticationFactory extends AbstractFactory
/**
* @param array $data
*
* @return void
* @return AbstractModel
* @throws RuntimeException
*/
public function create(array $data = [])
Expand All @@ -44,7 +46,7 @@ public function create(array $data = [])
/**
* @param array $data
*
* @return void
* @return GenericCollection
* @throws RuntimeException
*/
public function createCollection(array $data = [])
Expand Down Expand Up @@ -106,7 +108,7 @@ public function createSessionToken(array $data = [])
* Create session token for guest
*
* @param array $data
* @return SessionToken
* @return GuestSessionToken
*/
public function createGuestSessionToken(array $data = [])
{
Expand Down
Loading

0 comments on commit 77533d5

Please sign in to comment.