diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 00000000..1775e057 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,3 @@ +# These are supported funding model platforms +github: [php-tmdb, wtfzdotnet] +custom: ['https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=SMLZ362KQ8K8W'] diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index ce3b991d..349b15fd 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -13,8 +13,9 @@ jobs: strategy: matrix: php-version: - - "7.3" - "7.4" + - "8.0" + - "8.1" deps: - "normal" symfony-require: @@ -22,25 +23,31 @@ jobs: symfony-deprecations-helper: - "" include: - - php-version: "7.3" + - php-version: "7.4" deps: "normal" - - php-version: "7.3" + - php-version: "7.4" deps: "low" - - php-version: "7.3" + - php-version: "7.4" deps: "dev" - - php-version: "7.4" + - php-version: "8.0" deps: "normal" - - php-version: "7.4" + - php-version: "8.0" deps: "low" - - php-version: "7.4" + - php-version: "8.0" deps: "dev" - - php-version: "8.0" + - php-version: "8.1" + deps: "normal" + + - php-version: "8.1" + deps: "low" + + - php-version: "8.1" deps: "dev" steps: @@ -77,7 +84,7 @@ jobs: run: "vendor/bin/phpunit --coverage-clover=coverage.xml" - name: "Upload coverage file" - uses: "actions/upload-artifact@v2" + uses: "actions/upload-artifact@v4" with: name: "phpunit-${{ matrix.php-version }}-${{ matrix.deps }}-${{ hashFiles('composer.lock') }}.coverage" path: "coverage.xml" diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml new file mode 100644 index 00000000..21edc6b6 --- /dev/null +++ b/.github/workflows/static-analysis.yml @@ -0,0 +1,34 @@ +name: Static Analysis + +on: ["pull_request", "push"] + +jobs: + static-analysis-phpstan: + name: "PHPStan" + runs-on: "ubuntu-latest" + + strategy: + matrix: + php-version: + - "7.4" + - "8.0" + - "8.1" + + steps: + - name: "Checkout code" + uses: "actions/checkout@v3" + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "none" + php-version: "${{ matrix.php-version }}" + tools: cs2pr + + - name: "Install dependencies with Composer" + uses: "ramsey/composer-install@v2" + with: + php_version: "${{ matrix.php-version }}" + + - name: "Run PHPStan" + run: "vendor/bin/phpstan analyse --error-format=checkstyle --no-progress | cs2pr" diff --git a/.github/workflows/static-analysis.yml.bak b/.github/workflows/static-analysis.yml.bak deleted file mode 100644 index 3310a020..00000000 --- a/.github/workflows/static-analysis.yml.bak +++ /dev/null @@ -1,57 +0,0 @@ -# Disable for time being -name: Static Analysis - -on: - pull_request: - -jobs: - static-analysis-phpstan: - name: "PHPStan" - runs-on: "ubuntu-latest" - - strategy: - matrix: - php-version: - - "7.4" - - steps: - - name: "Checkout code" - uses: "actions/checkout@v2" - - - name: "Install PHP" - uses: "shivammathur/setup-php@v2" - with: - coverage: "none" - php-version: "${{ matrix.php-version }}" - tools: cs2pr - - - name: "Install dependencies with Composer" - uses: "ramsey/composer-install@v1" - - - name: "Run PHPStan" - run: "vendor/bin/phpstan analyse --error-format=checkstyle --no-progress -c phpstan.neon | cs2pr" - - static-analysis-psalm: - name: "Psalm" - runs-on: "ubuntu-latest" - - strategy: - matrix: - php-version: - - "7.4" - - steps: - - name: "Checkout code" - uses: "actions/checkout@v2" - - - name: "Install PHP" - uses: "shivammathur/setup-php@v2" - with: - coverage: "none" - php-version: "${{ matrix.php-version }}" - - - name: "Install dependencies with Composer" - uses: "ramsey/composer-install@v1" - - - name: "Run a static analysis with vimeo/psalm" - run: "vendor/bin/psalm --show-info=false --stats --output-format=github --threads=$(nproc)" diff --git a/.gitignore b/.gitignore index c12b74ec..46e2d17d 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,5 @@ composer.lock .phpunit.result.cache examples/ examples/var/ +phpstan.neon$ +.DS_Store diff --git a/README.md b/README.md index 290b2cd1..b3f3151f 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ [![License](https://poser.pugx.org/php-tmdb/api/license.png)](https://packagist.org/packages/php-tmdb/api) [![License](https://img.shields.io/github/v/tag/php-tmdb/api)](https://github.com/php-tmdb/api/releases) -[![Build Status](https://img.shields.io/github/workflow/status/php-tmdb/api/Continuous%20Integration?label=phpunit)](https://github.com/php-tmdb/api/actions?query=workflow%3A%22Continuous+Integration%22) -[![Build Status](https://img.shields.io/github/workflow/status/php-tmdb/api/Coding%20Standards?label=phpcs)](https://github.com/php-tmdb/api/actions?query=workflow%3A%22Coding+Standards%22) +[![Build Status](https://img.shields.io/github/actions/workflow/status/php-tmdb/api/continuous-integration.yml?label=phpunit)](https://github.com/php-tmdb/api/actions/workflows/continuous-integration.yml) +[![Build Status](https://img.shields.io/github/actions/workflow/status/php-tmdb/api/coding-standards.yml?label=phpcs)](https://github.com/php-tmdb/api/actions/workflows/coding-standards.yml) [![codecov](https://img.shields.io/codecov/c/github/php-tmdb/api?token=gTM9AiO5vH)](https://codecov.io/gh/php-tmdb/api) [![PHP](https://img.shields.io/badge/php->=7.3,%20>=7.4,%20>=8.0-8892BF.svg)](https://packagist.org/packages/php-tmdb/api) [![Total Downloads](https://poser.pugx.org/php-tmdb/api/downloads.svg)](https://packagist.org/packages/php-tmdb/api) diff --git a/composer.json b/composer.json index fa9652ab..79a56e52 100644 --- a/composer.json +++ b/composer.json @@ -31,34 +31,34 @@ "license": "MIT", "name": "php-tmdb/api", "require": { - "php": "^7.3 || ^7.4 || ^8.0", + "php": "^7.3 || ^8.0", "ext-json": "*", - "symfony/options-resolver": "^4.4 || ^5.0 || ^6.0", - "psr/cache": "^1.0 || ^2.0 || ^3.0", - "psr/simple-cache": "^1.0 || ^2.0 || ^3.0", - "psr/event-dispatcher": "^1.0", - "psr/event-dispatcher-implementation": "^1.0", - "psr/log": "^1.0 || ^2.0 || ^3.0", + "symfony/options-resolver": "^4.4 || ^5 || ^6", + "psr/cache": "^1 || ^2 || ^3", + "psr/simple-cache": "^1 || ^2 || ^3", + "psr/event-dispatcher": "^1", + "psr/event-dispatcher-implementation": "^1", + "psr/log": "^1 || ^2 || ^3", "php-http/discovery": "^1.11", - "psr/http-client": "^1.0", - "psr/http-client-implementation": "^1.0", - "psr/http-factory": "^1.0", - "psr/http-factory-implementation": "^1.0", - "psr/http-message": "^1.0" + "psr/http-client": "^1", + "psr/http-client-implementation": "^1", + "psr/http-factory": "^1", + "psr/http-factory-implementation": "^1", + "psr/http-message": "^1" }, "require-dev": { "nyholm/psr7": "^1.2", - "friendsofphp/php-cs-fixer": "^2.17", "php-http/mock-client": "^1.2", - "slevomat/coding-standard": "^6.4.1", + "slevomat/coding-standard": "^8.8", "squizlabs/php_codesniffer": "^3.5.8", - "symfony/cache": ">=4.4,<6", - "symfony/event-dispatcher": "^5.0,<6", - "phpstan/phpstan": "^0.12.18", - "phpunit/phpunit": "^7.5 || ^8.0 || ^9.3", - "php-http/guzzle7-adapter": "^0.1", - "monolog/monolog": ">=1.11.0", - "vimeo/psalm": "^4", + "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", "php-http/cache-plugin": "^1.7", "jeroen/psr-log-test-doubles": "^2.1 || ^3" }, @@ -67,8 +67,7 @@ "test-ci": "vendor/bin/phpunit --coverage-text --coverage-clover=build/coverage.xml coverage", "test-coverage": "php -d xdebug.mode=coverage vendor/bin/phpunit --coverage-html build/coverage", "test-cs": "vendor/bin/phpcs", - "test-phpstan": "vendor/bin/phpstan analyse", - "test-psalm": "vendor/bin/psalm lib/" + "test-phpstan": "vendor/bin/phpstan analyse" }, "suggest": { "psr/log-implementation": "If you wish to enable logging features, provide an PSR-3 logger.", @@ -78,5 +77,11 @@ "php-http/cache-plugin": "When making use of cache, you need to install this plugin.", "psr/simple-cache-implementation": "If you wish to enable caching features, provide an PSR-16 cache." }, - "type": "library" + "type": "library", + "config": { + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": true, + "php-http/discovery": false + } + } } diff --git a/lib/Tmdb/Api/Account.php b/lib/Tmdb/Api/Account.php index a1010bbf..fab3670e 100644 --- a/lib/Tmdb/Api/Account.php +++ b/lib/Tmdb/Api/Account.php @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/lib/Tmdb/Api/Authentication.php b/lib/Tmdb/Api/Authentication.php index 8fa4d8e6..6a0b618c 100644 --- a/lib/Tmdb/Api/Authentication.php +++ b/lib/Tmdb/Api/Authentication.php @@ -102,6 +102,8 @@ public function validateRequestTokenWithLogin($requestToken, $username, $passwor if ($e->getCode() == 401) { throw new UnauthorizedRequestTokenException("The request token has not been validated yet."); } + + return null; } //@codeCoverageIgnoreEnd } @@ -110,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 */ @@ -128,6 +130,8 @@ public function getNewSession($requestToken) if ($e->getCode() == 401) { throw new UnauthorizedRequestTokenException("The request token has not been validated yet."); } + + return null; //@codeCoverageIgnoreEnd } } diff --git a/lib/Tmdb/Api/Configuration.php b/lib/Tmdb/Api/Configuration.php index eb2c4014..4a48785f 100644 --- a/lib/Tmdb/Api/Configuration.php +++ b/lib/Tmdb/Api/Configuration.php @@ -46,4 +46,13 @@ public function getConfiguration(array $headers = []) { return $this->get('configuration', [], $headers); } + + /** + * @param array $headers + * @return array + */ + public function getLanguages(array $headers = []): array + { + return $this->get('configuration/languages', [], $headers); + } } diff --git a/lib/Tmdb/Api/Find.php b/lib/Tmdb/Api/Find.php index 66b3a7b4..8d29b9b2 100644 --- a/lib/Tmdb/Api/Find.php +++ b/lib/Tmdb/Api/Find.php @@ -37,12 +37,12 @@ class Find extends AbstractApi * @param string $id * @param array $parameters * @param array $headers - * @return mixed + * @return array */ - public function findBy($id, array $parameters = [], array $headers = []) + public function findBy(string $id, array $parameters = [], array $headers = []): array { return $this->get( - sprintf('find/%s', $id), + 'find/' . $id, $parameters, $headers ); diff --git a/lib/Tmdb/Api/Lists.php b/lib/Tmdb/Api/Lists.php index d5f5b646..b6dcf4c4 100644 --- a/lib/Tmdb/Api/Lists.php +++ b/lib/Tmdb/Api/Lists.php @@ -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) @@ -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) diff --git a/lib/Tmdb/Api/Tv.php b/lib/Tmdb/Api/Tv.php index ea43d3e6..ab6f0af3 100644 --- a/lib/Tmdb/Api/Tv.php +++ b/lib/Tmdb/Api/Tv.php @@ -289,11 +289,13 @@ public function rateTvShow($id, $rating) * Get the alternative titles for a specific show ID. * * @param integer $id + * @param array $parameters + * @param array $headers * @return mixed */ - public function getAlternativeTitles($id) + public function getAlternativeTitles($id, array $parameters = [], array $headers = []) { - return $this->get('tv/' . $id . '/alternative_titles'); + return $this->get('tv/' . $id . '/alternative_titles', $parameters, $headers); } /** diff --git a/lib/Tmdb/Client.php b/lib/Tmdb/Client.php index 439e1c7e..36468168 100644 --- a/lib/Tmdb/Client.php +++ b/lib/Tmdb/Client.php @@ -264,9 +264,9 @@ public function getGuestSessionToken(): ?GuestSessionToken /** * @param GuestSessionToken|null $guestSessionToken - * @return $this + * @return self */ - public function setGuestSessionToken(GuestSessionToken $guestSessionToken): Client + public function setGuestSessionToken(?GuestSessionToken $guestSessionToken): Client { $this->options['guest_session_token'] = $guestSessionToken; diff --git a/lib/Tmdb/Event/HydrationEvent.php b/lib/Tmdb/Event/HydrationEvent.php index 3fbf8be5..15a3052b 100644 --- a/lib/Tmdb/Event/HydrationEvent.php +++ b/lib/Tmdb/Event/HydrationEvent.php @@ -63,7 +63,7 @@ public function getSubject(): AbstractModel /** * @param AbstractModel $subject - * @return $this + * @return self */ public function setSubject(AbstractModel $subject): HydrationEvent { @@ -82,7 +82,7 @@ public function getData(): array /** * @param array $data - * @return $this + * @return self */ public function setData(array $data = []): HydrationEvent { @@ -109,9 +109,9 @@ public function getLastRequest(): ?RequestInterface /** * @param RequestInterface|null $lastRequest - * @return $this + * @return self */ - public function setLastRequest(RequestInterface $lastRequest = null): HydrationEvent + public function setLastRequest(?RequestInterface $lastRequest = null): HydrationEvent { $this->lastRequest = $lastRequest; @@ -128,9 +128,9 @@ public function getLastResponse(): ?ResponseInterface /** * @param ResponseInterface|null $lastResponse - * @return $this + * @return self */ - public function setLastResponse(ResponseInterface $lastResponse = null): HydrationEvent + public function setLastResponse(?ResponseInterface $lastResponse = null): HydrationEvent { $this->lastResponse = $lastResponse; diff --git a/lib/Tmdb/Event/Listener/Logger/LogApiErrorListener.php b/lib/Tmdb/Event/Listener/Logger/LogApiErrorListener.php index 2c1878d4..431fe055 100644 --- a/lib/Tmdb/Event/Listener/Logger/LogApiErrorListener.php +++ b/lib/Tmdb/Event/Listener/Logger/LogApiErrorListener.php @@ -40,7 +40,7 @@ class LogApiErrorListener * @param LoggerInterface $logger * @param TmdbApiExceptionFormatterInterface|null $formatter */ - public function __construct(LoggerInterface $logger, TmdbApiExceptionFormatterInterface $formatter = null) + public function __construct(LoggerInterface $logger, ?TmdbApiExceptionFormatterInterface $formatter = null) { $this->logger = $logger; $this->formatter = $formatter ?: new SimpleTmdbApiExceptionFormatter(); diff --git a/lib/Tmdb/Event/Listener/Logger/LogHttpMessageListener.php b/lib/Tmdb/Event/Listener/Logger/LogHttpMessageListener.php index 8f0d3689..16f1bfd3 100644 --- a/lib/Tmdb/Event/Listener/Logger/LogHttpMessageListener.php +++ b/lib/Tmdb/Event/Listener/Logger/LogHttpMessageListener.php @@ -44,7 +44,7 @@ class LogHttpMessageListener * @param LoggerInterface $logger * @param HttpMessageFormatterInterface|null $formatter */ - public function __construct(LoggerInterface $logger, HttpMessageFormatterInterface $formatter = null) + public function __construct(LoggerInterface $logger, ?HttpMessageFormatterInterface $formatter = null) { $this->logger = $logger; $this->formatter = $formatter ?: new SimpleHttpMessageFormatter(); @@ -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); } } diff --git a/lib/Tmdb/Event/Listener/Logger/LogHydrationListener.php b/lib/Tmdb/Event/Listener/Logger/LogHydrationListener.php index 6cd5f467..40ab81be 100644 --- a/lib/Tmdb/Event/Listener/Logger/LogHydrationListener.php +++ b/lib/Tmdb/Event/Listener/Logger/LogHydrationListener.php @@ -32,7 +32,7 @@ class LogHydrationListener private $logger; /** - * @var HttpMessageFormatterInterface + * @var HydrationFormatterInterface */ private $formatter; @@ -49,7 +49,7 @@ class LogHydrationListener */ public function __construct( LoggerInterface $logger, - HydrationFormatterInterface $formatter = null, + ?HydrationFormatterInterface $formatter = null, bool $withData = false ) { $this->logger = $logger; @@ -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( diff --git a/lib/Tmdb/Event/Listener/Request/SessionTokenRequestListener.php b/lib/Tmdb/Event/Listener/Request/SessionTokenRequestListener.php index 188656ae..cb550834 100644 --- a/lib/Tmdb/Event/Listener/Request/SessionTokenRequestListener.php +++ b/lib/Tmdb/Event/Listener/Request/SessionTokenRequestListener.php @@ -23,7 +23,7 @@ class SessionTokenRequestListener { /** - * @var string + * @var SessionToken */ private $token; diff --git a/lib/Tmdb/Event/Listener/Request/UserAgentRequestListener.php b/lib/Tmdb/Event/Listener/Request/UserAgentRequestListener.php index 1b25178f..0190003d 100644 --- a/lib/Tmdb/Event/Listener/Request/UserAgentRequestListener.php +++ b/lib/Tmdb/Event/Listener/Request/UserAgentRequestListener.php @@ -28,7 +28,7 @@ class UserAgentRequestListener * UserAgentRequestListener constructor. * @param string|null $userAgent */ - public function __construct(string $userAgent = null) + public function __construct(?string $userAgent = null) { $this->userAgent = $userAgent ?? sprintf('php-tmdb/api/%s', Client::VERSION); } diff --git a/lib/Tmdb/Event/RequestEvent.php b/lib/Tmdb/Event/RequestEvent.php index d52bcb39..e8997afd 100644 --- a/lib/Tmdb/Event/RequestEvent.php +++ b/lib/Tmdb/Event/RequestEvent.php @@ -30,12 +30,12 @@ class RequestEvent extends StoppableEvent implements LoggableHttpEventInterface private $request; /** - * @var ResponseInterface + * @var ?ResponseInterface */ private $response; /** - * @var SessionToken + * @var ?SessionToken */ private $sessionToken; @@ -45,7 +45,7 @@ class RequestEvent extends StoppableEvent implements LoggableHttpEventInterface * @param RequestInterface $request * @param SessionToken|null $sessionToken */ - public function __construct(RequestInterface $request, SessionToken $sessionToken = null) + public function __construct(RequestInterface $request, ?SessionToken $sessionToken = null) { $this->request = $request; $this->sessionToken = $sessionToken; @@ -61,7 +61,7 @@ public function getRequest(): RequestInterface /** * @param RequestInterface $request - * @return $this + * @return self */ public function setRequest(RequestInterface $request): RequestEvent { @@ -71,7 +71,7 @@ public function setRequest(RequestInterface $request): RequestEvent } /** - * @return ResponseInterface + * @return ?ResponseInterface */ public function getResponse(): ?ResponseInterface { @@ -80,7 +80,7 @@ public function getResponse(): ?ResponseInterface /** * @param ResponseInterface $response - * @return $this + * @return self */ public function setResponse(ResponseInterface $response): RequestEvent { @@ -98,18 +98,18 @@ public function hasResponse() } /** - * @return SessionToken + * @return ?SessionToken */ - public function getSessionToken(): SessionToken + public function getSessionToken(): ?SessionToken { return $this->sessionToken; } /** * @param SessionToken|null $sessionToken - * @return $this + * @return self */ - public function setSessionToken(SessionToken $sessionToken = null): RequestEvent + public function setSessionToken(?SessionToken $sessionToken = null): RequestEvent { $this->sessionToken = $sessionToken; diff --git a/lib/Tmdb/Event/ResponseEvent.php b/lib/Tmdb/Event/ResponseEvent.php index 6a5b8385..e928a962 100644 --- a/lib/Tmdb/Event/ResponseEvent.php +++ b/lib/Tmdb/Event/ResponseEvent.php @@ -17,7 +17,6 @@ use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use Symfony\Contracts\EventDispatcher\Event; -use Tmdb\HttpClient\Request; class ResponseEvent implements LoggableHttpEventInterface { @@ -52,8 +51,8 @@ public function getRequest(): RequestInterface } /** - * @param Request $request - * @return $this + * @param RequestInterface $request + * @return self */ public function setRequest($request) { @@ -72,7 +71,7 @@ public function getResponse(): ResponseInterface /** * @param ResponseInterface $response - * @return $this + * @return self */ public function setResponse(ResponseInterface $response) { diff --git a/lib/Tmdb/Exception/TmdbApiException.php b/lib/Tmdb/Exception/TmdbApiException.php index 3da0ebb2..402eb530 100644 --- a/lib/Tmdb/Exception/TmdbApiException.php +++ b/lib/Tmdb/Exception/TmdbApiException.php @@ -81,9 +81,9 @@ class TmdbApiException extends Exception public function __construct( int $code, string $message, - RequestInterface $request = null, - ResponseInterface $response = null, - Exception $previous = null + ?RequestInterface $request = null, + ?ResponseInterface $response = null, + ?Exception $previous = null ) { parent::__construct($message, $code, $previous); @@ -101,7 +101,7 @@ public function getRequest() /** * @param RequestInterface $request - * @return $this + * @return self */ public function setRequest(RequestInterface $request): TmdbApiException { @@ -120,7 +120,7 @@ public function getResponse() /** * @param ResponseInterface $response - * @return $this + * @return self */ public function setResponse(ResponseInterface $response): TmdbApiException { diff --git a/lib/Tmdb/Factory/AbstractFactory.php b/lib/Tmdb/Factory/AbstractFactory.php index 978ed689..74eeafe1 100644 --- a/lib/Tmdb/Factory/AbstractFactory.php +++ b/lib/Tmdb/Factory/AbstractFactory.php @@ -29,6 +29,9 @@ /** * Class AbstractFactory + * + * @template T of AbstractModel + * * @package Tmdb\Factory */ abstract class AbstractFactory @@ -52,7 +55,7 @@ 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 = []); @@ -60,19 +63,20 @@ 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 */ abstract public function createCollection(array $data = []); /** * Create a result collection * - * @param array $data + * @param null|array $data * @param string $method - * @return ResultCollection + * @return ResultCollection */ - public function createResultCollection($data = [], $method = 'create') + public function createResultCollection($data = [], $method = 'create'): ResultCollection { + /** @var ResultCollection */ $collection = new ResultCollection(); if (null === $data) { @@ -106,7 +110,7 @@ public function createResultCollection($data = [], $method = 'create') * Create rating * * @param array $data - * @return AbstractModel + * @return Rating */ public function createRating(array $data = []) { @@ -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 = []) { @@ -167,7 +173,7 @@ protected function getHttpClient() * Create the account states * * @param array $data - * @return AbstractModel + * @return AccountStates */ public function createAccountStates(array $data = []) { @@ -190,7 +196,7 @@ public function createAccountStates(array $data = []) * Create result * * @param array $data - * @return AbstractModel + * @return Result */ public function createResult(array $data = []) { @@ -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 */ - 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.'); @@ -215,12 +222,9 @@ protected function createGenericCollection(array $data = [], AbstractModel $clas $class = get_class($class); } + /** @var GenericCollection */ $collection = new GenericCollection(); - if (null === $data) { - return $collection; - } - foreach ($data as $item) { $collection->add(null, $this->hydrate(new $class(), $item)); } @@ -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 * @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)); } @@ -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 */ protected function createGenericCollectionFromMediaTypes($data = []) { diff --git a/lib/Tmdb/Factory/Account/AvatarFactory.php b/lib/Tmdb/Factory/Account/AvatarFactory.php index 72781954..f345ab32 100644 --- a/lib/Tmdb/Factory/Account/AvatarFactory.php +++ b/lib/Tmdb/Factory/Account/AvatarFactory.php @@ -28,7 +28,7 @@ class AvatarFactory extends AbstractFactory /** * {@inheritdoc} */ - public function createCollection(array $data = []) + public function createCollection(array $data = []): GenericCollection { // @todo 4.0.x double check on this bug if (array_key_exists(0, $data)) { diff --git a/lib/Tmdb/Factory/AccountFactory.php b/lib/Tmdb/Factory/AccountFactory.php index 09f0e62c..b56abba8 100644 --- a/lib/Tmdb/Factory/AccountFactory.php +++ b/lib/Tmdb/Factory/AccountFactory.php @@ -23,6 +23,7 @@ /** * Class AccountFactory + * @extends AbstractFactory * @package Tmdb\Factory */ class AccountFactory extends AbstractFactory @@ -67,7 +68,7 @@ public function __construct(HttpClient $httpClient) * * @return Account */ - public function create(array $data = []) + public function create(array $data = []): Account { $account = new Account(); @@ -120,7 +121,7 @@ public function getMovieFactory() /** * @param MovieFactory $movieFactory - * @return $this + * @return self */ public function setMovieFactory($movieFactory) { @@ -151,7 +152,7 @@ public function getTvFactory() /** * @param TvFactory $tvFactory - * @return $this + * @return self */ public function setTvFactory($tvFactory) { @@ -187,7 +188,7 @@ public function getImageFactory() /** * @param ImageFactory $imageFactory - * @return $this + * @return self */ public function setImageFactory($imageFactory) { @@ -210,7 +211,7 @@ public function createCollection(array $data = []) /** * @param AvatarFactory $avatarFactory - * @return $this + * @return self */ public function setAvatarFactory($avatarFactory) { diff --git a/lib/Tmdb/Factory/AuthenticationFactory.php b/lib/Tmdb/Factory/AuthenticationFactory.php index 17d6f2dc..fef26d0e 100644 --- a/lib/Tmdb/Factory/AuthenticationFactory.php +++ b/lib/Tmdb/Factory/AuthenticationFactory.php @@ -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; @@ -29,7 +31,7 @@ class AuthenticationFactory extends AbstractFactory /** * @param array $data * - * @return void + * @return AbstractModel * @throws RuntimeException */ public function create(array $data = []) @@ -44,7 +46,7 @@ public function create(array $data = []) /** * @param array $data * - * @return void + * @return GenericCollection * @throws RuntimeException */ public function createCollection(array $data = []) @@ -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 = []) { diff --git a/lib/Tmdb/Factory/CertificationFactory.php b/lib/Tmdb/Factory/CertificationFactory.php index 359e179d..a27234ef 100644 --- a/lib/Tmdb/Factory/CertificationFactory.php +++ b/lib/Tmdb/Factory/CertificationFactory.php @@ -26,7 +26,7 @@ class CertificationFactory extends AbstractFactory /** * {@inheritdoc} */ - public function createCollection(array $data = []) + public function createCollection(array $data = []): GenericCollection { if (array_key_exists('certifications', $data)) { $data = $data['certifications']; @@ -53,9 +53,9 @@ public function createCollection(array $data = []) /** * @param array $data * - * @return Certification + * @return Certification\CountryCertification */ - public function create(array $data = []) + public function create(array $data = []): Certification\CountryCertification { return $this->hydrate(new Certification\CountryCertification(), $data); } diff --git a/lib/Tmdb/Factory/ChangesFactory.php b/lib/Tmdb/Factory/ChangesFactory.php index 08915835..71064d2a 100644 --- a/lib/Tmdb/Factory/ChangesFactory.php +++ b/lib/Tmdb/Factory/ChangesFactory.php @@ -26,7 +26,7 @@ class ChangesFactory extends AbstractFactory /** * {@inheritdoc} */ - public function createCollection(array $data = []) + public function createCollection(array $data = []): Changes { $collection = new Changes(); @@ -57,7 +57,7 @@ public function createCollection(array $data = []) * {@inheritdoc} * @return Change */ - public function create(array $data = []) + public function create(array $data = []): Change { return $this->hydrate(new Change(), $data); } diff --git a/lib/Tmdb/Factory/CollectionFactory.php b/lib/Tmdb/Factory/CollectionFactory.php index 0c3b9768..d870e3eb 100644 --- a/lib/Tmdb/Factory/CollectionFactory.php +++ b/lib/Tmdb/Factory/CollectionFactory.php @@ -51,7 +51,7 @@ public function __construct(HttpClient $httpClient) /** * {@inheritdoc} */ - public function createCollection(array $data = []) + public function createCollection(array $data = []): GenericCollection { $collection = new GenericCollection(); @@ -66,7 +66,7 @@ public function createCollection(array $data = []) * {@inheritdoc} * @return Collection */ - public function create(array $data = []) + public function create(array $data = []): Collection { $collection = new Collection(); @@ -120,7 +120,7 @@ public function getMovieFactory() /** * @param MovieFactory $movieFactory - * @return $this + * @return self */ public function setMovieFactory($movieFactory) { @@ -139,7 +139,7 @@ public function getImageFactory() /** * @param ImageFactory $imageFactory - * @return $this + * @return self */ public function setImageFactory($imageFactory) { diff --git a/lib/Tmdb/Factory/Common/ChangeFactory.php b/lib/Tmdb/Factory/Common/ChangeFactory.php index 590cc7d0..c06645b7 100644 --- a/lib/Tmdb/Factory/Common/ChangeFactory.php +++ b/lib/Tmdb/Factory/Common/ChangeFactory.php @@ -16,6 +16,7 @@ use Tmdb\Factory\AbstractFactory; use Tmdb\Model\AbstractModel; +use Tmdb\Model\Collection\Changes; use Tmdb\Model\Common\Change; use Tmdb\Model\Common\GenericCollection; @@ -28,9 +29,9 @@ class ChangeFactory extends AbstractFactory /** * {@inheritdoc} */ - public function createCollection(array $data = []) + public function createCollection(array $data = []): Changes { - $collection = new GenericCollection(); + $collection = new Changes(); if (array_key_exists('changes', $data)) { $data = $data['changes']; @@ -46,7 +47,7 @@ public function createCollection(array $data = []) /** * {@inheritdoc} */ - public function create(array $data = []) + public function create(array $data = []): Change { $change = new Change(); @@ -69,9 +70,9 @@ public function create(array $data = []) * Create individual change items * * @param array $data - * @return AbstractModel + * @return Change\Item */ - private function createChangeItem(array $data = []) + private function createChangeItem(array $data = []): Change\Item { return $this->hydrate(new Change\Item(), $data); } diff --git a/lib/Tmdb/Factory/Common/VideoFactory.php b/lib/Tmdb/Factory/Common/VideoFactory.php index 5c0f5e2e..887a114a 100644 --- a/lib/Tmdb/Factory/Common/VideoFactory.php +++ b/lib/Tmdb/Factory/Common/VideoFactory.php @@ -21,6 +21,7 @@ /** * Class VideoFactory + * @extends AbstractFactory