diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml index 8c69385b..f9635b42 100644 --- a/.github/workflows/coding-standards.yml +++ b/.github/workflows/coding-standards.yml @@ -5,16 +5,16 @@ on: ["pull_request"] jobs: coding-standards: name: "Coding Standards" - runs-on: "ubuntu-20.04" + runs-on: "ubuntu-latest" strategy: matrix: php-version: - - "7.4" + - "8.3" steps: - name: "Checkout" - uses: "actions/checkout@v2" + uses: "actions/checkout@v3" with: fetch-depth: 10 @@ -26,7 +26,7 @@ jobs: tools: "cs2pr" - name: "Cache dependencies installed with Composer" - uses: "actions/cache@v2" + uses: "actions/cache@v3" with: path: "~/.composer/cache" key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}" diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 349b15fd..8d14dce2 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -8,14 +8,13 @@ env: jobs: phpunit: name: "PHPUnit" - runs-on: "ubuntu-20.04" + runs-on: "ubuntu-latest" strategy: matrix: php-version: - - "7.4" - - "8.0" - - "8.1" + - "8.3" + - "8.4" deps: - "normal" symfony-require: @@ -23,36 +22,39 @@ jobs: symfony-deprecations-helper: - "" include: - - php-version: "7.4" + # PHP 8.3 test matrix + - php-version: "8.3" deps: "normal" - - php-version: "7.4" + - php-version: "8.3" deps: "low" - - php-version: "7.4" + - php-version: "8.3" deps: "dev" - - - php-version: "8.0" + + # Test Symfony 7 with PHP 8.3 + - php-version: "8.3" deps: "normal" - - - php-version: "8.0" - deps: "low" - - - php-version: "8.0" - deps: "dev" - - - php-version: "8.1" + symfony-require: "7.0.*" + + # PHP 8.4 test matrix + - php-version: "8.4" deps: "normal" - - php-version: "8.1" + - php-version: "8.4" deps: "low" - - php-version: "8.1" + - php-version: "8.4" deps: "dev" + + # Test latest Symfony with PHP 8.4 + - php-version: "8.4" + deps: "normal" + symfony-require: "7.*" steps: - name: "Checkout" - uses: "actions/checkout@v2" + uses: "actions/checkout@v3" with: fetch-depth: 2 @@ -60,14 +62,26 @@ jobs: uses: "shivammathur/setup-php@v2" with: php-version: "${{ matrix.php-version }}" + extensions: "json" + tools: "composer:2" + coverage: "pcov" + ini-values: "memory_limit=-1" - name: "Cache dependencies installed with composer" - uses: "actions/cache@v2" + uses: "actions/cache@v3" with: path: "~/.composer/cache" key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}" restore-keys: "php-${{ matrix.php-version }}-composer-locked-" + - name: "Require specific Symfony version" + run: "composer global require --no-progress --no-scripts --no-plugins 'symfony/flex:^2.3'" + if: "${{ matrix.symfony-require != '' }}" + + - name: "Set Symfony version constraint" + run: "composer config extra.symfony.require ${{ matrix.symfony-require }}" + if: "${{ matrix.symfony-require != '' }}" + - name: "Install stable dependencies with composer" run: "composer update --no-interaction --prefer-dist --prefer-stable" if: "${{ matrix.deps == 'normal' }}" @@ -86,9 +100,9 @@ jobs: - name: "Upload coverage file" uses: "actions/upload-artifact@v4" with: - name: "phpunit-${{ matrix.php-version }}-${{ matrix.deps }}-${{ hashFiles('composer.lock') }}.coverage" + name: "phpunit-${{ matrix.php-version }}-${{ matrix.deps }}-${{ matrix.symfony-require }}-${{ hashFiles('composer.lock') }}.coverage" path: "coverage.xml" - - uses: codecov/codecov-action@v1 + - uses: codecov/codecov-action@v3 with: verbose: true diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 21edc6b6..531b41a2 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -10,9 +10,8 @@ jobs: strategy: matrix: php-version: - - "7.4" - - "8.0" - - "8.1" + - "8.3" + - "8.4" steps: - name: "Checkout code" diff --git a/README.md b/README.md index b3f3151f..ed99390f 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [![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) +[![PHP](https://img.shields.io/badge/php->=8.2-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) Tests run with minimal, normal and development dependencies. diff --git a/UPGRADE-CURRENT.md b/UPGRADE-CURRENT.md new file mode 100644 index 00000000..b84e4dda --- /dev/null +++ b/UPGRADE-CURRENT.md @@ -0,0 +1,9 @@ +# UPGRADE-CURRENT.md + +## Changes in this version + +- Removed `rtheunissen/guzzle-log-middleware` dependency due to compatibility issues with Guzzle 7.0. This middleware is temporarily removed and may be reintroduced in a future release once compatibility is resolved. +- Added support for Symfony 7 components. Note that Symfony 7 requires PHP 8.1 or higher. If you're using PHP < 8.1, Composer will automatically select a compatible Symfony version (4, 5, or 6). +- Dropped support for PHP 7.4 and 8.0 as they have reached End-of-Life (EOL). +- Dropped support for PHP 8.1 and updated minimum PHP version to 8.2 to accommodate PHPUnit 12. +- Upgraded PHPUnit from 9.x to 12.x. \ No newline at end of file diff --git a/composer.json b/composer.json index 79a56e52..a39ba5a4 100644 --- a/composer.json +++ b/composer.json @@ -31,36 +31,36 @@ "license": "MIT", "name": "php-tmdb/api", "require": { - "php": "^7.3 || ^8.0", + "php": "^8.3", "ext-json": "*", - "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", + "php-http/discovery": "^1.11 || ^2.0", "psr/http-client": "^1", "psr/http-client-implementation": "^1", "psr/http-factory": "^1", "psr/http-factory-implementation": "^1", - "psr/http-message": "^1" + "psr/http-message": "^1 || ^2", + "phpunit/phpunit": "^12.1" }, "require-dev": { "nyholm/psr7": "^1.2", - "php-http/mock-client": "^1.2", + "php-http/mock-client": "^1.2 || ^2.0", "slevomat/coding-standard": "^8.8", "squizlabs/php_codesniffer": "^3.5.8", - "symfony/cache": "^4.4 || ^5 || ^6", - "symfony/event-dispatcher": "^4.4 || ^5 || ^6", + "symfony/cache": "^7.0", + "symfony/event-dispatcher": "^7.0", "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" + "php-http/cache-plugin": "^1.7 || ^2.0", + "jeroen/psr-log-test-doubles": "^2.1 || ^3", + "symfony/options-resolver": "^7.0" }, "scripts": { "test": "vendor/bin/phpunit", @@ -81,7 +81,7 @@ "config": { "allow-plugins": { "dealerdirect/phpcodesniffer-composer-installer": true, - "php-http/discovery": false + "php-http/discovery": true } } } diff --git a/lib/Tmdb/Api/AbstractApi.php b/lib/Tmdb/Api/AbstractApi.php index aba79069..c912ab71 100644 --- a/lib/Tmdb/Api/AbstractApi.php +++ b/lib/Tmdb/Api/AbstractApi.php @@ -1,14 +1,16 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ @@ -23,151 +25,104 @@ use Tmdb\HttpClient\HttpClient; /** - * Class AbstractApi - * @package Tmdb\Api + * Class AbstractApi. */ abstract class AbstractApi implements ApiInterface { /** - * The client - * - * @var Client - */ - protected $client; - - /** - * Constructor - * - * @param Client $client + * Constructor. */ - public function __construct(Client $client) + public function __construct( + /** + * The client. + */ + protected \Tmdb\Client $client + ) { - $this->client = $client; } /** - * Send a GET request - * - * @param string $path - * @param array $parameters - * @param array $headers - * @return array + * Send a GET request. */ public function get(string $path, array $parameters = [], array $headers = []): array { return $this->decodeResponse( - $this->getHttpClient()->send($path, 'GET', $parameters, $headers) + $this->getHttpClient()->send($path, 'GET', $parameters, $headers), ); } /** - * Send a POST request - * - * @param string $path - * @param null $postBody - * @param array $parameters - * @param array $headers - * @return array + * Send a POST request. */ public function post(string $path, $postBody = null, array $parameters = [], array $headers = []): array { return $this->decodeResponse( - $this->getHttpClient()->send($path, 'POST', $parameters, $headers, $postBody) + $this->getHttpClient()->send($path, 'POST', $parameters, $headers, $postBody), ); } /** - * Send a POST request but json_encode the post body in the request + * Send a POST request but json_encode the post body in the request. * - * @param string $path - * @param mixed $postBody - * @param array $parameters - * @param array $headers - * @return array * @throws InvalidArgumentException */ public function postJson(string $path, $postBody = null, array $parameters = [], array $headers = []): array { try { - if (is_array($postBody)) { + if (\is_array($postBody)) { $postBody = json_encode($postBody, JSON_THROW_ON_ERROR); } return $this->post($path, $postBody, $parameters, $headers); } catch (JsonException $e) { - throw new InvalidArgumentException( - 'Unable to json_encode the data provided.', - 0, - $e - ); + throw new InvalidArgumentException('Unable to json_encode the data provided.', 0, $e); } } /** - * Send a HEAD request - * - * @param string $path - * @param array $parameters - * @param array $headers - * @return array + * Send a HEAD request. */ public function head(string $path, array $parameters = [], array $headers = []): array { return $this->decodeResponse( - $this->getHttpClient()->send($path, 'HEAD', $parameters, $headers) + $this->getHttpClient()->send($path, 'HEAD', $parameters, $headers), ); } /** - * Send a PUT request - * - * @param string $path - * @param null $body - * @param array $parameters - * @param array $headers - * @return array + * Send a PUT request. */ public function put(string $path, $body = null, array $parameters = [], array $headers = []): array { return $this->decodeResponse( - $this->getHttpClient()->send($path, 'PUT', $parameters, $headers, $body) + $this->getHttpClient()->send($path, 'PUT', $parameters, $headers, $body), ); } /** - * Send a DELETE request - * - * @param string $path - * @param null $body - * @param array $parameters - * @param array $headers - * @return array + * Send a DELETE request. */ public function delete(string $path, $body = null, array $parameters = [], array $headers = []): array { return $this->decodeResponse( - $this->getHttpClient()->send($path, 'DELETE', $parameters, $headers, $body) + $this->getHttpClient()->send($path, 'DELETE', $parameters, $headers, $body), ); } /** - * Send a PATCH request + * Send a PATCH request. * - * @param string $path * @param string|null $body - * @param array $parameters - * @param array $headers - * @return array */ public function patch(string $path, $body = null, array $parameters = [], array $headers = []): array { return $this->decodeResponse( - $this->getHttpClient()->send($path, 'PATCH', $parameters, $headers, $body) + $this->getHttpClient()->send($path, 'PATCH', $parameters, $headers, $body), ); } /** - * Retrieve the client + * Retrieve the client. * * @return Client */ @@ -177,7 +132,7 @@ public function getClient() } /** - * Retrieve the http client + * Retrieve the http client. * * @return HttpClient */ @@ -187,29 +142,36 @@ public function getHttpClient() } /** - * Decode the response + * Decode the response. * - * @param ResponseInterface $response * @return array + * + * @throws UnexpectedResponseException */ private function decodeResponse(ResponseInterface $response) { - try { - if ($response->getBody() instanceof StreamInterface) { - return json_decode((string)$response->getBody(), true, 512, JSON_THROW_ON_ERROR); + if (!$response->getBody() instanceof StreamInterface) { + throw new UnexpectedResponseException('Response body is not a valid StreamInterface instance', $response->getStatusCode()); + } + + $body = (string) $response->getBody(); + + // If the body is empty, we should still throw an exception + // Empty responses are only acceptable for 204 No Content responses + if ($body === '' || $body === '0') { + if (204 === $response->getStatusCode()) { + return []; } - return []; + throw new UnexpectedResponseException(\sprintf('Empty response body with status code %d', $response->getStatusCode()), $response->getStatusCode()); + } + + try { + // Decode any response with a valid JSON body, regardless of status code + // This ensures we capture error details from 4xx/5xx responses + return json_decode($body, true, 512, JSON_THROW_ON_ERROR); } catch (JsonException $e) { - throw new UnexpectedResponseException( - sprintf( - 'Unable to decode response with body "%s", %s.', - (string)$response->getBody(), - json_last_error_msg() - ), - $response->getStatusCode(), - $e - ); + throw new UnexpectedResponseException(\sprintf('Unable to decode response with body "%s", %s.', $body, json_last_error_msg()), $response->getStatusCode(), $e); } } } diff --git a/lib/Tmdb/Api/Account.php b/lib/Tmdb/Api/Account.php index fab3670e..d51f166e 100644 --- a/lib/Tmdb/Api/Account.php +++ b/lib/Tmdb/Api/Account.php @@ -1,34 +1,32 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ namespace Tmdb\Api; /** - * Class Account - * @package Tmdb\Api + * Class Account. + * * @see http://docs.themoviedb.apiary.io/#account */ class Account extends AbstractApi { /** * Get the basic information for an account. You will need to have a valid session id. - * - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getAccount(array $parameters = [], array $headers = []) + public function getAccount(array $parameters = [], array $headers = []): array { return $this->get('account', $parameters, $headers); } @@ -37,11 +35,8 @@ public function getAccount(array $parameters = [], array $headers = []) * Get the lists that you have created and marked as a favorite. * * @param int|string $accountId - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getLists($accountId, array $parameters = [], array $headers = []) + public function getLists($accountId, array $parameters = [], array $headers = []): array { return $this->get('account/' . $accountId . '/lists', $parameters, $headers); } @@ -50,11 +45,8 @@ public function getLists($accountId, array $parameters = [], array $headers = [] * Get the list of favorite movies for an account. * * @param int|string $accountId - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getFavoriteMovies($accountId, array $parameters = [], array $headers = []) + public function getFavoriteMovies($accountId, array $parameters = [], array $headers = []): array { return $this->get('account/' . $accountId . '/favorite/movies', $parameters, $headers); } @@ -63,11 +55,8 @@ public function getFavoriteMovies($accountId, array $parameters = [], array $hea * Get the list of favorite TV series for an account. * * @param int|string $accountId - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getFavoriteTvShows($accountId, array $parameters = [], array $headers = []) + public function getFavoriteTvShows($accountId, array $parameters = [], array $headers = []): array { return $this->get('account/' . $accountId . '/favorite/tv', $parameters, $headers); } @@ -76,17 +65,16 @@ public function getFavoriteTvShows($accountId, array $parameters = [], array $he * Add or remove a movie to an accounts favorite list. * * @param int|string $accountId - * @param integer $mediaId - * @param boolean $isFavorite - * @param string $mediaType Either movie or tv - * @return mixed + * @param int $mediaId + * @param bool $isFavorite + * @param string $mediaType Either movie or tv */ - public function favorite($accountId, $mediaId, $isFavorite = true, $mediaType = 'movie') + public function favorite($accountId, $mediaId, $isFavorite = true, $mediaType = 'movie'): array { return $this->postJson('account/' . $accountId . '/favorite', [ 'media_id' => $mediaId, 'media_type' => $mediaType, - 'favorite' => $isFavorite + 'favorite' => $isFavorite, ]); } @@ -94,11 +82,8 @@ public function favorite($accountId, $mediaId, $isFavorite = true, $mediaType = * Get the list of rated movies (and associated rating) for an account. * * @param int|string $accountId - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getRatedMovies($accountId, array $parameters = [], array $headers = []) + public function getRatedMovies($accountId, array $parameters = [], array $headers = []): array { return $this->get('account/' . $accountId . '/rated/movies', $parameters, $headers); } @@ -107,11 +92,8 @@ public function getRatedMovies($accountId, array $parameters = [], array $header * Get the list of rated TV shows (and associated rating) for an account. * * @param int|string $accountId - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getRatedTvShows($accountId, array $parameters = [], array $headers = []) + public function getRatedTvShows($accountId, array $parameters = [], array $headers = []): array { return $this->get('account/' . $accountId . '/rated/tv', $parameters, $headers); } @@ -120,11 +102,8 @@ public function getRatedTvShows($accountId, array $parameters = [], array $heade * Get the list of movies on an accounts watchlist. * * @param int|string $accountId - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getMovieWatchlist($accountId, array $parameters = [], array $headers = []) + public function getMovieWatchlist($accountId, array $parameters = [], array $headers = []): array { return $this->get('account/' . $accountId . '/watchlist/movies', $parameters, $headers); } @@ -133,11 +112,8 @@ public function getMovieWatchlist($accountId, array $parameters = [], array $hea * Get the list of TV series on an accounts watchlist. * * @param int|string $accountId - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getTvWatchlist($accountId, array $parameters = [], array $headers = []) + public function getTvWatchlist($accountId, array $parameters = [], array $headers = []): array { return $this->get('account/' . $accountId . '/watchlist/tv', $parameters, $headers); } @@ -146,17 +122,16 @@ public function getTvWatchlist($accountId, array $parameters = [], array $header * Add or remove a movie to an accounts watch list. * * @param int|string $accountId - * @param integer $mediaId - * @param boolean $isOnWatchlist - * @param string $mediaType Either movie or tv - * @return mixed + * @param int $mediaId + * @param bool $isOnWatchlist + * @param string $mediaType Either movie or tv */ - public function watchlist($accountId, $mediaId, $isOnWatchlist = true, $mediaType = 'movie') + public function watchlist($accountId, $mediaId, $isOnWatchlist = true, $mediaType = 'movie'): array { return $this->postJson('account/' . $accountId . '/watchlist', [ 'media_id' => $mediaId, 'media_type' => $mediaType, - 'watchlist' => $isOnWatchlist + 'watchlist' => $isOnWatchlist, ]); } } diff --git a/lib/Tmdb/Api/ApiInterface.php b/lib/Tmdb/Api/ApiInterface.php index d1a5ece7..4e2d6e5d 100644 --- a/lib/Tmdb/Api/ApiInterface.php +++ b/lib/Tmdb/Api/ApiInterface.php @@ -1,22 +1,23 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ namespace Tmdb\Api; /** - * Interface ApiInterface - * @package Tmdb\Api + * Interface ApiInterface. */ interface ApiInterface { diff --git a/lib/Tmdb/Api/Authentication.php b/lib/Tmdb/Api/Authentication.php index 6a0b618c..cd4508d2 100644 --- a/lib/Tmdb/Api/Authentication.php +++ b/lib/Tmdb/Api/Authentication.php @@ -1,14 +1,16 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ @@ -20,8 +22,8 @@ use Tmdb\Token\Session\RequestToken; /** - * Class Authentication - * @package Tmdb\Api + * Class Authentication. + * * @see http://docs.themoviedb.apiary.io/#authentication */ class Authentication extends AbstractApi @@ -34,38 +36,34 @@ class Authentication extends AbstractApi * * You can generate any number of request tokens but they will expire after 60 minutes. * As soon as a valid session id has been created the token will be destroyed. - * - * @return mixed */ - public function getNewToken() + public function getNewToken(): array { return $this->get('authentication/token/new'); } /** - * Redirect the user to authenticate the request token + * Redirect the user to authenticate the request token. * * @param string $token - * - * @return void */ public function authenticateRequestToken($token): void { - header(sprintf( + header(\sprintf( 'Location: %s/%s', self::REQUEST_TOKEN_URI, - $token + $token, )); } - //@codeCoverageIgnoreEnd + // @codeCoverageIgnoreEnd /** - * Helper method to validate the request_token and obtain a session_token + * Helper method to validate the request_token and obtain a session_token. * * @param RequestToken $requestToken - * @param string $username - * @param string $password - * @return mixed + * @param string $username + * @param string $password + * * @throws InvalidArgumentException */ public function getSessionTokenWithLogin($requestToken, $username, $password) @@ -86,26 +84,26 @@ public function getSessionTokenWithLogin($requestToken, $username, $password) * @param string $requestToken * @param string $username * @param string $password - * @return mixed + * * @throws UnauthorizedRequestTokenException */ - public function validateRequestTokenWithLogin($requestToken, $username, $password) + public function validateRequestTokenWithLogin($requestToken, $username, $password): ?array { try { return $this->get('authentication/token/validate_with_login', [ 'username' => $username, 'password' => $password, - 'request_token' => (string)$requestToken + 'request_token' => (string) $requestToken, ]); - //@codeCoverageIgnoreStart + // @codeCoverageIgnoreStart } catch (Exception $e) { - if ($e->getCode() == 401) { - throw new UnauthorizedRequestTokenException("The request token has not been validated yet."); + if (401 === $e->getCode()) { + throw new UnauthorizedRequestTokenException('The request token has not been validated yet.'); } return null; } - //@codeCoverageIgnoreEnd + // @codeCoverageIgnoreEnd } /** @@ -113,26 +111,27 @@ public function validateRequestTokenWithLogin($requestToken, $username, $passwor * A session id is required in order to use any of the write methods. * * @param array|string $requestToken - * @return mixed + * * @throws UnauthorizedRequestTokenException */ - public function getNewSession($requestToken) + public function getNewSession($requestToken): ?array { try { // @todo 4.0 / 4.1 verify - if (is_array($requestToken)) { + if (\is_array($requestToken)) { $requestToken = $requestToken['request_token']; } - return $this->get('authentication/session/new', ['request_token' => (string)$requestToken]); - //@codeCoverageIgnoreStart + return $this->get('authentication/session/new', ['request_token' => (string) $requestToken]); + + // @codeCoverageIgnoreStart } catch (Exception $e) { - if ($e->getCode() == 401) { - throw new UnauthorizedRequestTokenException("The request token has not been validated yet."); + if (401 === $e->getCode()) { + throw new UnauthorizedRequestTokenException('The request token has not been validated yet.'); } return null; - //@codeCoverageIgnoreEnd + // @codeCoverageIgnoreEnd } } @@ -147,10 +146,8 @@ public function getNewSession($requestToken) * doing the guest session actions. * * If a guest session is not used for the first time within 24 hours, it will be automatically discarded. - * - * @return mixed */ - public function getNewGuestSession() + public function getNewGuestSession(): array { return $this->get('authentication/guest_session/new'); } diff --git a/lib/Tmdb/Api/Certifications.php b/lib/Tmdb/Api/Certifications.php index f7e54794..876d4290 100644 --- a/lib/Tmdb/Api/Certifications.php +++ b/lib/Tmdb/Api/Certifications.php @@ -1,22 +1,24 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ namespace Tmdb\Api; /** - * Class Certifications - * @package Tmdb\Api + * Class Certifications. + * * @see http://docs.themoviedb.apiary.io/#certifications */ class Certifications extends AbstractApi @@ -26,12 +28,8 @@ class Certifications extends AbstractApi * * These can be used in conjunction with the certification_country and * certification.lte parameters when using discover. - * - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getMovieList(array $parameters = [], array $headers = []) + public function getMovieList(array $parameters = [], array $headers = []): array { return $this->get('certification/movie/list', $parameters, $headers); } @@ -41,12 +39,8 @@ public function getMovieList(array $parameters = [], array $headers = []) * * These can be used in conjunction with the certification_country and * certification.lte parameters when using discover. - * - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getTvList(array $parameters = [], array $headers = []) + public function getTvList(array $parameters = [], array $headers = []): array { return $this->get('certification/tv/list', $parameters, $headers); } diff --git a/lib/Tmdb/Api/Changes.php b/lib/Tmdb/Api/Changes.php index d9a09e81..de688a47 100644 --- a/lib/Tmdb/Api/Changes.php +++ b/lib/Tmdb/Api/Changes.php @@ -1,23 +1,23 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ namespace Tmdb\Api; /** - * Class Changes - * @package Tmdb\Api - * http://docs.themoviedb.apiary.io/#changes + * Class Changes. */ class Changes extends AbstractApi { @@ -31,12 +31,8 @@ class Changes extends AbstractApi * * Please note that the change log system to support this was changed * on October 5, 2012 and will only show movies that have been edited since. - * - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getMovieChanges(array $parameters = [], array $headers = []) + public function getMovieChanges(array $parameters = [], array $headers = []): array { return $this->get('movie/changes', $parameters, $headers); } @@ -51,12 +47,8 @@ public function getMovieChanges(array $parameters = [], array $headers = []) * * Please note that the change log system to support this was changed * on October 5, 2012 and will only show movies that have been edited since. - * - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getPersonChanges(array $parameters = [], array $headers = []) + public function getPersonChanges(array $parameters = [], array $headers = []): array { return $this->get('person/changes', $parameters, $headers); } @@ -71,12 +63,8 @@ public function getPersonChanges(array $parameters = [], array $headers = []) * * Please note that the change log system to support this was changed * on May 13, 2014 and will only show tv shows that have been edited since. - * - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getTvChanges(array $parameters = [], array $headers = []) + public function getTvChanges(array $parameters = [], array $headers = []): array { return $this->get('tv/changes', $parameters, $headers); } diff --git a/lib/Tmdb/Api/Collections.php b/lib/Tmdb/Api/Collections.php index 15e1df3b..6e572f1d 100644 --- a/lib/Tmdb/Api/Collections.php +++ b/lib/Tmdb/Api/Collections.php @@ -1,22 +1,24 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ namespace Tmdb\Api; /** - * Class Collections - * @package Tmdb\Api + * Class Collections. + * * @see http://docs.themoviedb.apiary.io/#collections */ class Collections extends AbstractApi @@ -29,39 +31,24 @@ class Collections extends AbstractApi * * Movie parts are not sorted in any particular order. * If you would like to sort them yourself you can use the provided release_date. - * - * @param $collection_id - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getCollection($collection_id, array $parameters = [], array $headers = []) + public function getCollection(string $collection_id, array $parameters = [], array $headers = []): array { return $this->get('collection/' . $collection_id, $parameters, $headers); } /** * Get all of the images for a particular collection by collection id. - * - * @param $collection_id - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getImages($collection_id, array $parameters = [], array $headers = []) + public function getImages(string $collection_id, array $parameters = [], array $headers = []): array { return $this->get('collection/' . $collection_id . '/images', $parameters, $headers); } /** * Get the list of translations that exist for a TV episode. - * - * @param $collection_id - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getTranslations($collection_id, array $parameters = [], array $headers = []) + public function getTranslations(string $collection_id, array $parameters = [], array $headers = []): array { return $this->get('collection/' . $collection_id . '/translations', $parameters, $headers); } diff --git a/lib/Tmdb/Api/Companies.php b/lib/Tmdb/Api/Companies.php index 573385fb..91a6302a 100644 --- a/lib/Tmdb/Api/Companies.php +++ b/lib/Tmdb/Api/Companies.php @@ -1,35 +1,32 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ namespace Tmdb\Api; /** - * Class Companies - * @package Tmdb\Api + * Class Companies. + * * @see http://docs.themoviedb.apiary.io/#companies */ class Companies extends AbstractApi { /** * This method is used to retrieve all of the basic information about a company. - * - * @param $company_id - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getCompany($company_id, array $parameters = [], array $headers = []) + public function getCompany(string $company_id, array $parameters = [], array $headers = []): array { return $this->get('company/' . $company_id, $parameters, $headers); } @@ -37,12 +34,9 @@ public function getCompany($company_id, array $parameters = [], array $headers = /** * Get the list of movies associated with a particular company. * - * @param integer $company_id - * @param array $parameters - * @param array $headers - * @return mixed + * @param int $company_id */ - public function getMovies($company_id, array $parameters = [], array $headers = []) + public function getMovies($company_id, array $parameters = [], array $headers = []): array { return $this->get('company/' . $company_id . '/movies', $parameters, $headers); } diff --git a/lib/Tmdb/Api/Configuration.php b/lib/Tmdb/Api/Configuration.php index 4a48785f..f428a317 100644 --- a/lib/Tmdb/Api/Configuration.php +++ b/lib/Tmdb/Api/Configuration.php @@ -1,22 +1,23 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ namespace Tmdb\Api; /** - * Class Configuration - * @package Tmdb\Api + * Class Configuration. * * @see http://docs.themoviedb.apiary.io/#configuration */ @@ -38,19 +39,12 @@ class Configuration extends AbstractApi * Simply combine them all and you will have a fully qualified URL. Here’s an example URL: * * http://d3gtl9l2a4fn1j.cloudfront.net/t/p/w500/8uO0gUM8aNqYLs1OsTBQiXu0fEv.jpg - * - * @param array $headers - * @return mixed */ - public function getConfiguration(array $headers = []) + public function getConfiguration(array $headers = []): array { 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/Credits.php b/lib/Tmdb/Api/Credits.php index e08c917c..0ed057ba 100644 --- a/lib/Tmdb/Api/Credits.php +++ b/lib/Tmdb/Api/Credits.php @@ -1,22 +1,24 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ namespace Tmdb\Api; /** - * Class Credits - * @package Tmdb\Api + * Class Credits. + * * @see http://docs.themoviedb.apiary.io/#credits */ class Credits extends AbstractApi @@ -33,13 +35,8 @@ class Credits extends AbstractApi * * Season credits are credits that were marked with the "add to every season" option in the editing interface * and are assumed to be "season regulars". - * - * @param $credit_id - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getCredit($credit_id, array $parameters = [], array $headers = []) + public function getCredit(string $credit_id, array $parameters = [], array $headers = []): array { return $this->get('credit/' . $credit_id, $parameters, $headers); } diff --git a/lib/Tmdb/Api/Discover.php b/lib/Tmdb/Api/Discover.php index c11cb8c3..3a639af6 100644 --- a/lib/Tmdb/Api/Discover.php +++ b/lib/Tmdb/Api/Discover.php @@ -1,34 +1,32 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ namespace Tmdb\Api; /** - * Class Discover - * @package Tmdb\Api + * Class Discover. + * * @see http://docs.themoviedb.apiary.io/#discover */ class Discover extends AbstractApi { /** * Discover movies by different types of data like average rating, number of votes, genres and certifications. - * - * @param array $parameters - * @param array $headers - * @return mixed */ - public function discoverMovies(array $parameters = [], array $headers = []) + public function discoverMovies(array $parameters = [], array $headers = []): array { return $this->get('discover/movie', $parameters, $headers); } @@ -36,12 +34,8 @@ public function discoverMovies(array $parameters = [], array $headers = []) /** * Discover TV shows by different types of data like average rating, number of votes, genres, * the network they aired on and air dates. - * - * @param array $parameters - * @param array $headers - * @return mixed */ - public function discoverTv(array $parameters = [], array $headers = []) + public function discoverTv(array $parameters = [], array $headers = []): array { return $this->get('discover/tv', $parameters, $headers); } diff --git a/lib/Tmdb/Api/Find.php b/lib/Tmdb/Api/Find.php index 8d29b9b2..a143d7a9 100644 --- a/lib/Tmdb/Api/Find.php +++ b/lib/Tmdb/Api/Find.php @@ -1,22 +1,24 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ namespace Tmdb\Api; /** - * Class Find - * @package Tmdb\Api + * Class Find. + * * @see http://docs.themoviedb.apiary.io/#find */ class Find extends AbstractApi @@ -33,18 +35,13 @@ class Find extends AbstractApi * Movies: imdb_id * People: imdb_id, freebase_mid, freebase_id, tvrage_id * TV Series: imdb_id, freebase_mid, freebase_id, tvdb_id, tvrage_id - * - * @param string $id - * @param array $parameters - * @param array $headers - * @return array */ public function findBy(string $id, array $parameters = [], array $headers = []): array { return $this->get( 'find/' . $id, $parameters, - $headers + $headers, ); } } diff --git a/lib/Tmdb/Api/Genres.php b/lib/Tmdb/Api/Genres.php index 2bd06155..e87f7350 100644 --- a/lib/Tmdb/Api/Genres.php +++ b/lib/Tmdb/Api/Genres.php @@ -1,39 +1,38 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ namespace Tmdb\Api; /** - * Class Genres - * @package Tmdb\Api + * Class Genres. + * * @see http://docs.themoviedb.apiary.io/#genres */ class Genres extends AbstractApi { /** - * Get the list of genres, and return one by id + * Get the list of genres, and return one by id. * - * @param integer $id - * @param array $parameters - * @param array $headers - * @return mixed + * @param int $id */ public function getGenre($id, array $parameters = [], array $headers = []) { $response = $this->getGenres($parameters, $headers); - if (null !== $response && array_key_exists('genres', $response)) { + if (null !== $response && \array_key_exists('genres', $response)) { return $this->extractGenreByIdFromResponse($id, $response['genres']); } @@ -42,54 +41,38 @@ public function getGenre($id, array $parameters = [], array $headers = []) /** * Get the list of genres. - * - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getGenres(array $parameters = [], array $headers = []) + public function getGenres(array $parameters = [], array $headers = []): array { - $data = array_merge_recursive( + return array_merge_recursive( $this->getMovieGenres($parameters, $headers), - $this->getTvGenres($parameters, $headers) + $this->getTvGenres($parameters, $headers), ); - - return $data; } /** * Get the list of movie genres. - * - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getMovieGenres(array $parameters = [], array $headers = []) + public function getMovieGenres(array $parameters = [], array $headers = []): array { return $this->get('genre/movie/list', $parameters, $headers); } /** * Get the list of TV genres. - * - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getTvGenres(array $parameters = [], array $headers = []) + public function getTvGenres(array $parameters = [], array $headers = []): array { return $this->get('genre/tv/list', $parameters, $headers); } /** - * @param integer $id - * @param array $data - * @return mixed + * @param int $id */ private function extractGenreByIdFromResponse($id, array $data = []) { foreach ($data as $genre) { - if ($id == $genre['id']) { + if ($id === $genre['id']) { return $genre; } } @@ -99,13 +82,8 @@ private function extractGenreByIdFromResponse($id, array $data = []) /** * Get the list of movies for a particular genre by id. By default, only movies with 10 or more votes are included. - * - * @param $genre_id - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getMovies($genre_id, array $parameters = [], array $headers = []) + public function getMovies(string $genre_id, array $parameters = [], array $headers = []): array { return $this->get('genre/' . $genre_id . '/movies', $parameters, $headers); } diff --git a/lib/Tmdb/Api/GuestSession.php b/lib/Tmdb/Api/GuestSession.php index 6aecfec5..9a3e5b17 100644 --- a/lib/Tmdb/Api/GuestSession.php +++ b/lib/Tmdb/Api/GuestSession.php @@ -1,14 +1,16 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ @@ -18,8 +20,8 @@ use Tmdb\Token\Session\SessionToken; /** - * Class GuestSession - * @package Tmdb\Api + * Class GuestSession. + * * @see http://docs.themoviedb.apiary.io/#guestsessions */ class GuestSession extends AbstractApi @@ -27,12 +29,9 @@ class GuestSession extends AbstractApi /** * Get a list of rated movies for a specific guest session id. * - * @param array $parameters - * @param array $headers - * @return mixed - * @throws MissingSessionTokenException when the guest session token was not set on the client. + * @throws MissingSessionTokenException when the guest session token was not set on the client */ - public function getRatedMovies(array $parameters = [], array $headers = []) + public function getRatedMovies(array $parameters = [], array $headers = []): array { $sessionToken = $this->client->getGuestSessionToken(); diff --git a/lib/Tmdb/Api/Jobs.php b/lib/Tmdb/Api/Jobs.php index 7dad85ef..3c4d79ad 100644 --- a/lib/Tmdb/Api/Jobs.php +++ b/lib/Tmdb/Api/Jobs.php @@ -1,34 +1,32 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ namespace Tmdb\Api; /** - * Class Jobs - * @package Tmdb\Api + * Class Jobs. + * * @see http://docs.themoviedb.apiary.io/#jobs */ class Jobs extends AbstractApi { /** * Get a list of valid jobs. - * - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getJobs(array $parameters = [], array $headers = []) + public function getJobs(array $parameters = [], array $headers = []): array { return $this->get('job/list', $parameters, $headers); } diff --git a/lib/Tmdb/Api/Keywords.php b/lib/Tmdb/Api/Keywords.php index 4c04f2a7..dd9f091c 100644 --- a/lib/Tmdb/Api/Keywords.php +++ b/lib/Tmdb/Api/Keywords.php @@ -1,22 +1,24 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ namespace Tmdb\Api; /** - * Class Keywords - * @package Tmdb\Api + * Class Keywords. + * * @see http://docs.themoviedb.apiary.io/#keywords */ class Keywords extends AbstractApi @@ -25,11 +27,8 @@ class Keywords extends AbstractApi * Get the basic information for a specific keyword id. * * @param int $keyword_id - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getKeyword($keyword_id, array $parameters = [], array $headers = []) + public function getKeyword($keyword_id, array $parameters = [], array $headers = []): array { return $this->get('keyword/' . $keyword_id, $parameters, $headers); } @@ -38,11 +37,8 @@ public function getKeyword($keyword_id, array $parameters = [], array $headers = * Get the list of movies for a particular keyword by id. * * @param int $keyword_id - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getMovies($keyword_id, array $parameters = [], array $headers = []) + public function getMovies($keyword_id, array $parameters = [], array $headers = []): array { return $this->get('keyword/' . $keyword_id . '/movies', $parameters, $headers); } diff --git a/lib/Tmdb/Api/Lists.php b/lib/Tmdb/Api/Lists.php index b6dcf4c4..916f1d00 100644 --- a/lib/Tmdb/Api/Lists.php +++ b/lib/Tmdb/Api/Lists.php @@ -1,35 +1,32 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ namespace Tmdb\Api; /** - * Class Lists - * @package Tmdb\Api + * Class Lists. + * * @see http://docs.themoviedb.apiary.io/#lists */ class Lists extends AbstractApi { /** * Get a list by id. - * - * @param string $list_id - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getList($list_id, array $parameters = [], array $headers = []) + public function getList(string $list_id, array $parameters = [], array $headers = []): array { return $this->get('list/' . $list_id, $parameters, $headers); } @@ -39,11 +36,8 @@ public function getList($list_id, array $parameters = [], array $headers = []) * * @param string $name * @param string $description - * @param array $parameters - * @param array $headers - * @return mixed */ - public function createList($name, $description, array $parameters = [], array $headers = []) + public function createList($name, $description, array $parameters = [], array $headers = []): array { return $this->postJson('list', ['name' => $name, 'description' => $description], $parameters, $headers); } @@ -51,29 +45,23 @@ public function createList($name, $description, array $parameters = [], array $h /** * Check to see if a movie ID is already added to a list. * - * @param string $id - * @param int $movieId - * @param array $parameters - * @param array $headers - * @return mixed + * @param int $movieId */ - public function getItemStatus($id, $movieId, array $parameters = [], array $headers = []) + public function getItemStatus(string $id, $movieId, array $parameters = [], array $headers = []): array { return $this->get( 'list/' . $id . '/item_status', array_merge($parameters, ['movie_id' => $movieId]), - $headers + $headers, ); } /** * This method lets users add new movies to a list that they created. A valid session id is required. * - * @param string $id * @param string|int $mediaId - * @return mixed */ - public function addMediaToList($id, $mediaId) + public function addMediaToList(string $id, $mediaId): array { return $this->postJson('list/' . $id . '/add_item', ['media_id' => $mediaId]); } @@ -81,22 +69,17 @@ 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|int $mediaId - * @return mixed */ - public function removeMediaFromList($id, $mediaId) + public function removeMediaFromList(string $id, $mediaId): array { return $this->postJson('list/' . $id . '/remove_item', ['media_id' => $mediaId]); } /** * This method lets users delete a list that they created. A valid session id is required. - * - * @param string $id - * @return mixed */ - public function deleteList($id) + public function deleteList(string $id): array { return $this->delete('list/' . $id); } @@ -107,16 +90,14 @@ public function deleteList($id) * This is a irreversible action and should be treated with caution. * A valid session id is required. * - * @param string $id - * @param boolean $confirm - * @return mixed + * @param bool $confirm */ - public function clearList($id, $confirm) + public function clearList(string $id, $confirm): array { return $this->post( 'list/' . $id . '/clear', null, - ['confirm' => (bool)$confirm === true ? 'true' : 'false'] + ['confirm' => (bool) $confirm ? 'true' : 'false'], ); } } diff --git a/lib/Tmdb/Api/Movies.php b/lib/Tmdb/Api/Movies.php index b7b139d5..f4dd9e7e 100644 --- a/lib/Tmdb/Api/Movies.php +++ b/lib/Tmdb/Api/Movies.php @@ -1,100 +1,72 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ namespace Tmdb\Api; /** - * Class Movies - * @package Tmdb\Api + * Class Movies. + * * @see http://docs.themoviedb.apiary.io/#movies */ class Movies extends AbstractApi { /** * Get the basic movie information for a specific movie id. - * - * @param $movie_id - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getMovie($movie_id, array $parameters = [], array $headers = []) + public function getMovie(string $movie_id, array $parameters = [], array $headers = []): array { return $this->get('movie/' . $movie_id, $parameters, $headers); } /** * Get the alternative titles for a specific movie id. - * - * @param $movie_id - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getAlternativeTitles($movie_id, array $parameters = [], array $headers = []) + public function getAlternativeTitles(string $movie_id, array $parameters = [], array $headers = []): array { return $this->get('movie/' . $movie_id . '/alternative_titles', $parameters, $headers); } /** * Get the cast and crew information for a specific movie id. - * - * @param $movie_id - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getCredits($movie_id, array $parameters = [], array $headers = []) + public function getCredits(string $movie_id, array $parameters = [], array $headers = []): array { return $this->get('movie/' . $movie_id . '/credits', $parameters, $headers); } /** * Get the images (posters and backdrops) for a specific movie id. - * - * @param $movie_id - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getImages($movie_id, array $parameters = [], array $headers = []) + public function getImages(string $movie_id, array $parameters = [], array $headers = []): array { return $this->get('movie/' . $movie_id . '/images', $parameters, $headers); } /** * Get the plot keywords for a specific movie id. - * - * @param $movie_id - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getKeywords($movie_id, array $parameters = [], array $headers = []) + public function getKeywords(string $movie_id, array $parameters = [], array $headers = []): array { return $this->get('movie/' . $movie_id . '/keywords', $parameters, $headers); } /** * Get the release date by country for a specific movie id. - * - * @param $movie_id - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getReleases($movie_id, array $parameters = [], array $headers = []) + public function getReleases(string $movie_id, array $parameters = [], array $headers = []): array { return $this->get('movie/' . $movie_id . '/releases', $parameters, $headers); } @@ -102,103 +74,65 @@ public function getReleases($movie_id, array $parameters = [], array $headers = /** * Get the trailers for a specific movie id. * - * @param $movie_id - * @param array $parameters - * @param array $headers - * @return mixed * @deprecated TMDB changed the way of requesting trailers, see getVideos instead! */ - public function getTrailers($movie_id, array $parameters = [], array $headers = []) + public function getTrailers(string $movie_id, array $parameters = [], array $headers = []): array { return $this->get('movie/' . $movie_id . '/trailers', $parameters, $headers); } /** * Get the translations for a specific movie id. - * - * @param $movie_id - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getTranslations($movie_id, array $parameters = [], array $headers = []) + public function getTranslations(string $movie_id, array $parameters = [], array $headers = []): array { return $this->get('movie/' . $movie_id . '/translations', $parameters, $headers); } /** * Get the similar movies for a specific movie id. - * - * @param $movie_id - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getSimilar($movie_id, array $parameters = [], array $headers = []) + public function getSimilar(string $movie_id, array $parameters = [], array $headers = []): array { return $this->get('movie/' . $movie_id . '/similar', $parameters, $headers); } /** * Get the recommended movies for a specific movie id. - * - * @param $movie_id - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getRecommendations($movie_id, array $parameters = [], array $headers = []) + public function getRecommendations(string $movie_id, array $parameters = [], array $headers = []): array { return $this->get('movie/' . $movie_id . '/recommendations', $parameters, $headers); } /** * Get the reviews for a particular movie id. - * - * @param $movie_id - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getReviews($movie_id, array $parameters = [], array $headers = []) + public function getReviews(string $movie_id, array $parameters = [], array $headers = []): array { return $this->get('movie/' . $movie_id . '/reviews', $parameters, $headers); } /** * Get the lists that the movie belongs to. - * - * @param $movie_id - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getLists($movie_id, array $parameters = [], array $headers = []) + public function getLists(string $movie_id, array $parameters = [], array $headers = []): array { return $this->get('movie/' . $movie_id . '/lists', $parameters, $headers); } /** * Get the changes for a specific movie id. - * - * @param $movie_id - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getChanges($movie_id, array $parameters = [], array $headers = []) + public function getChanges(string $movie_id, array $parameters = [], array $headers = []): array { return $this->get('movie/' . $movie_id . '/changes', $parameters, $headers); } /** * Get the latest movie id. - * - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getLatest(array $parameters = [], array $headers = []) + public function getLatest(array $parameters = [], array $headers = []): array { return $this->get('movie/latest', $parameters, $headers); } @@ -206,12 +140,8 @@ public function getLatest(array $parameters = [], array $headers = []) /** * Get the list of upcoming movies. This list refreshes every day. * The maximum number of items this list will include is 100. - * - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getUpcoming(array $parameters = [], array $headers = []) + public function getUpcoming(array $parameters = [], array $headers = []): array { return $this->get('movie/upcoming', $parameters, $headers); } @@ -219,12 +149,8 @@ public function getUpcoming(array $parameters = [], array $headers = []) /** * Get the list of movies playing in theatres. This list refreshes every day. * The maximum number of items this list will include is 100. - * - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getNowPlaying(array $parameters = [], array $headers = []) + public function getNowPlaying(array $parameters = [], array $headers = []): array { return $this->get('movie/now_playing', $parameters, $headers); } @@ -232,12 +158,8 @@ public function getNowPlaying(array $parameters = [], array $headers = []) /** * Get the list of popular movies on The Movie Database. * This list refreshes every day. - * - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getPopular(array $parameters = [], array $headers = []) + public function getPopular(array $parameters = [], array $headers = []): array { return $this->get('movie/popular', $parameters, $headers); } @@ -245,12 +167,8 @@ public function getPopular(array $parameters = [], array $headers = []) /** * Get the list of top rated movies. By default, this list will only include * movies that have 10 or more votes. This list refreshes every day. - * - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getTopRated(array $parameters = [], array $headers = []) + public function getTopRated(array $parameters = [], array $headers = []): array { return $this->get('movie/top_rated', $parameters, $headers); } @@ -261,10 +179,9 @@ public function getTopRated(array $parameters = [], array $headers = []) * * A valid session id is required. * - * @param integer $id - * @return mixed + * @param int $id */ - public function getAccountStates($id) + public function getAccountStates($id): array { return $this->get('movie/' . $id . '/account_states'); } @@ -274,50 +191,34 @@ public function getAccountStates($id) * * A valid session id or guest session id is required. * - * @param integer $id - * @param double $rating - * @return mixed + * @param int $id + * @param float $rating */ - public function rateMovie($id, $rating) + public function rateMovie($id, $rating): array { - return $this->postJson('movie/' . $id . '/rating', ['value' => (float)$rating]); + return $this->postJson('movie/' . $id . '/rating', ['value' => (float) $rating]); } /** * Get the videos (trailers, teasers, clips, etc...) for a specific movie id. - * - * @param $movie_id - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getVideos($movie_id, array $parameters = [], array $headers = []) + public function getVideos(string $movie_id, array $parameters = [], array $headers = []): array { return $this->get('movie/' . $movie_id . '/videos', $parameters, $headers); } /** * Get the watch providers (by region) for a specific movie id. - * - * @param $movie_id - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getWatchProviders($movie_id, array $parameters = [], array $headers = []) + public function getWatchProviders(string $movie_id, array $parameters = [], array $headers = []): array { return $this->get('movie/' . $movie_id . '/watch/providers', $parameters, $headers); } /** * Get the external ids that we have stored for a movie. - * - * @param $movie_id - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getExternalIds($movie_id, array $parameters = [], array $headers = []) + public function getExternalIds(string $movie_id, array $parameters = [], array $headers = []): array { return $this->get('movie/' . $movie_id . '/external_ids', $parameters, $headers); } diff --git a/lib/Tmdb/Api/Networks.php b/lib/Tmdb/Api/Networks.php index c0038caa..d0c57af6 100644 --- a/lib/Tmdb/Api/Networks.php +++ b/lib/Tmdb/Api/Networks.php @@ -1,22 +1,24 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ namespace Tmdb\Api; /** - * Class Networks - * @package Tmdb\Api + * Class Networks. + * * @see http://docs.themoviedb.apiary.io/#networks */ class Networks extends AbstractApi @@ -28,11 +30,8 @@ class Networks extends AbstractApi * At this time we don't have much but this will be fleshed out over time. * * @param int $network_id - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getNetwork($network_id, array $parameters = [], array $headers = []) + public function getNetwork($network_id, array $parameters = [], array $headers = []): array { return $this->get('network/' . $network_id, $parameters, $headers); } diff --git a/lib/Tmdb/Api/People.php b/lib/Tmdb/Api/People.php index 93c61039..538e153e 100644 --- a/lib/Tmdb/Api/People.php +++ b/lib/Tmdb/Api/People.php @@ -1,46 +1,38 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ namespace Tmdb\Api; /** - * Class People - * @package Tmdb\Api + * Class People. + * * @see http://docs.themoviedb.apiary.io/#people */ class People extends AbstractApi { /** * Get the general person information for a specific id. - * - * @param $person_id - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getPerson($person_id, array $parameters = [], array $headers = []) + public function getPerson($person_id, array $parameters = [], array $headers = []): array { return $this->get('person/' . $person_id, $parameters, $headers); } /** * Get the credits for a specific person id. - * - * @param $person_id - * @param array $parameters - * @param array $headers - * @return mixed */ public function getCredits($person_id, array $parameters = [], array $headers = []) { @@ -52,26 +44,16 @@ public function getCredits($person_id, array $parameters = [], array $headers = * * To get the expanded details for each TV record, call the /credit method with the provided credit_id. * This will provide details about which episode and/or season the credit is for. - * - * @param $person_id - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getCombinedCredits($person_id, array $parameters = [], array $headers = []) + public function getCombinedCredits($person_id, array $parameters = [], array $headers = []): array { return $this->get('person/' . $person_id . '/combined_credits', $parameters, $headers); } /** * Get the movie credits for a specific person id. - * - * @param $person_id - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getMovieCredits($person_id, array $parameters = [], array $headers = []) + public function getMovieCredits($person_id, array $parameters = [], array $headers = []): array { return $this->get('person/' . $person_id . '/movie_credits', $parameters, $headers); } @@ -81,26 +63,16 @@ public function getMovieCredits($person_id, array $parameters = [], array $heade * * To get the expanded details for each record, call the /credit method with the provided credit_id. * This will provide details about which episode and/or season the credit is for. - * - * @param $person_id - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getTvCredits($person_id, array $parameters = [], array $headers = []) + public function getTvCredits($person_id, array $parameters = [], array $headers = []): array { return $this->get('person/' . $person_id . '/tv_credits', $parameters, $headers); } /** * Get the images for a specific person id. - * - * @param $person_id - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getImages($person_id, array $parameters = [], array $headers = []) + public function getImages($person_id, array $parameters = [], array $headers = []): array { return $this->get('person/' . $person_id . '/images', $parameters, $headers); } @@ -113,26 +85,16 @@ public function getImages($person_id, array $parameters = [], array $headers = [ * By default, only the last 24 hours of changes are returned. * The maximum number of days that can be returned in a single request is 14. * The language is present on fields that are translatable. - * - * @param $person_id - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getChanges($person_id, array $parameters = [], array $headers = []) + public function getChanges($person_id, array $parameters = [], array $headers = []): array { return $this->get('person/' . $person_id . '/changes', $parameters, $headers); } /** * Get the external ids for a specific person id. - * - * @param $person_id - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getExternalIds($person_id, array $parameters = [], array $headers = []) + public function getExternalIds($person_id, array $parameters = [], array $headers = []): array { return $this->get('person/' . $person_id . '/external_ids', $parameters, $headers); } @@ -141,35 +103,24 @@ public function getExternalIds($person_id, array $parameters = [], array $header * Get the images that have been tagged with a specific person id. * * We return all of the image results with a media object mapped for each image. - * - * @param $person_id - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getTaggedImages($person_id, array $parameters = [], array $headers = []) + public function getTaggedImages($person_id, array $parameters = [], array $headers = []): array { return $this->get('person/' . $person_id . '/tagged_images', $parameters, $headers); } /** * Get the list of popular people on The Movie Database. This list refreshes every day. - * - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getPopular(array $parameters = [], array $headers = []) + public function getPopular(array $parameters = [], array $headers = []): array { return $this->get('person/popular', $parameters, $headers); } /** * Get the latest person id. - * - * @return mixed */ - public function getLatest() + public function getLatest(): array { return $this->get('person/latest'); } diff --git a/lib/Tmdb/Api/Reviews.php b/lib/Tmdb/Api/Reviews.php index a1f925ce..c1299991 100644 --- a/lib/Tmdb/Api/Reviews.php +++ b/lib/Tmdb/Api/Reviews.php @@ -1,35 +1,32 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ namespace Tmdb\Api; /** - * Class Reviews - * @package Tmdb\Api + * Class Reviews. + * * @see http://docs.themoviedb.apiary.io/#reviews */ class Reviews extends AbstractApi { /** * Get the full details of a review by ID. - * - * @param $review_id - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getReview($review_id, array $parameters = [], array $headers = []) + public function getReview(string $review_id, array $parameters = [], array $headers = []): array { return $this->get('review/' . $review_id, $parameters, $headers); } diff --git a/lib/Tmdb/Api/Search.php b/lib/Tmdb/Api/Search.php index d48dcad7..a21a52b7 100644 --- a/lib/Tmdb/Api/Search.php +++ b/lib/Tmdb/Api/Search.php @@ -1,22 +1,24 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ namespace Tmdb\Api; /** - * Class Search - * @package Tmdb\Api + * Class Search. + * * @see http://docs.themoviedb.apiary.io/#search */ class Search extends AbstractApi @@ -25,14 +27,11 @@ class Search extends AbstractApi * Search for movies by title. * * @param string $query - * @param array $parameters - * @param array $headers - * @return mixed */ - public function searchMovies($query, array $parameters = [], array $headers = []) + public function searchMovies($query, array $parameters = [], array $headers = []): array { return $this->get('search/movie', array_merge($parameters, [ - 'query' => $query + 'query' => $query, ], $headers)); } @@ -40,14 +39,11 @@ public function searchMovies($query, array $parameters = [], array $headers = [] * Search for collections by name. * * @param string $query - * @param array $parameters - * @param array $headers - * @return mixed */ - public function searchCollection($query, array $parameters = [], array $headers = []) + public function searchCollection($query, array $parameters = [], array $headers = []): array { return $this->get('search/collection', array_merge($parameters, [ - 'query' => $query + 'query' => $query, ], $headers)); } @@ -55,14 +51,11 @@ public function searchCollection($query, array $parameters = [], array $headers * Search for TV shows by title. * * @param string $query - * @param array $parameters - * @param array $headers - * @return mixed */ - public function searchTv($query, array $parameters = [], array $headers = []) + public function searchTv($query, array $parameters = [], array $headers = []): array { return $this->get('search/tv', array_merge($parameters, [ - 'query' => $query + 'query' => $query, ], $headers)); } @@ -70,29 +63,21 @@ public function searchTv($query, array $parameters = [], array $headers = []) * Search for people by name. * * @param string $query - * @param array $parameters - * @param array $headers - * @return mixed */ - public function searchPersons($query, array $parameters = [], array $headers = []) + public function searchPersons($query, array $parameters = [], array $headers = []): array { return $this->get('search/person', array_merge($parameters, [ - 'query' => $query + 'query' => $query, ], $headers)); } /** * Search for companies by name. - * - * @param $query - * @param array $parameters - * @param array $headers - * @return mixed */ - public function searchCompany(string $query, array $parameters = [], array $headers = []) + public function searchCompany(string $query, array $parameters = [], array $headers = []): array { return $this->get('search/company', array_merge($parameters, [ - 'query' => $query + 'query' => $query, ], $headers)); } @@ -100,14 +85,11 @@ public function searchCompany(string $query, array $parameters = [], array $head * Search for companies by name. * * @param string $query - * @param array $parameters - * @param array $headers - * @return mixed */ - public function searchKeyword($query, array $parameters = [], array $headers = []) + public function searchKeyword($query, array $parameters = [], array $headers = []): array { return $this->get('search/keyword', array_merge($parameters, [ - 'query' => $query + 'query' => $query, ], $headers)); } @@ -118,14 +100,11 @@ public function searchKeyword($query, array $parameters = [], array $headers = [ * Each mapped result is the same response you would get from each independent search. * * @param string $query - * @param array $parameters - * @param array $headers - * @return mixed */ - public function searchMulti($query, array $parameters = [], array $headers = []) + public function searchMulti($query, array $parameters = [], array $headers = []): array { return $this->get('search/multi', array_merge($parameters, [ - 'query' => $query + 'query' => $query, ], $headers)); } } diff --git a/lib/Tmdb/Api/Timezones.php b/lib/Tmdb/Api/Timezones.php index b015eb86..0c598867 100644 --- a/lib/Tmdb/Api/Timezones.php +++ b/lib/Tmdb/Api/Timezones.php @@ -1,32 +1,32 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ namespace Tmdb\Api; /** - * Class Timezones - * @package Tmdb\Api + * Class Timezones. + * * @see http://docs.themoviedb.apiary.io/#timezones */ class Timezones extends AbstractApi { /** * Get the list of supported timezones for the API methods that support them. - * - * @return mixed */ - public function getTimezones() + public function getTimezones(): array { return $this->get('timezones/list'); } diff --git a/lib/Tmdb/Api/Tv.php b/lib/Tmdb/Api/Tv.php index ab6f0af3..5790d223 100644 --- a/lib/Tmdb/Api/Tv.php +++ b/lib/Tmdb/Api/Tv.php @@ -1,22 +1,24 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ namespace Tmdb\Api; /** - * Class Tv - * @package Tmdb\Api + * Class Tv. + * * @see http://docs.themoviedb.apiary.io/#tv */ class Tv extends AbstractApi @@ -24,12 +26,9 @@ class Tv extends AbstractApi /** * Get the primary information about a TV series by id. * - * @param integer $tvshow_id - * @param array $parameters - * @param array $headers - * @return mixed + * @param int $tvshow_id */ - public function getTvshow($tvshow_id, array $parameters = [], array $headers = []) + public function getTvshow($tvshow_id, array $parameters = [], array $headers = []): array { return $this->get('tv/' . $tvshow_id, $parameters, $headers); } @@ -37,63 +36,40 @@ public function getTvshow($tvshow_id, array $parameters = [], array $headers = [ /** * Get the cast & crew information about a TV series. * Just like the website, we pull this information from the last season of the series. - * - * @param $tvshow_id - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getCredits($tvshow_id, array $parameters = [], array $headers = []) + public function getCredits(string $tvshow_id, array $parameters = [], array $headers = []): array { return $this->get('tv/' . $tvshow_id . '/credits', $parameters, $headers); } /** * Get the content ratings for a specific TV show id. - * @param $tvshow_id - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getContentRatings($tvshow_id, array $parameters = [], array $headers = []) + public function getContentRatings(string $tvshow_id, array $parameters = [], array $headers = []): array { return $this->get('tv/' . $tvshow_id . '/content_ratings', $parameters, $headers); } /** * Get the external ids that we have stored for a TV series. - * - * @param $tvshow_id - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getExternalIds($tvshow_id, array $parameters = [], array $headers = []) + public function getExternalIds(string $tvshow_id, array $parameters = [], array $headers = []): array { return $this->get('tv/' . $tvshow_id . '/external_ids', $parameters, $headers); } /** * Get the images (posters and backdrops) for a TV series. - * - * @param $tvshow_id - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getImages($tvshow_id, array $parameters = [], array $headers = []) + public function getImages(string $tvshow_id, array $parameters = [], array $headers = []): array { return $this->get('tv/' . $tvshow_id . '/images', $parameters, $headers); } /** * Get the list of popular TV shows. This list refreshes every day. - * - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getPopular(array $parameters = [], array $headers = []) + public function getPopular(array $parameters = [], array $headers = []): array { return $this->get('tv/popular', $parameters, $headers); } @@ -103,12 +79,8 @@ public function getPopular(array $parameters = [], array $headers = []) * * By default, this list will only include TV shows that have 2 or more votes. * This list refreshes every day. - * - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getTopRated(array $parameters = [], array $headers = []) + public function getTopRated(array $parameters = [], array $headers = []): array { return $this->get('tv/top_rated', $parameters, $headers); } @@ -119,11 +91,8 @@ public function getTopRated(array $parameters = [], array $headers = []) * These translations cascade down to the episode level. * * @param int $tvshow_id - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getTranslations($tvshow_id, array $parameters = [], array $headers = []) + public function getTranslations($tvshow_id, array $parameters = [], array $headers = []): array { return $this->get('tv/' . $tvshow_id . '/translations', $parameters, $headers); } @@ -132,12 +101,8 @@ public function getTranslations($tvshow_id, array $parameters = [], array $heade * Get the list of TV shows that are currently on the air. * * This query looks for any TV show that has an episode with an air date in the next 7 days. - * - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getOnTheAir(array $parameters = [], array $headers = []) + public function getOnTheAir(array $parameters = [], array $headers = []): array { return $this->get('tv/on_the_air', $parameters, $headers); } @@ -146,38 +111,26 @@ public function getOnTheAir(array $parameters = [], array $headers = []) * Get the list of TV shows that air today. * * Without a specified timezone, this query defaults to EST (Eastern Time UTC-05:00). - * - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getAiringToday(array $parameters = [], array $headers = []) + public function getAiringToday(array $parameters = [], array $headers = []): array { return $this->get('tv/airing_today', $parameters, $headers); } /** - * Get the videos that have been added to a TV series (trailers, opening credits, etc...) + * Get the videos that have been added to a TV series (trailers, opening credits, etc...). * * @param int $tvshow_id - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getVideos($tvshow_id, array $parameters = [], array $headers = []) + public function getVideos($tvshow_id, array $parameters = [], array $headers = []): array { return $this->get('tv/' . $tvshow_id . '/videos', $parameters, $headers); } /** * Get the watch providers (by region) for a specific movie id. - * - * @param $movie_id - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getWatchProviders($tvshow_id, array $parameters = [], array $headers = []) + public function getWatchProviders(string $tvshow_id, array $parameters = [], array $headers = []): array { return $this->get('tv/' . $tvshow_id . '/watch/providers', $parameters, $headers); } @@ -195,64 +148,40 @@ public function getWatchProviders($tvshow_id, array $parameters = [], array $hea * These keys will contain a series_id and episode_id. * * You can use the /tv/season/{id}/changes and /tv/episode/{id}/changes methods to look up these specific changes. - * - * @param $tvshow_id - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getChanges($tvshow_id, array $parameters = [], array $headers = []) + public function getChanges(string $tvshow_id, array $parameters = [], array $headers = []): array { return $this->get('tv/' . $tvshow_id . '/changes', $parameters, $headers); } /** * Get the latest TV show id. - * - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getLatest(array $parameters = [], array $headers = []) + public function getLatest(array $parameters = [], array $headers = []): array { return $this->get('tv/latest', $parameters, $headers); } /** * Get the plot keywords for a specific TV show id. - * - * @param $tvshow_id - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getKeywords($tvshow_id, array $parameters = [], array $headers = []) + public function getKeywords(string $tvshow_id, array $parameters = [], array $headers = []): array { return $this->get('tv/' . $tvshow_id . '/keywords', $parameters, $headers); } /** * Get the similar TV shows for a specific tv id. - * - * @param $tvshow_id - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getSimilar($tvshow_id, array $parameters = [], array $headers = []) + public function getSimilar(string $tvshow_id, array $parameters = [], array $headers = []): array { return $this->get('tv/' . $tvshow_id . '/similar', $parameters, $headers); } /** * Get the recommended TV shows for a specific tv id. - * - * @param $tvshow_id - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getRecommendations($tvshow_id, array $parameters = [], array $headers = []) + public function getRecommendations(string $tvshow_id, array $parameters = [], array $headers = []): array { return $this->get('tv/' . $tvshow_id . '/recommendations', $parameters, $headers); } @@ -263,10 +192,9 @@ public function getRecommendations($tvshow_id, array $parameters = [], array $he * * A valid session id is required. * - * @param integer $id - * @return mixed + * @param int $id */ - public function getAccountStates($id) + public function getAccountStates($id): array { return $this->get('tv/' . $id . '/account_states'); } @@ -276,24 +204,20 @@ public function getAccountStates($id) * * A valid session id or guest session id is required. * - * @param integer $id - * @param double $rating - * @return mixed + * @param int $id + * @param float $rating */ - public function rateTvShow($id, $rating) + public function rateTvShow($id, $rating): array { - return $this->postJson('tv/' . $id . '/rating', ['value' => (float)$rating]); + return $this->postJson('tv/' . $id . '/rating', ['value' => (float) $rating]); } /** * Get the alternative titles for a specific show ID. * - * @param integer $id - * @param array $parameters - * @param array $headers - * @return mixed + * @param int $id */ - public function getAlternativeTitles($id, array $parameters = [], array $headers = []) + public function getAlternativeTitles($id, array $parameters = [], array $headers = []): array { return $this->get('tv/' . $id . '/alternative_titles', $parameters, $headers); } @@ -301,10 +225,9 @@ public function getAlternativeTitles($id, array $parameters = [], array $headers /** * Get the alternative titles for a specific show ID. * - * @param integer $id - * @return mixed + * @param int $id */ - public function getEpisodeGroups($id) + public function getEpisodeGroups($id): array { return $this->get('tv/' . $id . '/episode_groups'); } diff --git a/lib/Tmdb/Api/TvEpisode.php b/lib/Tmdb/Api/TvEpisode.php index 02b764a6..325469ac 100644 --- a/lib/Tmdb/Api/TvEpisode.php +++ b/lib/Tmdb/Api/TvEpisode.php @@ -1,195 +1,159 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ namespace Tmdb\Api; /** - * Class TvEpisode - * @package Tmdb\Api + * Class TvEpisode. + * * @see http://docs.themoviedb.apiary.io/#tvepisodes */ class TvEpisode extends AbstractApi { /** * Get the primary information about a TV episode by combination of a season and episode number. - * - * @param $tvshow_id - * @param $season_number - * @param $episode_number - * @param array $parameters - * @param array $headers - * @return mixed */ public function getEpisode( $tvshow_id, $season_number, $episode_number, array $parameters = [], - array $headers = [] - ) { + array $headers = [], + ): array { return $this->get( - sprintf( + \sprintf( 'tv/%s/season/%s/episode/%s', $tvshow_id, $season_number, - $episode_number + $episode_number, ), $parameters, - $headers + $headers, ); } /** * Get the TV episode credits by combination of season and episode number. - * - * @param $tvshow_id - * @param $season_number - * @param $episode_number - * @param array $parameters - * @param array $headers - * @return mixed */ public function getCredits( $tvshow_id, $season_number, $episode_number, array $parameters = [], - array $headers = [] - ) { + array $headers = [], + ): array { return $this->get( - sprintf( + \sprintf( 'tv/%s/season/%s/episode/%s/credits', $tvshow_id, $season_number, - $episode_number + $episode_number, ), $parameters, - $headers + $headers, ); } /** * Get the external ids for a TV episode by comabination of a season and episode number. - * - * @param $tvshow_id - * @param $season_number - * @param $episode_number - * @param array $parameters - * @param array $headers - * @return mixed */ public function getExternalIds( $tvshow_id, $season_number, $episode_number, array $parameters = [], - array $headers = [] - ) { + array $headers = [], + ): array { return $this->get( - sprintf( + \sprintf( 'tv/%s/season/%s/episode/%s/external_ids', $tvshow_id, $season_number, - $episode_number + $episode_number, ), $parameters, - $headers + $headers, ); } /** * Get the images (episode stills) for a TV episode by combination of a season and episode number. - * - * @param $tvshow_id - * @param $season_number - * @param $episode_number - * @param array $parameters - * @param array $headers - * @return mixed */ public function getImages( $tvshow_id, $season_number, $episode_number, array $parameters = [], - array $headers = [] - ) { + array $headers = [], + ): array { return $this->get( - sprintf( + \sprintf( 'tv/%s/season/%s/episode/%s/images', $tvshow_id, $season_number, - $episode_number + $episode_number, ), $parameters, - $headers + $headers, ); } /** * Get the list of translations that exist for a TV episode. * - * @param int $tvshow_id - * @param array $parameters - * @param array $headers - * @return mixed + * @param int $tvshow_id */ public function getTranslations( $tvshow_id, $season_number, $episode_number, array $parameters = [], - array $headers = [] - ) { + array $headers = [], + ): array { return $this->get( - sprintf( + \sprintf( 'tv/%s/season/%s/episode/%s/translations', $tvshow_id, $season_number, - $episode_number + $episode_number, ), $parameters, - $headers + $headers, ); } /** - * Get the videos that have been added to a TV episode (teasers, clips, etc...) - * - * @param $tvshow_id - * @param $season_number - * @param $episode_number - * @param array $parameters - * @param array $headers - * @return mixed + * Get the videos that have been added to a TV episode (teasers, clips, etc...). */ public function getVideos( $tvshow_id, $season_number, $episode_number, array $parameters = [], - array $headers = [] - ) { + array $headers = [], + ): array { return $this->get( - sprintf( + \sprintf( 'tv/%s/season/%s/episode/%s/videos', $tvshow_id, $season_number, - $episode_number + $episode_number, ), $parameters, - $headers + $headers, ); } @@ -198,30 +162,23 @@ public function getVideos( * * This method is used in conjunction with the /tv/{id}/changes method. * This method uses the episode_id value found in the change entries. - * - * @param $tvshow_id - * @param $season_number - * @param $episode_number - * @param array $parameters - * @param array $headers - * @return mixed */ public function getChanges( $tvshow_id, $season_number, $episode_number, array $parameters = [], - array $headers = [] - ) { + array $headers = [], + ): array { return $this->get( - sprintf( + \sprintf( 'tv/%s/season/%s/episode/%s/changes', $tvshow_id, $season_number, - $episode_number + $episode_number, ), $parameters, - $headers + $headers, ); } @@ -229,25 +186,19 @@ public function getChanges( * This method lets users get the status of whether or not the TV episode has been rated. * * A valid session id is required. - * - * @param $tvshow_id - * @param $season_number - * @param $episode_number - * - * @return mixed */ public function getAccountStates( $tvshow_id, $season_number, - $episode_number - ) { + $episode_number, + ): array { return $this->get( - sprintf( + \sprintf( 'tv/%s/season/%s/episode/%s/account_states', $tvshow_id, $season_number, - $episode_number - ) + $episode_number, + ), ); } @@ -256,27 +207,22 @@ public function getAccountStates( * * A valid session id or guest session id is required. * - * @param $tvshow_id - * @param $season_number - * @param $episode_number - * @param double $rating - * - * @return mixed + * @param float $rating */ public function rateTvEpisode( $tvshow_id, $season_number, $episode_number, - $rating - ) { + $rating, + ): array { return $this->postJson( - sprintf( + \sprintf( 'tv/%s/season/%s/episode/%s/rating', $tvshow_id, $season_number, - $episode_number + $episode_number, ), - ['value' => (float)$rating] + ['value' => (float) $rating], ); } } diff --git a/lib/Tmdb/Api/TvEpisodeGroup.php b/lib/Tmdb/Api/TvEpisodeGroup.php index 76b111e2..e2ccaf8c 100644 --- a/lib/Tmdb/Api/TvEpisodeGroup.php +++ b/lib/Tmdb/Api/TvEpisodeGroup.php @@ -1,46 +1,43 @@ get( - sprintf( + \sprintf( 'tv/episode_group/%s', - $episode_group + $episode_group, ), $parameters, - $headers + $headers, ); } } diff --git a/lib/Tmdb/Api/TvSeason.php b/lib/Tmdb/Api/TvSeason.php index 61ebad47..e8094300 100644 --- a/lib/Tmdb/Api/TvSeason.php +++ b/lib/Tmdb/Api/TvSeason.php @@ -1,94 +1,66 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ namespace Tmdb\Api; /** - * Class TvSeason - * @package Tmdb\Api + * Class TvSeason. + * * @see http://docs.themoviedb.apiary.io/#tvseasons */ class TvSeason extends AbstractApi { /** * Get the primary information about a TV season by its season number. - * - * @param $tvshow_id - * @param $season_number - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getSeason(int $tvshow_id, int $season_number, array $parameters = [], array $headers = []) + public function getSeason(int $tvshow_id, int $season_number, array $parameters = [], array $headers = []): array { - return $this->get(sprintf('tv/%s/season/%s', $tvshow_id, $season_number), $parameters, $headers); + return $this->get(\sprintf('tv/%s/season/%s', $tvshow_id, $season_number), $parameters, $headers); } /** * Get the cast & crew credits for a TV season by season number. - * - * @param $tvshow_id - * @param $season_number - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getCredits($tvshow_id, $season_number, array $parameters = [], array $headers = []) + public function getCredits($tvshow_id, $season_number, array $parameters = [], array $headers = []): array { - return $this->get(sprintf('tv/%s/season/%s/credits', $tvshow_id, $season_number), $parameters, $headers); + return $this->get(\sprintf('tv/%s/season/%s/credits', $tvshow_id, $season_number), $parameters, $headers); } /** * Get the external ids that we have stored for a TV season by season number. - * - * @param $tvshow_id - * @param $season_number - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getExternalIds($tvshow_id, $season_number, array $parameters = [], array $headers = []) + public function getExternalIds($tvshow_id, $season_number, array $parameters = [], array $headers = []): array { - return $this->get(sprintf('tv/%s/season/%s/external_ids', $tvshow_id, $season_number), $parameters, $headers); + return $this->get(\sprintf('tv/%s/season/%s/external_ids', $tvshow_id, $season_number), $parameters, $headers); } /** * Get the images (posters) that we have stored for a TV season by season number. - * - * @param $tvshow_id - * @param $season_number - * @param array $parameters - * @param array $headers - * @return mixed */ - public function getImages($tvshow_id, $season_number, array $parameters = [], array $headers = []) + public function getImages($tvshow_id, $season_number, array $parameters = [], array $headers = []): array { - return $this->get(sprintf('tv/%s/season/%s/images', $tvshow_id, $season_number), $parameters, $headers); + return $this->get(\sprintf('tv/%s/season/%s/images', $tvshow_id, $season_number), $parameters, $headers); } /** - * Get the videos that have been added to a TV season (trailers, teasers, etc...) - * - * @param $tvshow_id - * @param $season_number - * @param array $parameters - * @param array $headers - * @return mixed + * Get the videos that have been added to a TV season (trailers, teasers, etc...). */ - public function getVideos($tvshow_id, $season_number, array $parameters = [], array $headers = []) + public function getVideos($tvshow_id, $season_number, array $parameters = [], array $headers = []): array { - return $this->get(sprintf('tv/%s/season/%s/videos', $tvshow_id, $season_number), $parameters, $headers); + return $this->get(\sprintf('tv/%s/season/%s/videos', $tvshow_id, $season_number), $parameters, $headers); } /** @@ -97,14 +69,11 @@ public function getVideos($tvshow_id, $season_number, array $parameters = [], ar * * This method uses the season_id value found in the change entries. * - * @param integer $tvshow_id - * @param integer $season_number - * @param array $parameters - * @param array $headers - * @return mixed + * @param int $tvshow_id + * @param int $season_number */ - public function getChanges($tvshow_id, $season_number, array $parameters = [], array $headers = []) + public function getChanges($tvshow_id, $season_number, array $parameters = [], array $headers = []): array { - return $this->get(sprintf('tv/%s/season/%s/changes', $tvshow_id, $season_number), $parameters, $headers); + return $this->get(\sprintf('tv/%s/season/%s/changes', $tvshow_id, $season_number), $parameters, $headers); } } diff --git a/lib/Tmdb/ApiMethodsTrait.php b/lib/Tmdb/ApiMethodsTrait.php index aed724ae..eb310e59 100644 --- a/lib/Tmdb/ApiMethodsTrait.php +++ b/lib/Tmdb/ApiMethodsTrait.php @@ -1,14 +1,16 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ @@ -16,202 +18,127 @@ trait ApiMethodsTrait { - /** - * @return Api\Account - */ - public function getAccountApi() + public function getAccountApi(): \Tmdb\Api\Account { return new Api\Account($this); } - /** - * @return Api\Authentication - */ - public function getAuthenticationApi() + public function getAuthenticationApi(): \Tmdb\Api\Authentication { return new Api\Authentication($this); } - /** - * @return Api\Certifications - */ - public function getCertificationsApi() + public function getCertificationsApi(): \Tmdb\Api\Certifications { return new Api\Certifications($this); } - /** - * @return Api\Changes - */ - public function getChangesApi() + public function getChangesApi(): \Tmdb\Api\Changes { return new Api\Changes($this); } - /** - * @return Api\Collections - */ - public function getCollectionsApi() + public function getCollectionsApi(): \Tmdb\Api\Collections { return new Api\Collections($this); } - /** - * @return Api\Companies - */ - public function getCompaniesApi() + public function getCompaniesApi(): \Tmdb\Api\Companies { return new Api\Companies($this); } - /** - * @return Api\Configuration - */ - public function getConfigurationApi() + public function getConfigurationApi(): \Tmdb\Api\Configuration { return new Api\Configuration($this); } - /** - * @return Api\Credits - */ - public function getCreditsApi() + public function getCreditsApi(): \Tmdb\Api\Credits { return new Api\Credits($this); } - /** - * @return Api\Discover - */ - public function getDiscoverApi() + public function getDiscoverApi(): \Tmdb\Api\Discover { return new Api\Discover($this); } - /** - * @return Api\Find - */ - public function getFindApi() + public function getFindApi(): \Tmdb\Api\Find { return new Api\Find($this); } - /** - * @return Api\Genres - */ - public function getGenresApi() + public function getGenresApi(): \Tmdb\Api\Genres { return new Api\Genres($this); } - /** - * @return Api\GuestSession - */ - public function getGuestSessionApi() + public function getGuestSessionApi(): \Tmdb\Api\GuestSession { return new Api\GuestSession($this); } - /** - * @return Api\Jobs - */ - public function getJobsApi() + public function getJobsApi(): \Tmdb\Api\Jobs { return new Api\Jobs($this); } - /** - * @return Api\Keywords - */ - public function getKeywordsApi() + public function getKeywordsApi(): \Tmdb\Api\Keywords { return new Api\Keywords($this); } - /** - * @return Api\Lists - */ - public function getListsApi() + public function getListsApi(): \Tmdb\Api\Lists { return new Api\Lists($this); } - /** - * @return Api\Movies - */ - public function getMoviesApi() + public function getMoviesApi(): \Tmdb\Api\Movies { return new Api\Movies($this); } - /** - * @return Api\Networks - */ - public function getNetworksApi() + public function getNetworksApi(): \Tmdb\Api\Networks { return new Api\Networks($this); } - /** - * @return Api\People - */ - public function getPeopleApi() + public function getPeopleApi(): \Tmdb\Api\People { return new Api\People($this); } - /** - * @return Api\Reviews - */ - public function getReviewsApi() + public function getReviewsApi(): \Tmdb\Api\Reviews { return new Api\Reviews($this); } - /** - * @return Api\Search - */ - public function getSearchApi() + public function getSearchApi(): \Tmdb\Api\Search { return new Api\Search($this); } - /** - * @return Api\Timezones - */ - public function getTimezonesApi() + public function getTimezonesApi(): \Tmdb\Api\Timezones { return new Api\Timezones($this); } - /** - * @return Api\Tv - */ - public function getTvApi() + public function getTvApi(): \Tmdb\Api\Tv { return new Api\Tv($this); } - /** - * @return Api\TvSeason - */ - public function getTvSeasonApi() + public function getTvSeasonApi(): \Tmdb\Api\TvSeason { return new Api\TvSeason($this); } - /** - * @return Api\TvEpisode - */ - public function getTvEpisodeApi() + public function getTvEpisodeApi(): \Tmdb\Api\TvEpisode { return new Api\TvEpisode($this); } - /** - * @return Api\TvEpisodeGroup - */ - public function getTvEpisodeGroupApi() + public function getTvEpisodeGroupApi(): \Tmdb\Api\TvEpisodeGroup { return new Api\TvEpisodeGroup($this); } diff --git a/lib/Tmdb/Client.php b/lib/Tmdb/Client.php index 36468168..fd7d68e9 100644 --- a/lib/Tmdb/Client.php +++ b/lib/Tmdb/Client.php @@ -1,14 +1,16 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ @@ -28,11 +30,9 @@ use Tmdb\Token\Api\BearerToken; use Tmdb\Token\Session\GuestSessionToken; use Tmdb\Token\Session\SessionBearerToken; -use Tmdb\Token\Session\SessionToken; /** - * Client wrapper for TMDB - * @package Tmdb + * Client wrapper for TMDB. */ class Client { @@ -51,21 +51,17 @@ class Client public const SCHEME_SECURE = 'https'; /** - * Stores the HTTP Client - * - * @var HttpClient + * Stores the HTTP Client. */ - private $httpClient; + private \Tmdb\HttpClient\HttpClient $httpClient; /** - * Store the options - * - * @var array + * Store the options. */ - private $options = []; + private array $options = []; /** - * Construct our client + * Construct our client. * * @param ConfigurationInterface|array $options */ @@ -79,9 +75,8 @@ public function __construct($options = []) } /** - * Configure options + * Configure options. * - * @param array $options * @return array */ protected function configureOptions(array $options) @@ -95,7 +90,7 @@ protected function configureOptions(array $options) 'base_uri' => null, 'api_token' => null, 'guest_session_token' => null, - 'http' => function (OptionsResolver $optionsResolver) { + 'http' => function (OptionsResolver $optionsResolver): void { $optionsResolver->setDefaults( [ 'client' => null, @@ -103,7 +98,7 @@ protected function configureOptions(array $options) 'response_factory' => null, 'stream_factory' => null, 'uri_factory' => null, - ] + ], ); $optionsResolver->setRequired( [ @@ -111,8 +106,8 @@ protected function configureOptions(array $options) 'request_factory', 'response_factory', 'stream_factory', - 'uri_factory' - ] + 'uri_factory', + ], ); $optionsResolver->setAllowedTypes('client', [ClientInterface::class, 'null']); $optionsResolver->setAllowedTypes('request_factory', [RequestFactoryInterface::class, 'null']); @@ -120,28 +115,28 @@ protected function configureOptions(array $options) $optionsResolver->setAllowedTypes('stream_factory', [StreamFactoryInterface::class, 'null']); $optionsResolver->setAllowedTypes('uri_factory', [UriFactoryInterface::class, 'null']); }, - 'hydration' => function (OptionsResolver $optionsResolver) { + 'hydration' => function (OptionsResolver $optionsResolver): void { $optionsResolver->setDefaults( [ 'event_listener_handles_hydration' => false, - 'only_for_specified_models' => [] - ] + 'only_for_specified_models' => [], + ], ); $optionsResolver->setAllowedTypes('event_listener_handles_hydration', ['bool']); // @todo 4.1 validate these are actually models $optionsResolver->setAllowedTypes('only_for_specified_models', ['array']); }, - 'event_dispatcher' => function (OptionsResolver $optionsResolver) { + 'event_dispatcher' => function (OptionsResolver $optionsResolver): void { $optionsResolver->setDefaults( [ - 'adapter' => null - ] + 'adapter' => null, + ], ); $optionsResolver->setRequired(['adapter']); $optionsResolver->setAllowedTypes('adapter', [EventDispatcherInterface::class]); - } - ] + }, + ], ); $resolver->setRequired( @@ -151,7 +146,7 @@ protected function configureOptions(array $options) 'secure', 'http', 'event_dispatcher', - ] + ], ); $resolver->setAllowedTypes('host', ['string']); @@ -168,16 +163,16 @@ protected function configureOptions(array $options) [ GuestSessionToken::class, SessionBearerToken::class, - 'null' - ] + 'null', + ], ); - if (is_string($options['api_token'])) { + if (\is_string($options['api_token'])) { $options['api_token'] = new ApiToken($options['api_token']); } $this->options = $this->postResolve( - $resolver->resolve($options) + $resolver->resolve($options), ); $this->httpClient = new HttpClient( @@ -185,62 +180,54 @@ protected function configureOptions(array $options) 'http' => $this->options['http'], 'event_dispatcher' => $this->options['event_dispatcher'], 'base_uri' => $this->options['base_uri'], - 'hydration' => $this->options['hydration'] - ] + 'hydration' => $this->options['hydration'], + ], ); return $this->options; } /** - * Post resolve - * - * @param array $options - * @return array + * Post resolve. */ protected function postResolve(array $options = []): array { - $options['http']['client'] = $options['http']['client'] ?? + $options['http']['client'] ??= Psr18ClientDiscovery::find(); - $options['http']['request_factory'] = $options['http']['request_factory'] ?? + $options['http']['request_factory'] ??= Psr17FactoryDiscovery::findRequestFactory(); - $options['http']['response_factory'] = $options['http']['response_factory'] ?? + $options['http']['response_factory'] ??= Psr17FactoryDiscovery::findResponseFactory(); - $options['http']['stream_factory'] = $options['http']['stream_factory'] ?? + $options['http']['stream_factory'] ??= Psr17FactoryDiscovery::findStreamFactory(); - $options['http']['uri_factory'] = $options['http']['uri_factory'] ?? + $options['http']['uri_factory'] ??= Psr17FactoryDiscovery::findUriFactory(); // Automatically enable event listener acceptance if the end-user forgot to enable this. if ( - !empty($options['hydration']['only_for_specified_models']) && - !$options['hydration']['event_listener_handles_hydration'] + !empty($options['hydration']['only_for_specified_models']) + && !$options['hydration']['event_listener_handles_hydration'] ) { $options['hydration']['event_listener_handles_hydration'] = true; } - $options['base_uri'] = sprintf( + $options['base_uri'] = \sprintf( '%s://%s', $options['secure'] ? self::SCHEME_SECURE : self::SCHEME_INSECURE, - $options['host'] + $options['host'], ); return $options; } /** - * Get the event dispatcher - * - * @return EventDispatcherInterface + * Get the event dispatcher. */ public function getEventDispatcher(): EventDispatcherInterface { return $this->options['event_dispatcher']['adapter']; } - /** - * @return HttpClient - */ public function getHttpClient(): HttpClient { return $this->httpClient; @@ -254,18 +241,11 @@ public function getOptions() return $this->options; } - /** - * @return GuestSessionToken|null - */ public function getGuestSessionToken(): ?GuestSessionToken { return $this->options['guest_session_token']; } - /** - * @param GuestSessionToken|null $guestSessionToken - * @return self - */ public function setGuestSessionToken(?GuestSessionToken $guestSessionToken): Client { $this->options['guest_session_token'] = $guestSessionToken; @@ -273,21 +253,16 @@ public function setGuestSessionToken(?GuestSessionToken $guestSessionToken): Cli return $this; } - /** - * @return ApiToken|BearerToken - */ public function getToken(): ApiToken { return $this->options['api_token']; } /** - * @param string $key - * * @return array|mixed */ public function getOption(string $key) { - return array_key_exists($key, $this->options) ? $this->options[$key] : null; + return $this->options[$key] ?? null; } } diff --git a/lib/Tmdb/Common/ObjectHydrator.php b/lib/Tmdb/Common/ObjectHydrator.php index ff1c15f6..9dc971fe 100644 --- a/lib/Tmdb/Common/ObjectHydrator.php +++ b/lib/Tmdb/Common/ObjectHydrator.php @@ -1,14 +1,16 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ @@ -21,36 +23,30 @@ * Utilisation class to hydrate objects. * * Class ObjectHydrator - * @package Tmdb\Common */ class ObjectHydrator { /** - * Hydrate the object with data + * Hydrate the object with data. * - * @param AbstractModel $object * @param array $data - * @return AbstractModel + * + * * @throws RuntimeException */ - public function hydrate(AbstractModel $object, $data = []) + public function hydrate(AbstractModel $object, $data = []): AbstractModel { if (!empty($data)) { foreach ($data as $k => $v) { - if (in_array($k, $object::$properties)) { + if (\in_array($k, $object::$properties, true)) { $method = $this->camelize( - sprintf('set_%s', $k) + \sprintf('set_%s', $k), ); - if (!is_callable([$object, $method])) { - throw new RuntimeException(sprintf( - 'Trying to call method "%s" on "%s" but it does not exist or is private.', - $method, - get_class($object) - )); - } else { - $object->$method($v); + if (!\is_callable([$object, $method])) { + throw new RuntimeException(\sprintf('Trying to call method "%s" on "%s" but it does not exist or is private.', $method, $object::class)); } + $object->{$method}($v); } } } @@ -59,14 +55,13 @@ public function hydrate(AbstractModel $object, $data = []) } /** - * Transforms an under_scored_string to a camelCasedOne + * Transforms an under_scored_string to a camelCasedOne. * * @see https://gist.github.com/troelskn/751517 * * @param string $candidate - * @return string */ - public function camelize($candidate) + public function camelize($candidate): string { return lcfirst( implode( @@ -77,11 +72,11 @@ public function camelize($candidate) 'strtolower', explode( '_', - $candidate - ) - ) - ) - ) + $candidate, + ), + ), + ), + ), ); } } diff --git a/lib/Tmdb/ConfigurationInterface.php b/lib/Tmdb/ConfigurationInterface.php index 8e0064b8..677ff3e7 100644 --- a/lib/Tmdb/ConfigurationInterface.php +++ b/lib/Tmdb/ConfigurationInterface.php @@ -1,14 +1,16 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ diff --git a/lib/Tmdb/Event/AfterHydrationEvent.php b/lib/Tmdb/Event/AfterHydrationEvent.php index f3ce021a..54b029b7 100644 --- a/lib/Tmdb/Event/AfterHydrationEvent.php +++ b/lib/Tmdb/Event/AfterHydrationEvent.php @@ -1,24 +1,21 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ namespace Tmdb\Event; -use Psr\Http\Message\RequestInterface; -use Psr\Http\Message\ResponseInterface; -use Symfony\Contracts\EventDispatcher\Event; -use Tmdb\Model\AbstractModel; - class AfterHydrationEvent extends HydrationEvent { } diff --git a/lib/Tmdb/Event/BeforeHydrationEvent.php b/lib/Tmdb/Event/BeforeHydrationEvent.php index 35f3594d..999ea6b6 100644 --- a/lib/Tmdb/Event/BeforeHydrationEvent.php +++ b/lib/Tmdb/Event/BeforeHydrationEvent.php @@ -1,24 +1,21 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ namespace Tmdb\Event; -use Psr\Http\Message\RequestInterface; -use Psr\Http\Message\ResponseInterface; -use Symfony\Contracts\EventDispatcher\Event; -use Tmdb\Model\AbstractModel; - class BeforeHydrationEvent extends HydrationEvent { } diff --git a/lib/Tmdb/Event/BeforeRequestEvent.php b/lib/Tmdb/Event/BeforeRequestEvent.php index d66ba25e..7790005f 100644 --- a/lib/Tmdb/Event/BeforeRequestEvent.php +++ b/lib/Tmdb/Event/BeforeRequestEvent.php @@ -1,26 +1,21 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ namespace Tmdb\Event; -use Psr\EventDispatcher\EventDispatcherInterface; -use Psr\EventDispatcher\StoppableEventInterface; -use Psr\Http\Message\RequestInterface; -use Psr\Http\Message\ResponseInterface; -use Symfony\Contracts\EventDispatcher\Event; -use Tmdb\HttpClient\Request; - class BeforeRequestEvent extends RequestEvent { } diff --git a/lib/Tmdb/Event/HttpClientExceptionEvent.php b/lib/Tmdb/Event/HttpClientExceptionEvent.php index 5a416689..c41552fc 100644 --- a/lib/Tmdb/Event/HttpClientExceptionEvent.php +++ b/lib/Tmdb/Event/HttpClientExceptionEvent.php @@ -1,14 +1,16 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ @@ -20,68 +22,35 @@ class HttpClientExceptionEvent extends StoppableEvent implements LoggableHttpEventInterface { - /** - * @var ClientExceptionInterface - */ - private $exception; - - /** - * @var RequestInterface - */ - private $request; - - /** - * @var ResponseInterface|null - */ - private $response; + private ?\Psr\Http\Message\ResponseInterface $response = null; /** - * Constructor - * - * @param ClientExceptionInterface $exception - * @param RequestInterface $request + * Constructor. */ - public function __construct(ClientExceptionInterface $exception, RequestInterface $request) + public function __construct(private readonly ClientExceptionInterface $exception, private readonly RequestInterface $request) { - $this->exception = $exception; - $this->request = $request; } - /** - * @return ClientExceptionInterface - */ public function getException(): ClientExceptionInterface { return $this->exception; } - /** - * @return RequestInterface - */ public function getRequest(): RequestInterface { return $this->request; } - /** - * @return bool - */ public function hasResponse(): bool { return null !== $this->response; } - /** - * @return ResponseInterface|null - */ public function getResponse(): ?ResponseInterface { return $this->response; } - /** - * @param ResponseInterface $response - */ public function setResponse(ResponseInterface $response): void { $this->response = $response; diff --git a/lib/Tmdb/Event/HydrationEvent.php b/lib/Tmdb/Event/HydrationEvent.php index 15a3052b..bd6ec41e 100644 --- a/lib/Tmdb/Event/HydrationEvent.php +++ b/lib/Tmdb/Event/HydrationEvent.php @@ -1,14 +1,16 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ @@ -21,50 +23,22 @@ class HydrationEvent extends Event { - /** - * @var AbstractModel - */ - private $subject; - - /** - * @var array - */ - private $data; - - /** - * @var RequestInterface|null - */ - private $lastRequest; + private ?\Psr\Http\Message\RequestInterface $lastRequest = null; - /** - * @var ResponseInterface|null - */ - private $lastResponse; + private ?\Psr\Http\Message\ResponseInterface $lastResponse = null; /** - * Constructor - * - * @param AbstractModel $subject - * @param array $data + * Constructor. */ - public function __construct(AbstractModel $subject, array $data = []) + public function __construct(private AbstractModel $subject, private array $data = []) { - $this->subject = $subject; - $this->data = $data; } - /** - * @return AbstractModel - */ public function getSubject(): AbstractModel { return $this->subject; } - /** - * @param AbstractModel $subject - * @return self - */ public function setSubject(AbstractModel $subject): HydrationEvent { $this->subject = $subject; @@ -72,18 +46,11 @@ public function setSubject(AbstractModel $subject): HydrationEvent return $this; } - /** - * @return array - */ public function getData(): array { return $this->data; } - /** - * @param array $data - * @return self - */ public function setData(array $data = []): HydrationEvent { $this->data = $data; @@ -91,26 +58,16 @@ public function setData(array $data = []): HydrationEvent return $this; } - /** - * @return bool - */ public function hasData(): bool { return !empty($this->data); } - /** - * @return RequestInterface|null - */ public function getLastRequest(): ?RequestInterface { return $this->lastRequest; } - /** - * @param RequestInterface|null $lastRequest - * @return self - */ public function setLastRequest(?RequestInterface $lastRequest = null): HydrationEvent { $this->lastRequest = $lastRequest; @@ -118,18 +75,11 @@ public function setLastRequest(?RequestInterface $lastRequest = null): Hydration return $this; } - /** - * @return ResponseInterface|null - */ public function getLastResponse(): ?ResponseInterface { return $this->lastResponse; } - /** - * @param ResponseInterface|null $lastResponse - * @return self - */ public function setLastResponse(?ResponseInterface $lastResponse = null): HydrationEvent { $this->lastResponse = $lastResponse; diff --git a/lib/Tmdb/Event/Listener/HydrationListener.php b/lib/Tmdb/Event/Listener/HydrationListener.php index 1d88eb1b..7f65bdb9 100644 --- a/lib/Tmdb/Event/Listener/HydrationListener.php +++ b/lib/Tmdb/Event/Listener/HydrationListener.php @@ -1,14 +1,16 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ @@ -22,39 +24,24 @@ use Tmdb\Model\AbstractModel; /** - * Class RequestSubscriber - * @package Tmdb\Event + * Class RequestSubscriber. */ class HydrationListener { - /** - * @var EventDispatcherInterface - */ - private $eventDispatcher; - - /** - * @var ObjectHydrator - */ - private $hydrator; + private readonly \Tmdb\Common\ObjectHydrator $hydrator; /** * HydrationListener constructor. - * @param EventDispatcherInterface $eventDispatcher */ - public function __construct(EventDispatcherInterface $eventDispatcher) + public function __construct(private readonly EventDispatcherInterface $eventDispatcher) { - $this->eventDispatcher = $eventDispatcher; $this->hydrator = new ObjectHydrator(); } /** - * Hydrate the subject with data - * - * @param HydrationEvent $event - * - * @return AbstractModel + * Hydrate the subject with data. */ - public function __invoke(HydrationEvent $event) + public function __invoke(HydrationEvent $event): \Tmdb\Model\AbstractModel { $before = new BeforeHydrationEvent($event->getSubject(), $event->getData()); $before->setLastRequest($event->getLastRequest()); @@ -76,9 +63,8 @@ public function __invoke(HydrationEvent $event) } /** - * Hydrate the subject + * Hydrate the subject. * - * @param HydrationEvent $event * @return AbstractModel */ public function hydrateSubject(HydrationEvent $event) diff --git a/lib/Tmdb/Event/Listener/Logger/LogApiErrorListener.php b/lib/Tmdb/Event/Listener/Logger/LogApiErrorListener.php index 431fe055..035c3bef 100644 --- a/lib/Tmdb/Event/Listener/Logger/LogApiErrorListener.php +++ b/lib/Tmdb/Event/Listener/Logger/LogApiErrorListener.php @@ -1,14 +1,16 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ @@ -20,43 +22,27 @@ use Tmdb\Formatter\TmdbApiExceptionFormatterInterface; /** - * Class LogApiErrorListener - * @package Tmdb\Event + * Class LogApiErrorListener. */ class LogApiErrorListener { - /** - * @var LoggerInterface - */ - private $logger; - - /** - * @var TmdbApiExceptionFormatterInterface - */ - private $formatter; + private readonly \Tmdb\Formatter\TmdbApiExceptionFormatterInterface $formatter; /** * LogApiErrorListener constructor. - * @param LoggerInterface $logger - * @param TmdbApiExceptionFormatterInterface|null $formatter */ - public function __construct(LoggerInterface $logger, ?TmdbApiExceptionFormatterInterface $formatter = null) + public function __construct(private readonly LoggerInterface $logger, ?TmdbApiExceptionFormatterInterface $formatter = null) { - $this->logger = $logger; $this->formatter = $formatter ?: new SimpleTmdbApiExceptionFormatter(); } - /** - * @param TmdbExceptionEvent $event - * @return void - */ public function __invoke(TmdbExceptionEvent $event): void { $this->logger->critical( - sprintf( + \sprintf( 'Critical API exception:' . PHP_EOL . '%s', - $this->formatter->formatApiException($event->getException()) - ) + $this->formatter->formatApiException($event->getException()), + ), ); } } diff --git a/lib/Tmdb/Event/Listener/Logger/LogHttpMessageListener.php b/lib/Tmdb/Event/Listener/Logger/LogHttpMessageListener.php index 16f1bfd3..a5e275e7 100644 --- a/lib/Tmdb/Event/Listener/Logger/LogHttpMessageListener.php +++ b/lib/Tmdb/Event/Listener/Logger/LogHttpMessageListener.php @@ -1,20 +1,21 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ namespace Tmdb\Event\Listener\Logger; -use Psr\Http\Client\ClientExceptionInterface; use Psr\Log\LoggerInterface; use Tmdb\Event\BeforeRequestEvent; use Tmdb\Event\HttpClientExceptionEvent; @@ -24,36 +25,20 @@ use Tmdb\Formatter\HttpMessageFormatterInterface; /** - * Class LogHttpMessageListener - * @package Tmdb\Event + * Class LogHttpMessageListener. */ class LogHttpMessageListener { - /** - * @var LoggerInterface - */ - private $logger; - - /** - * @var HttpMessageFormatterInterface - */ - private $formatter; + private readonly \Tmdb\Formatter\HttpMessageFormatterInterface $formatter; /** * LogHttpMessageListener constructor. - * @param LoggerInterface $logger - * @param HttpMessageFormatterInterface|null $formatter */ - public function __construct(LoggerInterface $logger, ?HttpMessageFormatterInterface $formatter = null) + public function __construct(private readonly LoggerInterface $logger, ?HttpMessageFormatterInterface $formatter = null) { - $this->logger = $logger; $this->formatter = $formatter ?: new SimpleHttpMessageFormatter(); } - /** - * @param LoggableHttpEventInterface $event - * @return void - */ public function __invoke(LoggableHttpEventInterface $event): void { if ($event instanceof BeforeRequestEvent) { @@ -69,41 +54,35 @@ public function __invoke(LoggableHttpEventInterface $event): void } } - /** - * @param BeforeRequestEvent $event - */ protected function logRequest(BeforeRequestEvent $event): void { - if (null !== $event->getRequest()->getBody()) { + if ($event->getRequest()->getBody() instanceof \Psr\Http\Message\StreamInterface) { $event->getRequest()->getBody()->rewind(); } $context = [ 'length' => $event->getRequest()->getBody()->getSize(), - 'has_session_token' => $event->hasSessionToken() + 'has_session_token' => $event->hasSessionToken(), ]; $this->logger->info( - sprintf( + \sprintf( 'Sending request:' . PHP_EOL . '%s', - $this->formatter->formatRequest($event->getRequest()) + $this->formatter->formatRequest($event->getRequest()), ), - $context + $context, ); } - /** - * @param ResponseEvent $event - */ protected function logResponse(ResponseEvent $event): void { - $cacheHit = $event->getResponse()->hasHeader('X-TMDB-Cache') && - 'HIT' === $event->getResponse()->getHeaderLine('X-TMDB-Cache'); + $cacheHit = $event->getResponse()->hasHeader('X-TMDB-Cache') + && 'HIT' === $event->getResponse()->getHeaderLine('X-TMDB-Cache'); $context = [ 'status_code' => $event->getResponse()->getStatusCode(), 'length' => $event->getResponse()->getBody()->getSize(), - 'cached' => $cacheHit + 'cached' => $cacheHit, ]; $format = 'Received response:' . PHP_EOL . '%s'; @@ -113,29 +92,26 @@ protected function logResponse(ResponseEvent $event): void } $this->logger->info( - sprintf( + \sprintf( $format, - $this->formatter->formatResponse($event->getResponse()) + $this->formatter->formatResponse($event->getResponse()), ), - $context + $context, ); } - /** - * @param HttpClientExceptionEvent $event - */ protected function logClientException(HttpClientExceptionEvent $event): void { $context = [ - 'request' => $event->getRequest()->getUri()->__toString() + 'request' => $event->getRequest()->getUri()->__toString(), ]; $this->logger->critical( - sprintf( + \sprintf( 'Critical http client error:' . PHP_EOL . '%s', - $this->formatter->formatClientException($event->getException()) + $this->formatter->formatClientException($event->getException()), ), - $context + $context, ); } } diff --git a/lib/Tmdb/Event/Listener/Logger/LogHydrationListener.php b/lib/Tmdb/Event/Listener/Logger/LogHydrationListener.php index 40ab81be..2402e1d9 100644 --- a/lib/Tmdb/Event/Listener/Logger/LogHydrationListener.php +++ b/lib/Tmdb/Event/Listener/Logger/LogHydrationListener.php @@ -1,14 +1,16 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ @@ -16,63 +18,41 @@ use Psr\Log\LoggerInterface; use Tmdb\Event\BeforeHydrationEvent; -use Tmdb\Formatter\HttpMessageFormatterInterface; use Tmdb\Formatter\Hydration\SimpleHydrationFormatter; use Tmdb\Formatter\HydrationFormatterInterface; /** - * Class LogHydrationListener - * @package Tmdb\Event + * Class LogHydrationListener. */ class LogHydrationListener { - /** - * @var LoggerInterface - */ - private $logger; - - /** - * @var HydrationFormatterInterface - */ - private $formatter; - - /** - * @var bool - */ - private $withData; + private readonly \Tmdb\Formatter\HydrationFormatterInterface $formatter; /** * RequestListener constructor. - * @param LoggerInterface $logger - * @param HydrationFormatterInterface|null $formatter - * @param bool $withData If true the context will contain the data used. + * + * @param bool $withData if true the context will contain the data used */ public function __construct( - LoggerInterface $logger, + private readonly LoggerInterface $logger, ?HydrationFormatterInterface $formatter = null, - bool $withData = false + private readonly bool $withData = false, ) { - $this->logger = $logger; $this->formatter = $formatter ?: new SimpleHydrationFormatter(); - $this->withData = $withData; } - /** - * @param BeforeHydrationEvent $event - * @return void - */ public function __invoke(BeforeHydrationEvent $event): void { $context = []; if ($this->withData) { $context['data'] = $event->getData(); - $context['data_size'] = \mb_strlen(\GuzzleHttp\Utils::jsonEncode($event->getData()), 'UTF-8'); + $context['data_size'] = mb_strlen(\GuzzleHttp\Utils::jsonEncode($event->getData()), 'UTF-8'); } $this->logger->debug( $this->formatter->formatBeforeEvent($event), - $context + $context, ); } } diff --git a/lib/Tmdb/Event/Listener/Psr6CachedRequestListener.php b/lib/Tmdb/Event/Listener/Psr6CachedRequestListener.php index e69cbe57..fe0ecee4 100644 --- a/lib/Tmdb/Event/Listener/Psr6CachedRequestListener.php +++ b/lib/Tmdb/Event/Listener/Psr6CachedRequestListener.php @@ -1,14 +1,16 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ @@ -32,25 +34,9 @@ * This is a little hacky, but I just wanna get 4.0 pushed ASAP. At a later stage we will review this again. * * Class Psr6CachedRequestListener - * @package Tmdb\Event\Listener */ class Psr6CachedRequestListener extends RequestListener { - /** - * @var CacheItemPoolInterface - */ - private $cache; - - /** - * @var StreamFactoryInterface - */ - private $streamFactory; - - /** - * @var array - */ - private $options; - /** * @var CachePlugin */ @@ -58,35 +44,22 @@ class Psr6CachedRequestListener extends RequestListener /** * Psr6CachedRequestListener constructor. - * - * @param HttpClient $httpClient - * @param EventDispatcherInterface $eventDispatcher - * @param CacheItemPoolInterface $cache - * @param StreamFactoryInterface $streamFactory - * @param array $options - * @param array $pluginOptions */ public function __construct( HttpClient $httpClient, EventDispatcherInterface $eventDispatcher, - CacheItemPoolInterface $cache, - StreamFactoryInterface $streamFactory, - array $options = [], - array $pluginOptions = [] + private readonly CacheItemPoolInterface $cache, + private readonly StreamFactoryInterface $streamFactory, + array $pluginOptions = [], ) { parent::__construct($httpClient, $eventDispatcher); - - $this->cache = $cache; - $this->streamFactory = $streamFactory; - $this->options = $options; $this->httpCachePlugin = CachePlugin::serverCache($this->cache, $this->streamFactory, $pluginOptions); } /** * Add the API token to the headers. - * - * @param RequestEvent $event */ + #[\Override] public function __invoke(RequestEvent $event): void { // Preparation of request parameters / Possibility to use for logging and caching etc. @@ -97,6 +70,7 @@ public function __invoke(RequestEvent $event): void if ($beforeRequestEvent->isPropagationStopped() && $beforeRequestEvent->hasResponse()) { $event->setResponse($beforeRequestEvent->getResponse()); + return; } @@ -105,20 +79,20 @@ public function __invoke(RequestEvent $event): void try { $response = $this->httpCachePlugin->handleRequest( $event->getRequest(), - function ($request) use ($beforeRequestEvent, &$cachedResponse) { + function ($request) use ($beforeRequestEvent, &$cachedResponse): \Http\Promise\FulfilledPromise { $cachedResponse = false; $response = $this->sendRequest($beforeRequestEvent); return new FulfilledPromise($response); }, - function () { - } // we do not need the plugin to go back + function (): void { + }, // we do not need the plugin to go back ); $response->then( - function ($result) use ($beforeRequestEvent) { + function ($result) use ($beforeRequestEvent): void { $beforeRequestEvent->setResponse($result); - } + }, ); $response = $beforeRequestEvent->getResponse(); @@ -128,10 +102,7 @@ function ($result) use ($beforeRequestEvent) { try { if ($response->getStatusCode() >= 400 && $response->getStatusCode() < 600) { - throw $this->responseExceptionFactory->createTmdbApiException( - $beforeRequestEvent->getRequest(), - $response - ); + throw $this->responseExceptionFactory->createTmdbApiException($beforeRequestEvent->getRequest(), $response); } $event->setRequest($beforeRequestEvent->getRequest()); diff --git a/lib/Tmdb/Event/Listener/Request/AcceptJsonRequestListener.php b/lib/Tmdb/Event/Listener/Request/AcceptJsonRequestListener.php index bc317557..1d6a5b75 100644 --- a/lib/Tmdb/Event/Listener/Request/AcceptJsonRequestListener.php +++ b/lib/Tmdb/Event/Listener/Request/AcceptJsonRequestListener.php @@ -1,14 +1,16 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ @@ -21,7 +23,7 @@ class AcceptJsonRequestListener public function __invoke(RequestEvent $event): void { $event->setRequest( - $event->getRequest()->withHeader('Accept', 'application/json; charset=utf-8') + $event->getRequest()->withHeader('Accept', 'application/json; charset=utf-8'), ); } } diff --git a/lib/Tmdb/Event/Listener/Request/AdultFilterRequestListener.php b/lib/Tmdb/Event/Listener/Request/AdultFilterRequestListener.php index 5cedfa8a..073be062 100644 --- a/lib/Tmdb/Event/Listener/Request/AdultFilterRequestListener.php +++ b/lib/Tmdb/Event/Listener/Request/AdultFilterRequestListener.php @@ -1,14 +1,16 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ @@ -19,26 +21,20 @@ class AdultFilterRequestListener { - private $includeAdult; - /** - * @var RequestQueryHelper - */ - private $requestQueryHelper; + private readonly \Tmdb\Helper\RequestQueryHelper $requestQueryHelper; /** * AdultFilterRequestListener constructor. + * * @param bool $includeAdult */ - public function __construct($includeAdult = false) + public function __construct(private $includeAdult = false) { - $this->includeAdult = $includeAdult; $this->requestQueryHelper = new RequestQueryHelper(); } /** * Set the adult filter. - * - * @param RequestEvent $event */ public function __invoke(RequestEvent $event): void { @@ -46,8 +42,8 @@ public function __invoke(RequestEvent $event): void $this->requestQueryHelper->withQuery( $event->getRequest(), 'include_adult', - $this->includeAdult === true ? 'true' : 'false' - ) + true === $this->includeAdult ? 'true' : 'false', + ), ); } } diff --git a/lib/Tmdb/Event/Listener/Request/ApiTokenRequestListener.php b/lib/Tmdb/Event/Listener/Request/ApiTokenRequestListener.php index 2f4e2e33..fb7c5e79 100644 --- a/lib/Tmdb/Event/Listener/Request/ApiTokenRequestListener.php +++ b/lib/Tmdb/Event/Listener/Request/ApiTokenRequestListener.php @@ -1,60 +1,50 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ namespace Tmdb\Event\Listener\Request; -use Tmdb\Token\Api\ApiToken; -use Tmdb\Token\Api\BearerToken; use Tmdb\Event\RequestEvent; use Tmdb\Helper\RequestQueryHelper; +use Tmdb\Token\Api\ApiToken; +use Tmdb\Token\Api\BearerToken; class ApiTokenRequestListener { - /** - * @var ApiToken - */ - private $token; - - /** - * @var RequestQueryHelper - */ - private $requestQueryHelper; + private readonly \Tmdb\Helper\RequestQueryHelper $requestQueryHelper; /** * ApiTokenRequestListener constructor. - * @param ApiToken $token */ - public function __construct(ApiToken $token) + public function __construct(private readonly ApiToken $token) { - $this->token = $token; $this->requestQueryHelper = new RequestQueryHelper(); } /** * Add the API token to the headers. - * - * @param RequestEvent $event */ public function __invoke(RequestEvent $event): void { if ($this->token instanceof BearerToken) { $event->setRequest( - $event->getRequest()->withHeader('Authorization', sprintf('Bearer %s', (string)$this->token)) + $event->getRequest()->withHeader('Authorization', \sprintf('Bearer %s', (string) $this->token)), ); } else { $event->setRequest( - $this->requestQueryHelper->withQuery($event->getRequest(), 'api_key', (string)$this->token) + $this->requestQueryHelper->withQuery($event->getRequest(), 'api_key', (string) $this->token), ); } } diff --git a/lib/Tmdb/Event/Listener/Request/ContentTypeJsonRequestListener.php b/lib/Tmdb/Event/Listener/Request/ContentTypeJsonRequestListener.php index 95bf25a6..9c805734 100644 --- a/lib/Tmdb/Event/Listener/Request/ContentTypeJsonRequestListener.php +++ b/lib/Tmdb/Event/Listener/Request/ContentTypeJsonRequestListener.php @@ -1,14 +1,16 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ @@ -18,22 +20,18 @@ class ContentTypeJsonRequestListener { - /** - * - * @param RequestEvent $event - */ public function __invoke(RequestEvent $event): void { $method = $event->getRequest()->getMethod(); if ( - $method == 'POST' || - $method == 'PUT' || - $method == 'PATCH' || - $method == 'DELETE' + 'POST' === $method + || 'PUT' === $method + || 'PATCH' === $method + || 'DELETE' === $method ) { $event->setRequest( - $event->getRequest()->withHeader('Content-Type', 'application/json') + $event->getRequest()->withHeader('Content-Type', 'application/json'), ); } } diff --git a/lib/Tmdb/Event/Listener/Request/LanguageFilterRequestListener.php b/lib/Tmdb/Event/Listener/Request/LanguageFilterRequestListener.php index 9c6d03c8..3a54a8a8 100644 --- a/lib/Tmdb/Event/Listener/Request/LanguageFilterRequestListener.php +++ b/lib/Tmdb/Event/Listener/Request/LanguageFilterRequestListener.php @@ -1,54 +1,45 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ namespace Tmdb\Event\Listener\Request; -use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Tmdb\Event\RequestEvent; use Tmdb\Helper\RequestQueryHelper; class LanguageFilterRequestListener { - /** - * @var string - */ - private $language; - - /** - * @var RequestQueryHelper - */ - private $requestQueryHelper; + private readonly \Tmdb\Helper\RequestQueryHelper $requestQueryHelper; /** * LanguageFilterRequestListener constructor. + * * @param string $language */ - public function __construct($language = 'en') + public function __construct(private $language = 'en') { - $this->language = $language; $this->requestQueryHelper = new RequestQueryHelper(); } /** * Set the language filter. - * - * @param RequestEvent $event */ public function __invoke(RequestEvent $event): void { $event->setRequest( - $this->requestQueryHelper->withQuery($event->getRequest(), 'language', $this->language) + $this->requestQueryHelper->withQuery($event->getRequest(), 'language', $this->language), ); } } diff --git a/lib/Tmdb/Event/Listener/Request/RegionFilterRequestListener.php b/lib/Tmdb/Event/Listener/Request/RegionFilterRequestListener.php index e7ef4bff..a153c9fc 100644 --- a/lib/Tmdb/Event/Listener/Request/RegionFilterRequestListener.php +++ b/lib/Tmdb/Event/Listener/Request/RegionFilterRequestListener.php @@ -1,54 +1,45 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ namespace Tmdb\Event\Listener\Request; -use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Tmdb\Event\RequestEvent; use Tmdb\Helper\RequestQueryHelper; class RegionFilterRequestListener { - /** - * @var string - */ - private $region; - - /** - * @var RequestQueryHelper - */ - private $requestQueryHelper; + private readonly \Tmdb\Helper\RequestQueryHelper $requestQueryHelper; /** * RegionFilterRequestListener constructor. + * * @param string $region */ - public function __construct($region = 'en') + public function __construct(private $region = 'en') { - $this->region = $region; $this->requestQueryHelper = new RequestQueryHelper(); } /** * Set the region filter. - * - * @param RequestEvent $event */ public function __invoke(RequestEvent $event): void { $event->setRequest( - $this->requestQueryHelper->withQuery($event->getRequest(), 'region', $this->region) + $this->requestQueryHelper->withQuery($event->getRequest(), 'region', $this->region), ); } } diff --git a/lib/Tmdb/Event/Listener/Request/SessionTokenRequestListener.php b/lib/Tmdb/Event/Listener/Request/SessionTokenRequestListener.php index cb550834..a703fe55 100644 --- a/lib/Tmdb/Event/Listener/Request/SessionTokenRequestListener.php +++ b/lib/Tmdb/Event/Listener/Request/SessionTokenRequestListener.php @@ -1,68 +1,56 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ namespace Tmdb\Event\Listener\Request; use Tmdb\Event\RequestEvent; -use Tmdb\Token\Session\GuestSessionToken; use Tmdb\Helper\RequestQueryHelper; +use Tmdb\Token\Session\GuestSessionToken; use Tmdb\Token\Session\SessionBearerToken; use Tmdb\Token\Session\SessionToken; class SessionTokenRequestListener { - /** - * @var SessionToken - */ - private $token; - - /** - * @var RequestQueryHelper - */ - private $requestQueryHelper; + private readonly \Tmdb\Helper\RequestQueryHelper $requestQueryHelper; /** * SessionTokenRequestListener constructor. - * @param SessionToken $token */ - public function __construct(SessionToken $token) + public function __construct(private readonly SessionToken $token) { - $this->token = $token; $this->requestQueryHelper = new RequestQueryHelper(); } /** * Set the token filter. - * - * @param RequestEvent $event */ public function __invoke(RequestEvent $event): void { if ($this->token instanceof SessionBearerToken) { $event->setRequest( - $event->getRequest()->withHeader('Authorization', sprintf('Bearer %s', (string)$this->token)) + $event->getRequest()->withHeader('Authorization', \sprintf('Bearer %s', (string) $this->token)), ); return; - } elseif ($this->token instanceof GuestSessionToken) { - $key = 'guest_session_id'; - } else { - $key = 'session_id'; } + $key = $this->token instanceof GuestSessionToken ? 'guest_session_id' : 'session_id'; + $event->setRequest( - $this->requestQueryHelper->withQuery($event->getRequest(), $key, (string)$this->token) + $this->requestQueryHelper->withQuery($event->getRequest(), $key, (string) $this->token), ); } } diff --git a/lib/Tmdb/Event/Listener/Request/UserAgentRequestListener.php b/lib/Tmdb/Event/Listener/Request/UserAgentRequestListener.php index 0190003d..2c516572 100644 --- a/lib/Tmdb/Event/Listener/Request/UserAgentRequestListener.php +++ b/lib/Tmdb/Event/Listener/Request/UserAgentRequestListener.php @@ -1,14 +1,16 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ @@ -19,29 +21,23 @@ class UserAgentRequestListener { - /** - * @var string|null - */ - private $userAgent; + private readonly string $userAgent; /** * UserAgentRequestListener constructor. - * @param string|null $userAgent */ public function __construct(?string $userAgent = null) { - $this->userAgent = $userAgent ?? sprintf('php-tmdb/api/%s', Client::VERSION); + $this->userAgent = $userAgent ?? \sprintf('php-tmdb/api/%s', Client::VERSION); } /** * Add the API token to the headers. - * - * @param RequestEvent $event */ public function __invoke(RequestEvent $event): void { $event->setRequest( - $event->getRequest()->withHeader('User-Agent', $this->userAgent) + $event->getRequest()->withHeader('User-Agent', $this->userAgent), ); } } diff --git a/lib/Tmdb/Event/Listener/RequestListener.php b/lib/Tmdb/Event/Listener/RequestListener.php index 359f346d..7fd83b72 100644 --- a/lib/Tmdb/Event/Listener/RequestListener.php +++ b/lib/Tmdb/Event/Listener/RequestListener.php @@ -1,14 +1,16 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ @@ -29,45 +31,26 @@ use Tmdb\HttpClient\HttpClient; /** - * Class RequestSubscriber - * @package Tmdb\Event + * Class RequestSubscriber. */ class RequestListener { - /** - * @var HttpClient - */ - private $httpClient; - - /** - * @var EventDispatcherInterface - */ - protected $eventDispatcher; - - /** - * @var ResponseExceptionFactory - */ - protected $responseExceptionFactory; + protected \Tmdb\Exception\Factory\ResponseExceptionFactory $responseExceptionFactory; /** * RequestListener constructor. - * @param EventDispatcherInterface $eventDispatcher */ - public function __construct(HttpClient $httpClient, EventDispatcherInterface $eventDispatcher) + public function __construct(private readonly HttpClient $httpClient, protected \Psr\EventDispatcher\EventDispatcherInterface $eventDispatcher) { - $this->httpClient = $httpClient; - $this->eventDispatcher = $eventDispatcher; $this->responseExceptionFactory = new ResponseExceptionFactory(); } /** - * @param RequestEvent $event - * @return void * @throws Exception * @throws TmdbApiException * @throws ClientExceptionInterface */ - public function __invoke(RequestEvent $event) + public function __invoke(RequestEvent $event): void { // Preparation of request parameters / Possibility to use for logging and caching etc. $beforeRequestEvent = new BeforeRequestEvent($event->getRequest()); @@ -77,6 +60,7 @@ public function __invoke(RequestEvent $event) if ($beforeRequestEvent->isPropagationStopped() && $beforeRequestEvent->hasResponse()) { $event->setResponse($beforeRequestEvent->getResponse()); + return; } @@ -88,10 +72,7 @@ public function __invoke(RequestEvent $event) try { if ($response->getStatusCode() >= 400 && $response->getStatusCode() < 600) { - throw $this->responseExceptionFactory->createTmdbApiException( - $beforeRequestEvent->getRequest(), - $response - ); + throw $this->responseExceptionFactory->createTmdbApiException($beforeRequestEvent->getRequest(), $response); } $event->setRequest($beforeRequestEvent->getRequest()); @@ -105,10 +86,8 @@ public function __invoke(RequestEvent $event) } /** - * Call upon the adapter to create an response object + * Call upon the adapter to create an response object. * - * @param RequestEvent $event - * @return ResponseInterface * @throws Exception * @throws ClientExceptionInterface */ @@ -118,14 +97,11 @@ public function sendRequest(RequestEvent $event): ResponseInterface } /** - * @param ClientExceptionInterface $e - * @param RequestInterface $request - * @return ResponseInterface * @throws ClientExceptionInterface */ protected function handleClientException( ClientExceptionInterface $e, - RequestInterface $request + RequestInterface $request, ): ResponseInterface { // In the event of failures, you can recover certain exceptions. $exceptionEvent = new HttpClientExceptionEvent($e, $request); @@ -140,8 +116,6 @@ protected function handleClientException( } /** - * @param TmdbApiException $e - * @return ResponseInterface * @throws TmdbApiException */ protected function handleTmdbApiException(TmdbApiException $e): ResponseInterface diff --git a/lib/Tmdb/Event/LoggableHttpEventInterface.php b/lib/Tmdb/Event/LoggableHttpEventInterface.php index 6cbf63f8..a7f05422 100644 --- a/lib/Tmdb/Event/LoggableHttpEventInterface.php +++ b/lib/Tmdb/Event/LoggableHttpEventInterface.php @@ -1,14 +1,16 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ diff --git a/lib/Tmdb/Event/RequestEvent.php b/lib/Tmdb/Event/RequestEvent.php index e8997afd..5572c75c 100644 --- a/lib/Tmdb/Event/RequestEvent.php +++ b/lib/Tmdb/Event/RequestEvent.php @@ -1,14 +1,16 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ @@ -19,50 +21,24 @@ use Tmdb\Token\Session\SessionToken; /** - * Class RequestEvent - * @package Tmdb\Event + * Class RequestEvent. */ class RequestEvent extends StoppableEvent implements LoggableHttpEventInterface { - /** - * @var RequestInterface - */ - private $request; - - /** - * @var ?ResponseInterface - */ - private $response; + private ?\Psr\Http\Message\ResponseInterface $response = null; /** - * @var ?SessionToken + * Construct the request event. */ - private $sessionToken; - - /** - * Construct the request event - * - * @param RequestInterface $request - * @param SessionToken|null $sessionToken - */ - public function __construct(RequestInterface $request, ?SessionToken $sessionToken = null) + public function __construct(private RequestInterface $request, private ?SessionToken $sessionToken = null) { - $this->request = $request; - $this->sessionToken = $sessionToken; } - /** - * @return RequestInterface - */ public function getRequest(): RequestInterface { return $this->request; } - /** - * @param RequestInterface $request - * @return self - */ public function setRequest(RequestInterface $request): RequestEvent { $this->request = $request; @@ -70,18 +46,11 @@ public function setRequest(RequestInterface $request): RequestEvent return $this; } - /** - * @return ?ResponseInterface - */ public function getResponse(): ?ResponseInterface { return $this->response; } - /** - * @param ResponseInterface $response - * @return self - */ public function setResponse(ResponseInterface $response): RequestEvent { $this->response = $response; @@ -97,18 +66,11 @@ public function hasResponse() return $this->response instanceof ResponseInterface; } - /** - * @return ?SessionToken - */ public function getSessionToken(): ?SessionToken { return $this->sessionToken; } - /** - * @param SessionToken|null $sessionToken - * @return self - */ public function setSessionToken(?SessionToken $sessionToken = null): RequestEvent { $this->sessionToken = $sessionToken; @@ -116,9 +78,6 @@ public function setSessionToken(?SessionToken $sessionToken = null): RequestEven return $this; } - /** - * @return bool - */ public function hasSessionToken(): bool { return $this->sessionToken instanceof SessionToken; diff --git a/lib/Tmdb/Event/ResponseEvent.php b/lib/Tmdb/Event/ResponseEvent.php index e928a962..996c5a0d 100644 --- a/lib/Tmdb/Event/ResponseEvent.php +++ b/lib/Tmdb/Event/ResponseEvent.php @@ -1,14 +1,16 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ @@ -21,30 +23,12 @@ class ResponseEvent implements LoggableHttpEventInterface { /** - * @var RequestInterface - */ - private $request; - - /** - * @var ResponseInterface + * Construct the request event. */ - private $response; - - /** - * Construct the request event - * - * @param ResponseInterface $response - * @param RequestInterface $request - */ - public function __construct(ResponseInterface $response, RequestInterface $request) + public function __construct(private ResponseInterface $response, private RequestInterface $request) { - $this->response = $response; - $this->request = $request; } - /** - * @return RequestInterface - */ public function getRequest(): RequestInterface { return $this->request; @@ -52,46 +36,32 @@ public function getRequest(): RequestInterface /** * @param RequestInterface $request - * @return self */ - public function setRequest($request) + public function setRequest($request): static { $this->request = $request; return $this; } - /** - * @return ResponseInterface - */ public function getResponse(): ResponseInterface { return $this->response; } - /** - * @param ResponseInterface $response - * @return self - */ - public function setResponse(ResponseInterface $response) + public function setResponse(ResponseInterface $response): static { $this->response = $response; return $this; } - /** - * @return bool - */ - public function hasResponse() + public function hasResponse(): bool { return null !== $this->response; } - /** - * @return bool - */ - public function hasRequest() + public function hasRequest(): bool { return null !== $this->request; } diff --git a/lib/Tmdb/Event/StoppableEvent.php b/lib/Tmdb/Event/StoppableEvent.php index 91dedb0e..cc6de1c7 100644 --- a/lib/Tmdb/Event/StoppableEvent.php +++ b/lib/Tmdb/Event/StoppableEvent.php @@ -1,14 +1,16 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ @@ -25,8 +27,9 @@ public function stopPropagation(): void $this->isPropagationStopped = true; } + #[\Override] public function isPropagationStopped(): bool { - return (bool)$this->isPropagationStopped; + return (bool) $this->isPropagationStopped; } } diff --git a/lib/Tmdb/Event/TmdbExceptionEvent.php b/lib/Tmdb/Event/TmdbExceptionEvent.php index 2bdde6dc..c3f172a3 100644 --- a/lib/Tmdb/Event/TmdbExceptionEvent.php +++ b/lib/Tmdb/Event/TmdbExceptionEvent.php @@ -1,14 +1,16 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ @@ -19,53 +21,30 @@ class TmdbExceptionEvent extends StoppableEvent { - /** - * @var TmdbApiException - */ - private $exception; + private ?\Psr\Http\Message\ResponseInterface $response = null; /** - * @var ResponseInterface + * Constructor. */ - private $response; - - /** - * Constructor - * - * @param TmdbApiException $exception - */ - public function __construct(TmdbApiException $exception) + public function __construct(private readonly TmdbApiException $exception) { - $this->exception = $exception; } - /** - * @return TmdbApiException - */ public function getException(): TmdbApiException { return $this->exception; } - /** - * @return bool - */ public function hasResponse(): bool { return null !== $this->response; } - /** - * @return ResponseInterface|null - */ public function getResponse(): ?ResponseInterface { return $this->response; } - /** - * @param ResponseInterface $response - */ public function setResponse(ResponseInterface $response): void { $this->response = $response; diff --git a/lib/Tmdb/Exception/ApiTokenMissingException.php b/lib/Tmdb/Exception/ApiTokenMissingException.php index ca00c9e8..eaaf5c77 100644 --- a/lib/Tmdb/Exception/ApiTokenMissingException.php +++ b/lib/Tmdb/Exception/ApiTokenMissingException.php @@ -1,23 +1,26 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ namespace Tmdb\Exception; +use RuntimeException; + /** - * Class ApiTokenException - * @package Tmdb\Exception + * Class ApiTokenException. */ -class ApiTokenMissingException extends \RuntimeException +class ApiTokenMissingException extends RuntimeException { } diff --git a/lib/Tmdb/Exception/Factory/ResponseExceptionFactory.php b/lib/Tmdb/Exception/Factory/ResponseExceptionFactory.php index 7f6e7d60..e47f56e3 100644 --- a/lib/Tmdb/Exception/Factory/ResponseExceptionFactory.php +++ b/lib/Tmdb/Exception/Factory/ResponseExceptionFactory.php @@ -1,19 +1,22 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ namespace Tmdb\Exception\Factory; +use Exception; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use Tmdb\Exception\RuntimeException; @@ -23,9 +26,6 @@ class ResponseExceptionFactory { /** - * @param RequestInterface $request - * @param ResponseInterface $response - * @return TmdbApiException * @throws UnexpectedResponseException * @throws RuntimeException */ @@ -33,8 +33,8 @@ public function createTmdbApiException(RequestInterface $request, ResponseInterf { try { if ( - $response->hasHeader('content-type') && - strpos($response->getHeaderLine('content-type'), 'application/json') !== false + $response->hasHeader('content-type') + && str_contains($response->getHeaderLine('content-type'), 'application/json') ) { $response->getBody()->rewind(); @@ -45,15 +45,13 @@ public function createTmdbApiException(RequestInterface $request, ResponseInterf $data->status_code, $data->status_message, $request, - $response + $response, ); } - } catch (\Exception $e) { + } catch (Exception) { throw new RuntimeException('Unable to create TmdbApiException, could not decode response body.'); } - throw new UnexpectedResponseException( - 'Unable to create an helpful Exception, server did not contain a json body.' - ); + throw new UnexpectedResponseException('Unable to create an helpful Exception, server did not contain a json body.'); } } diff --git a/lib/Tmdb/Exception/InvalidArgumentException.php b/lib/Tmdb/Exception/InvalidArgumentException.php index b49a6cec..a9f91e92 100644 --- a/lib/Tmdb/Exception/InvalidArgumentException.php +++ b/lib/Tmdb/Exception/InvalidArgumentException.php @@ -1,22 +1,23 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ namespace Tmdb\Exception; /** - * Class InvalidArgumentException - * @package Tmdb\Exception + * Class InvalidArgumentException. */ class InvalidArgumentException extends \InvalidArgumentException { diff --git a/lib/Tmdb/Exception/JsonDecodingException.php b/lib/Tmdb/Exception/JsonDecodingException.php index 0b837f1a..fd6bc146 100644 --- a/lib/Tmdb/Exception/JsonDecodingException.php +++ b/lib/Tmdb/Exception/JsonDecodingException.php @@ -1,14 +1,16 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ diff --git a/lib/Tmdb/Exception/MissingArgumentException.php b/lib/Tmdb/Exception/MissingArgumentException.php index 51f90f20..9cf51dcc 100644 --- a/lib/Tmdb/Exception/MissingArgumentException.php +++ b/lib/Tmdb/Exception/MissingArgumentException.php @@ -1,23 +1,26 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ namespace Tmdb\Exception; +use InvalidArgumentException; + /** - * Class MissingArgumentException - * @package Tmdb\Exception + * Class MissingArgumentException. */ -class MissingArgumentException extends \InvalidArgumentException +class MissingArgumentException extends InvalidArgumentException { } diff --git a/lib/Tmdb/Exception/MissingSessionTokenException.php b/lib/Tmdb/Exception/MissingSessionTokenException.php index 2b71b12d..62901cde 100644 --- a/lib/Tmdb/Exception/MissingSessionTokenException.php +++ b/lib/Tmdb/Exception/MissingSessionTokenException.php @@ -1,23 +1,26 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ namespace Tmdb\Exception; +use RuntimeException; + /** - * Class MissingSessionTokenException - * @package Tmdb\Exception + * Class MissingSessionTokenException. */ -class MissingSessionTokenException extends \RuntimeException +class MissingSessionTokenException extends RuntimeException { } diff --git a/lib/Tmdb/Exception/NotImplementedException.php b/lib/Tmdb/Exception/NotImplementedException.php index 777944c1..2ba5a072 100644 --- a/lib/Tmdb/Exception/NotImplementedException.php +++ b/lib/Tmdb/Exception/NotImplementedException.php @@ -1,14 +1,16 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ @@ -17,8 +19,7 @@ use Exception; /** - * Class NotImplementedException - * @package Tmdb\Exception + * Class NotImplementedException. */ class NotImplementedException extends Exception { diff --git a/lib/Tmdb/Exception/RuntimeException.php b/lib/Tmdb/Exception/RuntimeException.php index 67121dd9..fbed3154 100644 --- a/lib/Tmdb/Exception/RuntimeException.php +++ b/lib/Tmdb/Exception/RuntimeException.php @@ -1,22 +1,23 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ namespace Tmdb\Exception; /** - * Class RuntimeException - * @package Tmdb\Exception + * Class RuntimeException. */ class RuntimeException extends \RuntimeException { diff --git a/lib/Tmdb/Exception/TmdbApiException.php b/lib/Tmdb/Exception/TmdbApiException.php index 402eb530..ecae653e 100644 --- a/lib/Tmdb/Exception/TmdbApiException.php +++ b/lib/Tmdb/Exception/TmdbApiException.php @@ -1,14 +1,16 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ @@ -19,8 +21,7 @@ use Psr\Http\Message\ResponseInterface; /** - * Class TmdbApiException - * @package Tmdb\Exception + * Class TmdbApiException. */ class TmdbApiException extends Exception { @@ -60,35 +61,16 @@ class TmdbApiException extends Exception public const STATUS_RESOURCE_NOT_FOUND = 34; /** - * @var RequestInterface - */ - protected $request; - - /** - * @var ResponseInterface - */ - protected $response; - - /** - * Create the exception - * - * @param int $code - * @param string $message - * @param RequestInterface|null $request - * @param ResponseInterface|null $response - * @param Exception|null $previous + * Create the exception. */ public function __construct( int $code, string $message, - ?RequestInterface $request = null, - ?ResponseInterface $response = null, - ?Exception $previous = null + protected ?\Psr\Http\Message\RequestInterface $request = null, + protected ?\Psr\Http\Message\ResponseInterface $response = null, + ?Exception $previous = null, ) { parent::__construct($message, $code, $previous); - - $this->request = $request; - $this->response = $response; } /** @@ -99,10 +81,6 @@ public function getRequest() return $this->request; } - /** - * @param RequestInterface $request - * @return self - */ public function setRequest(RequestInterface $request): TmdbApiException { $this->request = $request; @@ -118,10 +96,6 @@ public function getResponse() return $this->response; } - /** - * @param ResponseInterface $response - * @return self - */ public function setResponse(ResponseInterface $response): TmdbApiException { $this->response = $response; diff --git a/lib/Tmdb/Exception/UnauthorizedRequestTokenException.php b/lib/Tmdb/Exception/UnauthorizedRequestTokenException.php index 2d98d095..ef66b652 100644 --- a/lib/Tmdb/Exception/UnauthorizedRequestTokenException.php +++ b/lib/Tmdb/Exception/UnauthorizedRequestTokenException.php @@ -1,23 +1,26 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ namespace Tmdb\Exception; +use RuntimeException; + /** - * Class UnauthorizedRequestTokenException - * @package Tmdb\Exception + * Class UnauthorizedRequestTokenException. */ -class UnauthorizedRequestTokenException extends \RuntimeException +class UnauthorizedRequestTokenException extends RuntimeException { } diff --git a/lib/Tmdb/Exception/UnexpectedResponseException.php b/lib/Tmdb/Exception/UnexpectedResponseException.php index 77e39354..d717d4b3 100644 --- a/lib/Tmdb/Exception/UnexpectedResponseException.php +++ b/lib/Tmdb/Exception/UnexpectedResponseException.php @@ -1,14 +1,16 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ diff --git a/lib/Tmdb/Factory/AbstractFactory.php b/lib/Tmdb/Factory/AbstractFactory.php index 74eeafe1..9b55f666 100644 --- a/lib/Tmdb/Factory/AbstractFactory.php +++ b/lib/Tmdb/Factory/AbstractFactory.php @@ -1,14 +1,16 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ @@ -18,7 +20,6 @@ use Tmdb\Common\ObjectHydrator; use Tmdb\Event\BeforeHydrationEvent; use Tmdb\Event\HydrationEvent; -use Tmdb\Event\TmdbEvents; use Tmdb\HttpClient\HttpClient; use Tmdb\Model\AbstractModel; use Tmdb\Model\Collection\ResultCollection; @@ -28,53 +29,42 @@ use Tmdb\Model\Lists\Result; /** - * Class AbstractFactory + * Class AbstractFactory. * * @template T of AbstractModel - * - * @package Tmdb\Factory */ abstract class AbstractFactory { /** - * @var HttpClient - */ - protected $httpClient; - - /** - * Constructor - * - * @param HttpClient $httpClient + * Constructor. */ - public function __construct(HttpClient $httpClient) + public function __construct(protected \Tmdb\HttpClient\HttpClient $httpClient) { - $this->httpClient = $httpClient; } /** - * Convert an array to an hydrated object + * Convert an array to an hydrated object. * - * @param array $data * @return T */ abstract public function create(array $data = []); /** - * Convert an array with an collection of items to an hydrated object collection + * Convert an array with an collection of items to an hydrated object collection. * - * @param array $data * @return GenericCollection */ abstract public function createCollection(array $data = []); /** - * Create a result collection + * Create a result collection. + * + * @param array|null $data + * @param string $method * - * @param null|array $data - * @param string $method * @return ResultCollection */ - public function createResultCollection($data = [], $method = 'create'): ResultCollection + public function createResultCollection(array $data = [], $method = 'create'): ResultCollection { /** @var ResultCollection */ $collection = new ResultCollection(); @@ -83,33 +73,32 @@ public function createResultCollection($data = [], $method = 'create'): ResultCo return $collection; } - if (array_key_exists('page', $data)) { + if (\array_key_exists('page', $data)) { $collection->setPage($data['page']); } - if (array_key_exists('total_pages', $data)) { + if (\array_key_exists('total_pages', $data)) { $collection->setTotalPages($data['total_pages']); } - if (array_key_exists('total_results', $data)) { + if (\array_key_exists('total_results', $data)) { $collection->setTotalResults($data['total_results']); } - if (array_key_exists('results', $data)) { + if (\array_key_exists('results', $data)) { $data = $data['results']; } foreach ($data as $item) { - $collection->add(null, $this->$method($item)); + $collection->add(null, $this->{$method}($item)); } return $collection; } /** - * Create rating + * Create rating. * - * @param array $data * @return Rating */ public function createRating(array $data = []) @@ -118,12 +107,13 @@ public function createRating(array $data = []) } /** - * Hydrate the object with data + * Hydrate the object with data. * * @template S of AbstractModel * - * @param S $subject + * @param S $subject * @param array $data + * * @return S */ protected function hydrate(AbstractModel $subject, $data = []) @@ -135,9 +125,10 @@ protected function hydrate(AbstractModel $subject, $data = []) $eventBasedHydrationModels = $hydrationOptions['only_for_specified_models']; if ( - $eventListenerHandlesHydration && empty($eventBasedHydrationModels) || in_array( - get_class($subject), - $eventBasedHydrationModels + $eventListenerHandlesHydration && empty($eventBasedHydrationModels) || \in_array( + $subject::class, + $eventBasedHydrationModels, + true, ) ) { $event = new HydrationEvent($subject, $data); @@ -160,7 +151,7 @@ protected function hydrate(AbstractModel $subject, $data = []) } /** - * Get the http client + * Get the http client. * * @return HttpClient */ @@ -170,16 +161,15 @@ protected function getHttpClient() } /** - * Create the account states + * Create the account states. * - * @param array $data * @return AccountStates */ public function createAccountStates(array $data = []) { $accountStates = new AccountStates(); - if (array_key_exists('rated', $data)) { + if (\array_key_exists('rated', $data)) { if ($data['rated']) { $rating = new Rating(); @@ -193,9 +183,8 @@ public function createAccountStates(array $data = []) } /** - * Create result + * Create result. * - * @param array $data * @return Result */ public function createResult(array $data = []) @@ -204,10 +193,10 @@ public function createResult(array $data = []) } /** - * Create a generic collection of data and map it on the class by it's static parameter $properties + * 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 S|string $class * * @return GenericCollection @@ -218,8 +207,8 @@ protected function createGenericCollection(array $data = [], $class = null): Gen throw new \Tmdb\Exception\RuntimeException('Expected a class to be present.'); } - if (is_object($class)) { - $class = get_class($class); + if (\is_object($class)) { + $class = $class::class; } /** @var GenericCollection */ @@ -233,26 +222,27 @@ protected function createGenericCollection(array $data = [], $class = null): Gen } /** - * Create a generic collection of data and map it on the class by it's static parameter $properties + * 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 S|string $class - * @param SC $collection + * @param SC $collection + * * @return SC */ protected function createCustomCollection( array $data, $class, - GenericCollection $collection + GenericCollection $collection, ) { if (!$class) { throw new \Tmdb\Exception\RuntimeException('Expected a class to be present.'); } - if (is_object($class)) { - $class = get_class($class); + if (\is_object($class)) { + $class = $class::class; } foreach ($data as $item) { @@ -263,9 +253,10 @@ protected function createCustomCollection( } /** - * Create an generic collection of an array that consists out of a mix of movies and tv shows + * Create an generic collection of an array that consists out of a mix of movies and tv shows. * * @param array $data + * * @return GenericCollection */ protected function createGenericCollectionFromMediaTypes($data = []) @@ -275,18 +266,11 @@ protected function createGenericCollectionFromMediaTypes($data = []) $collection = new GenericCollection(); foreach ($data as $item) { - switch ($item['media_type']) { - case "movie": - $collection->add(null, $movieFactory->create($item)); - break; - - case "tv": - $collection->add(null, $tvFactory->create($item)); - break; - - default: - throw new RuntimeException('Unknown media type "%s"', $item['media_type']); - } + match ($item['media_type']) { + 'movie' => $collection->add(null, $movieFactory->create($item)), + 'tv' => $collection->add(null, $tvFactory->create($item)), + default => throw new RuntimeException('Unknown media type "%s"', $item['media_type']), + }; } return $collection; diff --git a/lib/Tmdb/Factory/Account/AvatarFactory.php b/lib/Tmdb/Factory/Account/AvatarFactory.php index f345ab32..3efa7eff 100644 --- a/lib/Tmdb/Factory/Account/AvatarFactory.php +++ b/lib/Tmdb/Factory/Account/AvatarFactory.php @@ -1,14 +1,16 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ @@ -20,18 +22,15 @@ use Tmdb\Model\Common\GenericCollection; /** - * Class AvatarFactory - * @package Tmdb\Factory\Account + * Class AvatarFactory. */ class AvatarFactory extends AbstractFactory { - /** - * {@inheritdoc} - */ + #[\Override] public function createCollection(array $data = []): GenericCollection { // @todo 4.0.x double check on this bug - if (array_key_exists(0, $data)) { + if (\array_key_exists(0, $data)) { $data = $data[0]; } @@ -42,31 +41,21 @@ public function createCollection(array $data = []): GenericCollection } /** - * @param array $data - * - * @return mixed * @throws InvalidArgumentException - * */ + #[\Override] public function create(array $data = []) { foreach ($data as $type => $content) { // @todo 4.0.x double check on this bug - if (array_key_exists(0, $content)) { + if (\array_key_exists(0, $content)) { $content = array_shift($content); } - switch ($type) { - case "gravatar": - return $this->hydrate(new Gravatar(), $content); - - default: - throw new InvalidArgumentException(sprintf( - 'The avatar type "%s" has not been defined in the factory "%s".', - $type, - __CLASS__ - )); - } + return match ($type) { + 'gravatar' => $this->hydrate(new Gravatar(), $content), + default => throw new InvalidArgumentException(\sprintf('The avatar type "%s" has not been defined in the factory "%s".', $type, self::class)), + }; } return null; diff --git a/lib/Tmdb/Factory/AccountFactory.php b/lib/Tmdb/Factory/AccountFactory.php index b56abba8..e465bcc0 100644 --- a/lib/Tmdb/Factory/AccountFactory.php +++ b/lib/Tmdb/Factory/AccountFactory.php @@ -1,14 +1,16 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ @@ -22,36 +24,22 @@ use Tmdb\Model\Lists\Result; /** - * Class AccountFactory + * Class AccountFactory. + * * @extends AbstractFactory - * @package Tmdb\Factory */ class AccountFactory extends AbstractFactory { - /** - * @var MovieFactory - */ - private $movieFactory; + private \Tmdb\Factory\MovieFactory $movieFactory; - /** - * @var ImageFactory - */ - private $imageFactory; + private \Tmdb\Factory\ImageFactory $imageFactory; - /** - * @var TvFactory - */ - private $tvFactory; + private \Tmdb\Factory\TvFactory $tvFactory; - /** - * @var AvatarFactory - */ - private $avatarFactory; + private \Tmdb\Factory\Account\AvatarFactory $avatarFactory; /** - * Constructor - * - * @param HttpClient $httpClient + * Constructor. */ public function __construct(HttpClient $httpClient) { @@ -63,18 +51,14 @@ public function __construct(HttpClient $httpClient) parent::__construct($httpClient); } - /** - * @param array $data - * - * @return Account - */ + #[\Override] public function create(array $data = []): Account { $account = new Account(); - if (array_key_exists('avatar', $data)) { + if (\array_key_exists('avatar', $data)) { $account->setAvatar( - $this->getAvatarFactory()->createCollection($data['avatar']) + $this->getAvatarFactory()->createCollection($data['avatar']), ); } @@ -90,8 +74,6 @@ public function getAvatarFactory() } /** - * @param array $data - * * @return Result */ public function createStatusResult(array $data = []) @@ -100,11 +82,7 @@ public function createStatusResult(array $data = []) } /** - * Create movie - * - * @param array $data - * - * @return AbstractModel|null + * Create movie. */ public function createMovie(array $data = []): ?AbstractModel { @@ -121,9 +99,8 @@ public function getMovieFactory() /** * @param MovieFactory $movieFactory - * @return self */ - public function setMovieFactory($movieFactory) + public function setMovieFactory($movieFactory): static { $this->movieFactory = $movieFactory; @@ -131,11 +108,7 @@ public function setMovieFactory($movieFactory) } /** - * Create TV show - * - * @param array $data - * - * @return AbstractModel|null + * Create TV show. */ public function createTvShow(array $data = []): ?AbstractModel { @@ -152,9 +125,8 @@ public function getTvFactory() /** * @param TvFactory $tvFactory - * @return self */ - public function setTvFactory($tvFactory) + public function setTvFactory($tvFactory): static { $this->tvFactory = $tvFactory; @@ -162,16 +134,15 @@ public function setTvFactory($tvFactory) } /** - * Create list item + * Create list item. * - * @param array $data * @return AbstractModel */ public function createListItem(array $data = []) { $listItem = new Account\ListItem(); - if (array_key_exists('poster_path', $data)) { + if (\array_key_exists('poster_path', $data)) { $listItem->setPosterImage($this->getImageFactory()->createFromPath($data['poster_path'], 'poster_path')); } @@ -188,32 +159,24 @@ public function getImageFactory() /** * @param ImageFactory $imageFactory - * @return self */ - public function setImageFactory($imageFactory) + public function setImageFactory($imageFactory): static { $this->imageFactory = $imageFactory; return $this; } - /** - * {@inheritdoc} - */ - public function createCollection(array $data = []) + #[\Override] + public function createCollection(array $data = []): void { - throw new RuntimeException(sprintf( - 'Class "%s" does not support method "%s".', - __CLASS__, - __METHOD__ - )); + throw new RuntimeException(\sprintf('Class "%s" does not support method "%s".', self::class, __METHOD__)); } /** * @param AvatarFactory $avatarFactory - * @return self */ - public function setAvatarFactory($avatarFactory) + public function setAvatarFactory($avatarFactory): static { $this->avatarFactory = $avatarFactory; diff --git a/lib/Tmdb/Factory/AuthenticationFactory.php b/lib/Tmdb/Factory/AuthenticationFactory.php index fef26d0e..91a8d539 100644 --- a/lib/Tmdb/Factory/AuthenticationFactory.php +++ b/lib/Tmdb/Factory/AuthenticationFactory.php @@ -1,14 +1,16 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ @@ -23,60 +25,44 @@ use Tmdb\Token\Session\SessionToken; /** - * Class AuthenticationFactory - * @package Tmdb\Factory + * Class AuthenticationFactory. */ class AuthenticationFactory extends AbstractFactory { /** - * @param array $data - * - * @return AbstractModel * @throws RuntimeException */ - public function create(array $data = []) + #[\Override] + public function create(array $data = []): never { - throw new RuntimeException(sprintf( - 'Class "%s" does not support method "%s".', - __CLASS__, - __METHOD__ - )); + throw new RuntimeException(\sprintf('Class "%s" does not support method "%s".', self::class, __METHOD__)); } /** - * @param array $data - * - * @return GenericCollection * @throws RuntimeException */ - public function createCollection(array $data = []) + #[\Override] + public function createCollection(array $data = []): never { - throw new RuntimeException(sprintf( - 'Class "%s" does not support method "%s".', - __CLASS__, - __METHOD__ - )); + throw new RuntimeException(\sprintf('Class "%s" does not support method "%s".', self::class, __METHOD__)); } /** - * Create request token - * - * @param array $data - * @return RequestToken + * Create request token. */ - public function createRequestToken(array $data = []) + public function createRequestToken(array $data = []): \Tmdb\Token\Session\RequestToken { $token = new RequestToken(); - if (array_key_exists('expires_at', $data)) { + if (\array_key_exists('expires_at', $data)) { $token->setExpiresAt(new DateTime($data['expires_at'])); } - if (array_key_exists('request_token', $data)) { + if (\array_key_exists('request_token', $data)) { $token->setToken($data['request_token']); } - if (array_key_exists('success', $data)) { + if (\array_key_exists('success', $data)) { $token->setSuccess($data['success']); } @@ -84,20 +70,17 @@ public function createRequestToken(array $data = []) } /** - * Create session token for user - * - * @param array $data - * @return SessionToken + * Create session token for user. */ - public function createSessionToken(array $data = []) + public function createSessionToken(array $data = []): \Tmdb\Token\Session\SessionToken { $token = new SessionToken(); - if (array_key_exists('session_id', $data)) { + if (\array_key_exists('session_id', $data)) { $token->setToken($data['session_id']); } - if (array_key_exists('success', $data)) { + if (\array_key_exists('success', $data)) { $token->setSuccess($data['success']); } @@ -105,24 +88,21 @@ public function createSessionToken(array $data = []) } /** - * Create session token for guest - * - * @param array $data - * @return GuestSessionToken + * Create session token for guest. */ - public function createGuestSessionToken(array $data = []) + public function createGuestSessionToken(array $data = []): \Tmdb\Token\Session\GuestSessionToken { $token = new GuestSessionToken(); - if (array_key_exists('expires_at', $data)) { + if (\array_key_exists('expires_at', $data)) { $token->setExpiresAt(new DateTime($data['expires_at'])); } - if (array_key_exists('guest_session_id', $data)) { + if (\array_key_exists('guest_session_id', $data)) { $token->setToken($data['guest_session_id']); } - if (array_key_exists('success', $data)) { + if (\array_key_exists('success', $data)) { $token->setSuccess($data['success']); } diff --git a/lib/Tmdb/Factory/CertificationFactory.php b/lib/Tmdb/Factory/CertificationFactory.php index a27234ef..30852c37 100644 --- a/lib/Tmdb/Factory/CertificationFactory.php +++ b/lib/Tmdb/Factory/CertificationFactory.php @@ -1,14 +1,16 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ @@ -18,17 +20,14 @@ use Tmdb\Model\Common\GenericCollection; /** - * Class CertificationFactory - * @package Tmdb\Factory + * Class CertificationFactory. */ class CertificationFactory extends AbstractFactory { - /** - * {@inheritdoc} - */ + #[\Override] public function createCollection(array $data = []): GenericCollection { - if (array_key_exists('certifications', $data)) { + if (\array_key_exists('certifications', $data)) { $data = $data['certifications']; } @@ -50,11 +49,7 @@ public function createCollection(array $data = []): GenericCollection return $collection; } - /** - * @param array $data - * - * @return Certification\CountryCertification - */ + #[\Override] 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 71064d2a..d1b585e9 100644 --- a/lib/Tmdb/Factory/ChangesFactory.php +++ b/lib/Tmdb/Factory/ChangesFactory.php @@ -1,14 +1,16 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ @@ -18,31 +20,28 @@ use Tmdb\Model\Collection\Changes; /** - * Class ChangesFactory - * @package Tmdb\Factory + * Class ChangesFactory. */ class ChangesFactory extends AbstractFactory { - /** - * {@inheritdoc} - */ + #[\Override] public function createCollection(array $data = []): Changes { $collection = new Changes(); - if (array_key_exists('page', $data)) { + if (\array_key_exists('page', $data)) { $collection->setPage($data['page']); } - if (array_key_exists('total_pages', $data)) { + if (\array_key_exists('total_pages', $data)) { $collection->setTotalPages($data['total_pages']); } - if (array_key_exists('total_results', $data)) { + if (\array_key_exists('total_results', $data)) { $collection->setTotalResults($data['total_results']); } - if (array_key_exists('results', $data)) { + if (\array_key_exists('results', $data)) { $data = $data['results']; } @@ -53,10 +52,7 @@ public function createCollection(array $data = []): Changes return $collection; } - /** - * {@inheritdoc} - * @return Change - */ + #[\Override] 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 d870e3eb..a2de7fc1 100644 --- a/lib/Tmdb/Factory/CollectionFactory.php +++ b/lib/Tmdb/Factory/CollectionFactory.php @@ -1,14 +1,16 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ @@ -16,29 +18,26 @@ use Tmdb\HttpClient\HttpClient; use Tmdb\Model\Collection; -use Tmdb\Model\Common\Translation; use Tmdb\Model\Common\GenericCollection; +use Tmdb\Model\Common\Translation; /** - * Class CollectionFactory - * @package Tmdb\Factory + * Class CollectionFactory. */ class CollectionFactory extends AbstractFactory { /** - * @var MovieFactory + * @var ImageFactory|mixed */ - private $movieFactory; + private $imageFactory; /** - * @var ImageFactory + * @var MovieFactory|mixed */ - private $imageFactory; + private $movieFactory; /** - * Constructor - * - * @param HttpClient $httpClient + * Constructor. */ public function __construct(HttpClient $httpClient) { @@ -48,9 +47,7 @@ public function __construct(HttpClient $httpClient) parent::__construct($httpClient); } - /** - * {@inheritdoc} - */ + #[\Override] public function createCollection(array $data = []): GenericCollection { $collection = new GenericCollection(); @@ -62,48 +59,45 @@ public function createCollection(array $data = []): GenericCollection return $collection; } - /** - * {@inheritdoc} - * @return Collection - */ + #[\Override] public function create(array $data = []): Collection { $collection = new Collection(); - if (array_key_exists('parts', $data)) { + if (\array_key_exists('parts', $data)) { $collection->setParts( - $this->getMovieFactory()->createCollection($data['parts']) + $this->getMovieFactory()->createCollection($data['parts']), ); } - if (array_key_exists('backdrop_path', $data)) { + if (\array_key_exists('backdrop_path', $data)) { $collection->setBackdropImage( - $this->getImageFactory()->createFromPath($data['backdrop_path'], 'backdrop_path') + $this->getImageFactory()->createFromPath($data['backdrop_path'], 'backdrop_path'), ); } - if (array_key_exists('images', $data)) { + if (\array_key_exists('images', $data)) { $collection->setImages( - $this->getImageFactory()->createCollectionFromMovie($data['images']) + $this->getImageFactory()->createCollectionFromMovie($data['images']), ); } - if (array_key_exists('poster_path', $data)) { + if (\array_key_exists('poster_path', $data)) { $collection->setPosterImage( - $this->getImageFactory()->createFromPath($data['poster_path'], 'poster_path') + $this->getImageFactory()->createFromPath($data['poster_path'], 'poster_path'), ); } - /** Translations */ - if (array_key_exists('translations', $data) && null !== $data['translations']) { - if (array_key_exists('translations', $data['translations'])) { + /* Translations */ + if (\array_key_exists('translations', $data) && null !== $data['translations']) { + if (\array_key_exists('translations', $data['translations'])) { $translations = $data['translations']['translations']; } else { $translations = $data['translations']; } $collection->setTranslations( - $this->createGenericCollection($translations, new Translation()) + $this->createGenericCollection($translations, new Translation()), ); } @@ -120,9 +114,8 @@ public function getMovieFactory() /** * @param MovieFactory $movieFactory - * @return self */ - public function setMovieFactory($movieFactory) + public function setMovieFactory($movieFactory): static { $this->movieFactory = $movieFactory; @@ -139,9 +132,8 @@ public function getImageFactory() /** * @param ImageFactory $imageFactory - * @return self */ - public function setImageFactory($imageFactory) + public function setImageFactory($imageFactory): static { $this->imageFactory = $imageFactory; diff --git a/lib/Tmdb/Factory/Common/ChangeFactory.php b/lib/Tmdb/Factory/Common/ChangeFactory.php index c06645b7..aa85a127 100644 --- a/lib/Tmdb/Factory/Common/ChangeFactory.php +++ b/lib/Tmdb/Factory/Common/ChangeFactory.php @@ -1,39 +1,37 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ namespace Tmdb\Factory\Common; use Tmdb\Factory\AbstractFactory; -use Tmdb\Model\AbstractModel; use Tmdb\Model\Collection\Changes; use Tmdb\Model\Common\Change; use Tmdb\Model\Common\GenericCollection; /** - * Class ChangeFactory - * @package Tmdb\Factory\Common + * Class ChangeFactory. */ class ChangeFactory extends AbstractFactory { - /** - * {@inheritdoc} - */ + #[\Override] public function createCollection(array $data = []): Changes { $collection = new Changes(); - if (array_key_exists('changes', $data)) { + if (\array_key_exists('changes', $data)) { $data = $data['changes']; } @@ -44,14 +42,12 @@ public function createCollection(array $data = []): Changes return $collection; } - /** - * {@inheritdoc} - */ + #[\Override] public function create(array $data = []): Change { $change = new Change(); - if (array_key_exists('items', $data)) { + if (\array_key_exists('items', $data)) { $items = new GenericCollection(); foreach ($data['items'] as $item) { @@ -67,10 +63,7 @@ public function create(array $data = []): Change } /** - * Create individual change items - * - * @param array $data - * @return Change\Item + * Create individual change items. */ private function createChangeItem(array $data = []): Change\Item { diff --git a/lib/Tmdb/Factory/Common/VideoFactory.php b/lib/Tmdb/Factory/Common/VideoFactory.php index 887a114a..968640e7 100644 --- a/lib/Tmdb/Factory/Common/VideoFactory.php +++ b/lib/Tmdb/Factory/Common/VideoFactory.php @@ -1,43 +1,42 @@ * @copyright (c) 2013, Michael Roterman + * * @version 4.0.0 */ namespace Tmdb\Factory\Common; use Tmdb\Factory\AbstractFactory; -use Tmdb\Model\AbstractModel; use Tmdb\Model\Collection\Videos; use Tmdb\Model\Common\Video; /** - * Class VideoFactory + * Class VideoFactory. + * * @extends AbstractFactory