From 8b3059d926aed6b8995015b36fc7e01da261904a Mon Sep 17 00:00:00 2001 From: Michael Roterman Date: Fri, 11 Jul 2014 00:04:15 +0200 Subject: [PATCH 01/19] Adding multi-search --- examples/search/api/multi.php | 21 ++++++ examples/search/model/multi.php | 26 +++++++ lib/Tmdb/Api/Search.php | 18 +++++ lib/Tmdb/Model/Search/SearchQuery.php | 8 +++ lib/Tmdb/Repository/SearchRepository.php | 68 +++++++++++++++++++ test/Tmdb/Tests/Api/SearchTest.php | 13 ++++ .../Tests/Repository/SearchRepositoryTest.php | 13 ++++ 7 files changed, 167 insertions(+) create mode 100644 examples/search/api/multi.php create mode 100644 examples/search/model/multi.php diff --git a/examples/search/api/multi.php b/examples/search/api/multi.php new file mode 100644 index 00000000..60b0b40c --- /dev/null +++ b/examples/search/api/multi.php @@ -0,0 +1,21 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +require_once '../../../vendor/autoload.php'; +require_once '../../../apikey.php'; + +$token = new \Tmdb\ApiToken(TMDB_API_KEY); +$client = new \Tmdb\Client($token); + +$result = $client->getSearchApi()->searchMulti('jack'); + +var_dump($result); diff --git a/examples/search/model/multi.php b/examples/search/model/multi.php new file mode 100644 index 00000000..9d7e7099 --- /dev/null +++ b/examples/search/model/multi.php @@ -0,0 +1,26 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +require_once '../../../vendor/autoload.php'; +require_once '../../../apikey.php'; + +$token = new \Tmdb\ApiToken(TMDB_API_KEY); +$client = new \Tmdb\Client($token); + +$query = new \Tmdb\Model\Search\SearchQuery\KeywordSearchQuery(); +$query->page(1); + +$repository = new \Tmdb\Repository\SearchRepository($client); + +$find = $repository->searchMulti('jack', $query); + +var_dump($find); diff --git a/lib/Tmdb/Api/Search.php b/lib/Tmdb/Api/Search.php index 8e5f1f1b..2c49f8e2 100644 --- a/lib/Tmdb/Api/Search.php +++ b/lib/Tmdb/Api/Search.php @@ -123,4 +123,22 @@ public function searchKeyword($query, array $parameters = array(), array $header 'query' => urlencode($query) ), $headers)); } + + /** + * Search the movie, tv show and person collections with a single query. + * + * Each item returned in the result array has a media_type field that maps to either movie, tv or person. + * Each mapped result is the same response you would get from each independent search. + * + * @param $query + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function searchMulti($query, array $parameters = array(), array $headers = array()) + { + return $this->get('search/multi', array_merge($parameters, array( + 'query' => urlencode($query) + ), $headers)); + } } diff --git a/lib/Tmdb/Model/Search/SearchQuery.php b/lib/Tmdb/Model/Search/SearchQuery.php index 1dcb94ce..732e44fa 100644 --- a/lib/Tmdb/Model/Search/SearchQuery.php +++ b/lib/Tmdb/Model/Search/SearchQuery.php @@ -20,6 +20,14 @@ */ class SearchQuery extends QueryParametersCollection { + /** + * Constructor + */ + public function __construct() + { + $this->page(1); + } + /** * CGI escaped string * diff --git a/lib/Tmdb/Repository/SearchRepository.php b/lib/Tmdb/Repository/SearchRepository.php index 3f7d71cd..3386587b 100644 --- a/lib/Tmdb/Repository/SearchRepository.php +++ b/lib/Tmdb/Repository/SearchRepository.php @@ -12,6 +12,7 @@ */ namespace Tmdb\Repository; +use Guzzle\Common\Exception\RuntimeException; use Tmdb\Client; use Tmdb\Exception\NotImplementedException; use Tmdb\Factory\CollectionFactory; @@ -190,6 +191,73 @@ public function searchKeyword($query, KeywordSearchQuery $parameters, array $hea return $this->getKeywordFactory()->createResultCollection($data); } + /** + * @param string $query + * @param KeywordSearchQuery $parameters + * @param array $headers + * + * @return ResultCollection|Keyword[] + */ + public function searchMulti($query, KeywordSearchQuery $parameters, array $headers = array()) + { + $data = $this->getApi()->searchMulti($query, $this->getParameters($parameters), $headers); + $collection = new ResultCollection(); + + if (null === $data) { + return $collection; + } + + if (array_key_exists('page', $data)) { + $collection->setPage($data['page']); + } + + if (array_key_exists('total_pages', $data)) { + $collection->setTotalPages($data['total_pages']); + } + + if (array_key_exists('total_results', $data)) { + $collection->setTotalResults($data['total_results']); + } + + if (array_key_exists('results', $data)) { + foreach ($data['results'] as $item) { + if ($item) { + $collection->add(null, $this->processSearchMultiItem($item)); + } + } + } + + return $collection; + } + + /** + * Process multi search items + * + * @param array $item + * @return bool|Movie|Person|Person\CastMember|Person\CrewMember|Tv + * @throws \RuntimeException + */ + private function processSearchMultiItem(array $item) + { + if (array_key_exists('media_type', $item)) { + switch ($item['media_type']) { + case 'movie': + return $this->getMovieFactory()->create($item); + case 'tv': + return $this->getTvFactory()->create($item); + case 'person': + return $this->getPeopleFactory()->create($item); + default: + throw new \RuntimeException(sprintf( + 'Could not process media_type "%s" in multi search, type unknown.', + $item['media_type'] + )); + } + } + + return false; + } + /** * Convert parameters back to an array * diff --git a/test/Tmdb/Tests/Api/SearchTest.php b/test/Tmdb/Tests/Api/SearchTest.php index 278a4a3f..cf6f8cce 100644 --- a/test/Tmdb/Tests/Api/SearchTest.php +++ b/test/Tmdb/Tests/Api/SearchTest.php @@ -113,6 +113,19 @@ public function shouldSearchKeyword() $api->searchKeyword(self::QUERY_KEYWORD); } + /** + * @test + */ + public function shouldSearchMulti() + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('search/multi', array('query' => urlencode(self::QUERY_KEYWORD))); + + $api->searchMulti(self::QUERY_KEYWORD); + } + protected function getApiClass() { return 'Tmdb\Api\Search'; diff --git a/test/Tmdb/Tests/Repository/SearchRepositoryTest.php b/test/Tmdb/Tests/Repository/SearchRepositoryTest.php index 4bf137f3..31b9f3d5 100644 --- a/test/Tmdb/Tests/Repository/SearchRepositoryTest.php +++ b/test/Tmdb/Tests/Repository/SearchRepositoryTest.php @@ -114,6 +114,19 @@ public function shouldSearchKeyword() $repository->searchKeyword('alien', new KeywordSearchQuery()); } + /** + * @test + */ + public function shouldSearchMulti() + { + /** + * @var SearchRepository $repository + */ + $repository = $this->getRepositoryWithMockedHttpClient(); + + $repository->searchKeyword('jack', new KeywordSearchQuery()); + } + /** * @test * @expectedException Tmdb\Exception\NotImplementedException From bd50b349bea83c510f42360eeb08949abe955a08 Mon Sep 17 00:00:00 2001 From: Michael Roterman Date: Thu, 10 Jul 2014 23:25:19 +0200 Subject: [PATCH 02/19] Initial setup, still some issues rose up concerning the differentiation of the thumbnail classes --- lib/Tmdb/Api/People.php | 2 - lib/Tmdb/Factory/ImageFactory.php | 45 ++++++++++++ lib/Tmdb/Model/Media/Image.php | 94 ++++++++++++++++++++++++ lib/Tmdb/Repository/PeopleRepository.php | 2 +- 4 files changed, 140 insertions(+), 3 deletions(-) create mode 100644 lib/Tmdb/Model/Media/Image.php diff --git a/lib/Tmdb/Api/People.php b/lib/Tmdb/Api/People.php index b9457cee..513a92bb 100644 --- a/lib/Tmdb/Api/People.php +++ b/lib/Tmdb/Api/People.php @@ -144,8 +144,6 @@ public function getExternalIds($person_id, array $parameters = array(), array $h * @param array $parameters * @param array $headers * @return mixed - * - * @todo Still does not contain the media and media_type properties, this will be worked on later on. */ public function getTaggedImages($person_id, array $parameters = array(), array $headers = array()) { diff --git a/lib/Tmdb/Factory/ImageFactory.php b/lib/Tmdb/Factory/ImageFactory.php index 3d38d7fc..0f1e5b55 100644 --- a/lib/Tmdb/Factory/ImageFactory.php +++ b/lib/Tmdb/Factory/ImageFactory.php @@ -12,6 +12,7 @@ */ namespace Tmdb\Factory; +use Tmdb\Exception\RuntimeException; use Tmdb\Model\Collection\Images; use Tmdb\Model\Image; @@ -52,6 +53,50 @@ public function createFromPath($path, $key) ); } + /** + * Create an Media/Image type which is used in calls like person/tagged_images, which contains an getMedia() + * reference either referring to movies / tv shows etc. + * + * @param array $data + * @param string|null $key + * @return Image + */ + public function createMediaImage(array $data = array(), $key = null) + { + $type = self::resolveImageType($key); + $image = $this->hydrate($type, $data); + $media = null; + + if (array_key_exists('media', $data) && array_key_exists('media_type', $data)) { + $factory = null; + + switch ($data['media_type']) { + case "movie": + $factory = new MovieFactory(); + break; + + case "tv": + $factory = new TvFactory(); + break; + + default: + throw new RuntimeException(sprintf( + 'Unrecognized media_type "%s" for method "%s".', + $data['media_type'], + __METHOD__ + )); + } + + $media = $factory->create($data['media']); + } + + if ($media) { + $image->setMedia(); + } + + return $this->hydrate($type, $data); + } + /** * Helper function to obtain a new object for an image type * diff --git a/lib/Tmdb/Model/Media/Image.php b/lib/Tmdb/Model/Media/Image.php new file mode 100644 index 00000000..0265ca08 --- /dev/null +++ b/lib/Tmdb/Model/Media/Image.php @@ -0,0 +1,94 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Media; + +/** + * Class Image + * @package Tmdb\Model + */ +class Image extends \Tmdb\Model\Image +{ + private $imageType; + private $media; + private $mediaType; + + public static $properties = array( + 'image_type', + 'media_type', + 'file_path', + 'width', + 'height', + 'iso_639_1', + 'aspect_ratio', + 'vote_average', + 'vote_count' + ); + + /** + * @param mixed $imageType + * @return $this + */ + public function setImageType($imageType) + { + $this->imageType = $imageType; + + return $this; + } + + /** + * @return mixed + */ + public function getImageType() + { + return $this->imageType; + } + + /** + * @param mixed $media + * @return $this + */ + public function setMedia($media) + { + $this->media = $media; + + return $this; + } + + /** + * @return mixed + */ + public function getMedia() + { + return $this->media; + } + + /** + * @param mixed $mediaType + * @return $this + */ + public function setMediaType($mediaType) + { + $this->mediaType = $mediaType; + + return $this; + } + + /** + * @return mixed + */ + public function getMediaType() + { + return $this->mediaType; + } + +} diff --git a/lib/Tmdb/Repository/PeopleRepository.php b/lib/Tmdb/Repository/PeopleRepository.php index 15b24dfa..9e20d882 100644 --- a/lib/Tmdb/Repository/PeopleRepository.php +++ b/lib/Tmdb/Repository/PeopleRepository.php @@ -180,7 +180,7 @@ public function getChanges($id, array $parameters = array(), array $headers = ar public function getTaggedImages($id, array $parameters = array(), array $headers = array()) { $data = $this->getApi()->getTaggedImages($id, $this->parseQueryParameters($parameters), $headers); - $person = $this->getFactory()->create(array('tagged_images' => $data)); + $person = $this->getFactory()->create(array('tagged_images' => $data), 'createMediaImage'); return $person->getTaggedImages(); } From 3d5047d6e63d182eb7a76d64047c5bd6df971a35 Mon Sep 17 00:00:00 2001 From: Michael Roterman Date: Fri, 11 Jul 2014 02:07:49 +0200 Subject: [PATCH 03/19] Fixing tagged_images in the people model, now fully supports the media object contained. --- examples/people/model/tagged_images.php | 2 + lib/Tmdb/Factory/ImageFactory.php | 20 +++-- lib/Tmdb/Model/Image.php | 20 +++++ lib/Tmdb/Model/Media/Image.php | 94 ------------------------ lib/Tmdb/Repository/PeopleRepository.php | 8 +- 5 files changed, 42 insertions(+), 102 deletions(-) delete mode 100644 lib/Tmdb/Model/Media/Image.php diff --git a/examples/people/model/tagged_images.php b/examples/people/model/tagged_images.php index a92cfac5..fda56bc4 100644 --- a/examples/people/model/tagged_images.php +++ b/examples/people/model/tagged_images.php @@ -10,6 +10,8 @@ * @copyright (c) 2013, Michael Roterman * @version 0.0.1 */ +ini_set('display_errors', 'On'); + require_once '../../../vendor/autoload.php'; require_once '../../../apikey.php'; diff --git a/lib/Tmdb/Factory/ImageFactory.php b/lib/Tmdb/Factory/ImageFactory.php index 0f1e5b55..099f98a4 100644 --- a/lib/Tmdb/Factory/ImageFactory.php +++ b/lib/Tmdb/Factory/ImageFactory.php @@ -60,16 +60,20 @@ public function createFromPath($path, $key) * @param array $data * @param string|null $key * @return Image + * + * @throws \RuntimeException */ public function createMediaImage(array $data = array(), $key = null) { - $type = self::resolveImageType($key); + if (!array_key_exists('image_type', $data)) { + throw new \RuntimeException('Unable to detect the image type.'); + } + + $type = $this->resolveImageType($data['image_type']); $image = $this->hydrate($type, $data); $media = null; if (array_key_exists('media', $data) && array_key_exists('media_type', $data)) { - $factory = null; - switch ($data['media_type']) { case "movie": $factory = new MovieFactory(); @@ -79,10 +83,16 @@ public function createMediaImage(array $data = array(), $key = null) $factory = new TvFactory(); break; + // I don't think this ever occurs, but just in case.. + case "person": + $factory = new PeopleFactory(); + break; + default: throw new RuntimeException(sprintf( - 'Unrecognized media_type "%s" for method "%s".', + 'Unrecognized media_type "%s" for method "%s::%s".', $data['media_type'], + __CLASS__, __METHOD__ )); } @@ -91,7 +101,7 @@ public function createMediaImage(array $data = array(), $key = null) } if ($media) { - $image->setMedia(); + $image->setMedia($media); } return $this->hydrate($type, $data); diff --git a/lib/Tmdb/Model/Image.php b/lib/Tmdb/Model/Image.php index d0416080..5c1abd6f 100644 --- a/lib/Tmdb/Model/Image.php +++ b/lib/Tmdb/Model/Image.php @@ -34,6 +34,7 @@ class Image extends AbstractModel implements ImageFilter, LanguageFilter private $aspectRatio; private $voteAverage; private $voteCount; + private $media; protected $id; protected $type; @@ -202,6 +203,25 @@ public function getWidth() return $this->width; } + /** + * @param mixed $media + * @return $this + */ + public function setMedia($media) + { + $this->media = $media; + + return $this; + } + + /** + * @return mixed + */ + public function getMedia() + { + return $this->media; + } + /** * Return the file path when casted to string * diff --git a/lib/Tmdb/Model/Media/Image.php b/lib/Tmdb/Model/Media/Image.php deleted file mode 100644 index 0265ca08..00000000 --- a/lib/Tmdb/Model/Media/Image.php +++ /dev/null @@ -1,94 +0,0 @@ - - * @copyright (c) 2013, Michael Roterman - * @version 0.0.1 - */ -namespace Tmdb\Model\Media; - -/** - * Class Image - * @package Tmdb\Model - */ -class Image extends \Tmdb\Model\Image -{ - private $imageType; - private $media; - private $mediaType; - - public static $properties = array( - 'image_type', - 'media_type', - 'file_path', - 'width', - 'height', - 'iso_639_1', - 'aspect_ratio', - 'vote_average', - 'vote_count' - ); - - /** - * @param mixed $imageType - * @return $this - */ - public function setImageType($imageType) - { - $this->imageType = $imageType; - - return $this; - } - - /** - * @return mixed - */ - public function getImageType() - { - return $this->imageType; - } - - /** - * @param mixed $media - * @return $this - */ - public function setMedia($media) - { - $this->media = $media; - - return $this; - } - - /** - * @return mixed - */ - public function getMedia() - { - return $this->media; - } - - /** - * @param mixed $mediaType - * @return $this - */ - public function setMediaType($mediaType) - { - $this->mediaType = $mediaType; - - return $this; - } - - /** - * @return mixed - */ - public function getMediaType() - { - return $this->mediaType; - } - -} diff --git a/lib/Tmdb/Repository/PeopleRepository.php b/lib/Tmdb/Repository/PeopleRepository.php index 9e20d882..fec61ee3 100644 --- a/lib/Tmdb/Repository/PeopleRepository.php +++ b/lib/Tmdb/Repository/PeopleRepository.php @@ -12,6 +12,7 @@ */ namespace Tmdb\Repository; +use Tmdb\Factory\ImageFactory; use Tmdb\Factory\PeopleFactory; use Tmdb\Model\Person; use Tmdb\Model\Person\QueryParameter\AppendToResponse; @@ -179,10 +180,11 @@ public function getChanges($id, array $parameters = array(), array $headers = ar */ public function getTaggedImages($id, array $parameters = array(), array $headers = array()) { - $data = $this->getApi()->getTaggedImages($id, $this->parseQueryParameters($parameters), $headers); - $person = $this->getFactory()->create(array('tagged_images' => $data), 'createMediaImage'); + $data = $this->getApi()->getTaggedImages($id, $this->parseQueryParameters($parameters), $headers); - return $person->getTaggedImages(); + $factory = new ImageFactory(); + + return $factory->createResultCollection($data, 'createMediaImage', 'tagged_images'); } /** From 847656188c2192cf627a68cf17c17545c021b7c1 Mon Sep 17 00:00:00 2001 From: "Johannes Hammersen, x75" Date: Fri, 11 Jul 2014 13:02:54 +0200 Subject: [PATCH 04/19] Added Tv changes --- lib/Tmdb/Api/Changes.php | 20 +++++++++++++++++ lib/Tmdb/Repository/ChangesRepository.php | 22 +++++++++++++++++++ test/Tmdb/Tests/Api/ChangesTest.php | 13 +++++++++++ .../Repository/ChangesRepositoryTest.php | 12 ++++++++++ 4 files changed, 67 insertions(+) diff --git a/lib/Tmdb/Api/Changes.php b/lib/Tmdb/Api/Changes.php index 084d5926..f16dfc19 100644 --- a/lib/Tmdb/Api/Changes.php +++ b/lib/Tmdb/Api/Changes.php @@ -58,4 +58,24 @@ public function getPersonChanges(array $parameters = array(), array $headers = a { return $this->get('person/changes', $parameters, $headers); } + + /** + * Get a list of tv show ids that have been edited. + * + * By default we show the last 24 hours and only 100 items per page. + * The maximum number of days that can be returned in a single request is 14. + * + * You can then use the tv changes API to get the actual data that has been changed. + * + * 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(), array $headers = array()) + { + return $this->get('tv/changes', $parameters, $headers); + } } diff --git a/lib/Tmdb/Repository/ChangesRepository.php b/lib/Tmdb/Repository/ChangesRepository.php index d873ff4f..516d0480 100644 --- a/lib/Tmdb/Repository/ChangesRepository.php +++ b/lib/Tmdb/Repository/ChangesRepository.php @@ -65,6 +65,28 @@ public function getPeopleChanges(ChangesQuery $query, array $headers = array()) return $this->getFactory()->createResultCollection($data); } + /** + * Get a list of tv show ids that have been edited. + * + * By default we show the last 24 hours and only 100 items per page. + * The maximum number of days that can be returned in a single request is 14. + * + * You can then use the tv changes API to get the actual data that has been changed. + * + * 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 ChangesQuery $query + * @param array $headers + * @return \Tmdb\Model\Common\GenericCollection + */ + public function getTvChanges(ChangesQuery $query, array $headers = array()) + { + $data = $this->getApi()->getTvChanges($query->toArray(), $headers); + + return $this->getFactory()->createResultCollection($data); + } + /** * Return the related API class * diff --git a/test/Tmdb/Tests/Api/ChangesTest.php b/test/Tmdb/Tests/Api/ChangesTest.php index 7535bc2b..60db22f2 100644 --- a/test/Tmdb/Tests/Api/ChangesTest.php +++ b/test/Tmdb/Tests/Api/ChangesTest.php @@ -40,6 +40,19 @@ public function shouldGetPersonChanges() $api->getPersonChanges(); } + /** + * @test + */ + public function shouldGetTvChanges() + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('tv/changes'); + + $api->getTvChanges(); + } + protected function getApiClass() { return 'Tmdb\Api\Changes'; diff --git a/test/Tmdb/Tests/Repository/ChangesRepositoryTest.php b/test/Tmdb/Tests/Repository/ChangesRepositoryTest.php index 9dce2e27..bac50347 100644 --- a/test/Tmdb/Tests/Repository/ChangesRepositoryTest.php +++ b/test/Tmdb/Tests/Repository/ChangesRepositoryTest.php @@ -40,6 +40,18 @@ public function shouldGetPeopleChanges() $repository->getPeopleChanges($query); } + /** + * @test + */ + public function shouldGetTvChanges() + { + $repository = $this->getRepositoryWithMockedHttpClient(); + + $query = new ChangesQuery(); + + $repository->getTvChanges($query); + } + protected function getApiClass() { return 'Tmdb\Api\Changes'; From cf57e5e41b32e4df1c2cc97bbcf53bb4eb86e283 Mon Sep 17 00:00:00 2001 From: Michael Roterman Date: Fri, 11 Jul 2014 14:31:54 +0200 Subject: [PATCH 05/19] Adding examples for the tv-changes --- examples/changes/api/tv.php | 25 +++++++++++++++++++++++++ examples/changes/model/tv.php | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 examples/changes/api/tv.php create mode 100644 examples/changes/model/tv.php diff --git a/examples/changes/api/tv.php b/examples/changes/api/tv.php new file mode 100644 index 00000000..2b78da03 --- /dev/null +++ b/examples/changes/api/tv.php @@ -0,0 +1,25 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +require_once '../../../vendor/autoload.php'; +require_once '../../../apikey.php'; + +$token = new \Tmdb\ApiToken(TMDB_API_KEY); +$client = new \Tmdb\Client($token); + +$tvChanges = $client->getChangesApi()->getTvChanges(array( + 'page' => 1, + 'start_date' => '2014-01-14', + 'end_date' => '2014-01-21' +)); + +var_dump($tvChanges); diff --git a/examples/changes/model/tv.php b/examples/changes/model/tv.php new file mode 100644 index 00000000..095da352 --- /dev/null +++ b/examples/changes/model/tv.php @@ -0,0 +1,33 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +require_once '../../../vendor/autoload.php'; +require_once '../../../apikey.php'; + +$token = new \Tmdb\ApiToken(TMDB_API_KEY); +$client = new \Tmdb\Client($token); + +$query = new \Tmdb\Model\Query\ChangesQuery(); + +$from = new \DateTime('14-01-2014'); +$to = new \DateTime('21-01-2014'); + +$query + ->page(1) + ->from($from) + ->to($to) +; + +$repository = new \Tmdb\Repository\ChangesRepository($client); +$response = $repository->getTvChanges($query); + +var_dump($response); From 7c052d7af8509f32ce81210dc454f2d468d81d38 Mon Sep 17 00:00:00 2001 From: Michael Roterman Date: Sat, 12 Jul 2014 10:49:24 +0200 Subject: [PATCH 06/19] Remove deprecated trailers method --- .../Movie/QueryParameter/AppendToResponse.php | 3 +-- lib/Tmdb/Repository/MovieRepository.php | 20 ++----------------- 2 files changed, 3 insertions(+), 20 deletions(-) diff --git a/lib/Tmdb/Model/Movie/QueryParameter/AppendToResponse.php b/lib/Tmdb/Model/Movie/QueryParameter/AppendToResponse.php index baeeeab5..a459302a 100644 --- a/lib/Tmdb/Model/Movie/QueryParameter/AppendToResponse.php +++ b/lib/Tmdb/Model/Movie/QueryParameter/AppendToResponse.php @@ -25,9 +25,8 @@ final class AppendToResponse extends BaseAppendToResponse const IMAGES = 'images'; const KEYWORDS = 'keywords'; const RELEASES = 'releases'; - const TRAILERS = 'trailers'; const TRANSLATIONS = 'translations'; - const SIMILAR_MOVIES = 'similar'; + const SIMILAR = 'similar'; const REVIEWS = 'reviews'; const LISTS = 'lists'; const CHANGES = 'changes'; diff --git a/lib/Tmdb/Repository/MovieRepository.php b/lib/Tmdb/Repository/MovieRepository.php index 88e6da27..9dc0b488 100644 --- a/lib/Tmdb/Repository/MovieRepository.php +++ b/lib/Tmdb/Repository/MovieRepository.php @@ -69,9 +69,9 @@ public function load($id, array $parameters = array(), array $headers = array()) AppendToResponse::LISTS, AppendToResponse::RELEASES, AppendToResponse::REVIEWS, - AppendToResponse::SIMILAR_MOVIES, - AppendToResponse::TRAILERS, + AppendToResponse::SIMILAR, AppendToResponse::TRANSLATIONS, + AppendToResponse::VIDEOS, )) ); } @@ -161,22 +161,6 @@ public function getReleases($id, array $parameters = array(), array $headers = a return $movie->getReleases(); } - /** - * Get the trailers for a specific movie id. - * - * @param $id - * @param $parameters - * @param $headers - * @return null|\Tmdb\Model\AbstractModel - */ - public function getTrailers($id, array $parameters = array(), array $headers = array()) - { - $data = $this->getApi()->getTrailers($id, $this->parseQueryParameters($parameters), $headers); - $movie = $this->getFactory()->create(array('trailers' => $data)); - - return $movie->getTrailers(); - } - /** * Get the translations for a specific movie id. * From 8541e7900e843b9991a3d6fa31b134908102d286 Mon Sep 17 00:00:00 2001 From: Michael Roterman Date: Sat, 12 Jul 2014 10:49:39 +0200 Subject: [PATCH 07/19] Remove deprecated credits method. --- lib/Tmdb/Model/Person.php | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/lib/Tmdb/Model/Person.php b/lib/Tmdb/Model/Person.php index b1bbd9e4..c396cd36 100644 --- a/lib/Tmdb/Model/Person.php +++ b/lib/Tmdb/Model/Person.php @@ -79,12 +79,6 @@ class Person extends AbstractModel implements PersonInterface */ private $profileImage; - /** - * @var Collection\CreditsCollection - * @deprecated - */ - protected $credits; - /** * @var CreditsCollection\MovieCredits */ @@ -142,7 +136,6 @@ class Person extends AbstractModel implements PersonInterface */ public function __construct() { - $this->credits = new CreditsCollection(); $this->movieCredits = new CreditsCollection\MovieCredits(); $this->tvCredits = new CreditsCollection\TvCredits(); $this->combinedCredits = new CreditsCollection\CombinedCredits(); @@ -250,25 +243,6 @@ public function getChanges() return $this->changes; } - /** - * @param mixed $credits - * @return $this - */ - public function setCredits($credits) - { - $this->credits = $credits; - - return $this; - } - - /** - * @return mixed - */ - public function getCredits() - { - return $this->credits; - } - /** * @param mixed $deathday * @return $this From 2c4260c6eff8bacb4096ca2a7bca7e893b30e604 Mon Sep 17 00:00:00 2001 From: Michael Roterman Date: Sat, 12 Jul 2014 12:49:00 +0200 Subject: [PATCH 08/19] Cleaning up, fixing documentation and some internal issues. --- lib/Tmdb/Api/AbstractApi.php | 8 +- lib/Tmdb/Api/Movies.php | 4 - lib/Tmdb/Factory/AbstractFactory.php | 25 ++++++ lib/Tmdb/Factory/AccountFactory.php | 7 +- lib/Tmdb/Factory/AuthenticationFactory.php | 17 ++-- lib/Tmdb/Factory/Common/VideoFactory.php | 2 +- lib/Tmdb/Factory/CreditsFactory.php | 9 +- lib/Tmdb/Factory/FindFactory.php | 7 +- lib/Tmdb/Factory/ImageFactory.php | 2 - lib/Tmdb/Factory/MovieFactory.php | 9 -- lib/Tmdb/Factory/PeopleFactory.php | 13 +-- lib/Tmdb/HttpClient/HttpClient.php | 6 +- .../HttpClient/Plugin/SessionTokenPlugin.php | 2 +- .../Model/Collection/CreditsCollection.php | 9 +- lib/Tmdb/Model/Movie.php | 83 +++++++------------ lib/Tmdb/Model/Network.php | 2 +- lib/Tmdb/Model/Person.php | 20 ++--- lib/Tmdb/Model/Person/AbstractMember.php | 4 +- lib/Tmdb/Model/Person/CastMember.php | 2 +- lib/Tmdb/Model/Person/CrewMember.php | 4 +- lib/Tmdb/Model/Timezone/CountryTimezone.php | 3 +- lib/Tmdb/Model/Tv.php | 14 ++-- lib/Tmdb/Model/Tv/Episode.php | 2 +- lib/Tmdb/Model/Tv/Season.php | 6 +- lib/Tmdb/Repository/MovieRepository.php | 6 +- lib/Tmdb/Repository/PeopleRepository.php | 2 +- lib/Tmdb/SessionToken.php | 4 +- .../Factory/AuthenticationFactoryTest.php | 4 +- test/Tmdb/Tests/Factory/FindFactoryTest.php | 2 +- test/Tmdb/Tests/Factory/MovieFactoryTest.php | 2 +- test/Tmdb/Tests/Model/MovieTest.php | 1 - test/Tmdb/Tests/Model/PersonTest.php | 5 +- .../Tests/Repository/MovieRepositoryTest.php | 10 --- 33 files changed, 142 insertions(+), 154 deletions(-) diff --git a/lib/Tmdb/Api/AbstractApi.php b/lib/Tmdb/Api/AbstractApi.php index 4e75af21..51396204 100644 --- a/lib/Tmdb/Api/AbstractApi.php +++ b/lib/Tmdb/Api/AbstractApi.php @@ -96,10 +96,10 @@ public function post($path, $postBody = null, array $parameters = array(), $head /** * Send a POST request but json_encode the post body in the request * - * @param $path - * @param null $postBody - * @param array $parameters - * @param array $headers + * @param string $path + * @param array|null $postBody + * @param array $parameters + * @param array $headers * @return mixed */ public function postJson($path, $postBody = null, array $parameters = array(), $headers = array()) diff --git a/lib/Tmdb/Api/Movies.php b/lib/Tmdb/Api/Movies.php index 35998601..400d98e1 100644 --- a/lib/Tmdb/Api/Movies.php +++ b/lib/Tmdb/Api/Movies.php @@ -260,8 +260,6 @@ public function getTopRated(array $parameters = array(), array $headers = array( * or added to their favourite or watch lists. * * A valid session id is required. - * - * @throws \Tmdb\Exception\NotImplementedException */ public function getAccountStates($id) { @@ -272,8 +270,6 @@ public function getAccountStates($id) * TThis method lets users rate a movie. * * A valid session id or guest session id is required. - * - * @throws \Tmdb\Exception\NotImplementedException */ public function rateMovie($id, $rating) { diff --git a/lib/Tmdb/Factory/AbstractFactory.php b/lib/Tmdb/Factory/AbstractFactory.php index 169c4c73..ccb62a4b 100644 --- a/lib/Tmdb/Factory/AbstractFactory.php +++ b/lib/Tmdb/Factory/AbstractFactory.php @@ -103,6 +103,31 @@ public function createResultCollection($data = array(), $method = 'create') return $collection; } + /** + * Create a generic collection of data and map it on the class by it's static parameter $properties + * + * @param array $data + * @param AbstractModel $class + * @param GenericCollection $collection + * @return GenericCollection + */ + protected function createCustomCollection($data = array(), $class, $collection) + { + if (is_object($class)) { + $class = get_class($class); + } + + if (null === $data) { + return $collection; + } + + foreach ($data as $item) { + $collection->add(null, $this->hydrate(new $class(), $item)); + } + + return $collection; + } + /** * Hydrate the object with data * diff --git a/lib/Tmdb/Factory/AccountFactory.php b/lib/Tmdb/Factory/AccountFactory.php index 074e4f12..3b9107cd 100644 --- a/lib/Tmdb/Factory/AccountFactory.php +++ b/lib/Tmdb/Factory/AccountFactory.php @@ -12,7 +12,6 @@ */ namespace Tmdb\Factory; -use Tmdb\Exception\NotImplementedException; use Tmdb\Model\Account; use Tmdb\Model\Lists\Result; @@ -108,7 +107,11 @@ public function createListItem(array $data = array()) */ public function createCollection(array $data = array()) { - throw new NotImplementedException('Not implemented'); + throw new \RuntimeException(sprintf( + 'Class "%s" does not support method "%s".', + __CLASS__, + __METHOD__ + )); } /** diff --git a/lib/Tmdb/Factory/AuthenticationFactory.php b/lib/Tmdb/Factory/AuthenticationFactory.php index f14f7ba0..81eefacd 100644 --- a/lib/Tmdb/Factory/AuthenticationFactory.php +++ b/lib/Tmdb/Factory/AuthenticationFactory.php @@ -12,7 +12,6 @@ */ namespace Tmdb\Factory; -use Tmdb\Exception\NotImplementedException; use Tmdb\GuestSessionToken; use Tmdb\RequestToken; use Tmdb\SessionToken; @@ -26,23 +25,31 @@ class AuthenticationFactory extends AbstractFactory /** * @param array $data * - * @throws NotImplementedException + * @throws \RuntimeException * @return void */ public function create(array $data = array()) { - throw new NotImplementedException(); + throw new \RuntimeException(sprintf( + 'Class "%s" does not support method "%s".', + __CLASS__, + __METHOD__ + )); } /** * @param array $data * - * @throws NotImplementedException + * @throws \RuntimeException * @return void */ public function createCollection(array $data = array()) { - throw new NotImplementedException(); + throw new \RuntimeException(sprintf( + 'Class "%s" does not support method "%s".', + __CLASS__, + __METHOD__ + )); } /** diff --git a/lib/Tmdb/Factory/Common/VideoFactory.php b/lib/Tmdb/Factory/Common/VideoFactory.php index 521dccaa..24098372 100644 --- a/lib/Tmdb/Factory/Common/VideoFactory.php +++ b/lib/Tmdb/Factory/Common/VideoFactory.php @@ -29,7 +29,7 @@ public function create(array $data = array()) { $videoType = $this->resolveVideoType($data); - return $this->hydrate($videoType, $data); + return (null === $videoType) ? null : $this->hydrate($videoType, $data); } /** diff --git a/lib/Tmdb/Factory/CreditsFactory.php b/lib/Tmdb/Factory/CreditsFactory.php index ac6c129d..0b08bb57 100644 --- a/lib/Tmdb/Factory/CreditsFactory.php +++ b/lib/Tmdb/Factory/CreditsFactory.php @@ -15,6 +15,7 @@ use Tmdb\Exception\NotImplementedException; use Tmdb\Model\Genre; use Tmdb\Model\Credits as Credits; +use Tmdb\Model\Person; /** * Class CreditsFactory @@ -71,9 +72,11 @@ public function create(array $data = array()) } if (array_key_exists('person', $data)) { - $credits->setPerson( - $this->getPeopleFactory()->create($data['person']) - ); + $person = $this->getPeopleFactory()->create($data['person']); + + if ($person instanceof Person) { + $credits->setPerson($person); + } } return $this->hydrate($credits, $data); diff --git a/lib/Tmdb/Factory/FindFactory.php b/lib/Tmdb/Factory/FindFactory.php index dd6fb3d9..59e37e82 100644 --- a/lib/Tmdb/Factory/FindFactory.php +++ b/lib/Tmdb/Factory/FindFactory.php @@ -12,7 +12,6 @@ */ namespace Tmdb\Factory; -use Tmdb\Exception\NotImplementedException; use Tmdb\Model\Find; /** @@ -73,7 +72,11 @@ public function create(array $data = array()) */ public function createCollection(array $data = array()) { - throw new NotImplementedException(sprintf('Method "%s" is not implemented.', __METHOD__)); + throw new \RuntimeException(sprintf( + 'Class "%s" does not support method "%s".', + __CLASS__, + __METHOD__ + )); } /** diff --git a/lib/Tmdb/Factory/ImageFactory.php b/lib/Tmdb/Factory/ImageFactory.php index 099f98a4..0c64e61f 100644 --- a/lib/Tmdb/Factory/ImageFactory.php +++ b/lib/Tmdb/Factory/ImageFactory.php @@ -98,9 +98,7 @@ public function createMediaImage(array $data = array(), $key = null) } $media = $factory->create($data['media']); - } - if ($media) { $image->setMedia($media); } diff --git a/lib/Tmdb/Factory/MovieFactory.php b/lib/Tmdb/Factory/MovieFactory.php index 520a3bec..44e87388 100644 --- a/lib/Tmdb/Factory/MovieFactory.php +++ b/lib/Tmdb/Factory/MovieFactory.php @@ -18,7 +18,6 @@ use Tmdb\Factory\People\CastFactory; use Tmdb\Factory\People\CrewFactory; use Tmdb\Model\Common\GenericCollection; -use Tmdb\Model\Common\Trailer\Youtube; use Tmdb\Model\Common\Translation; use Tmdb\Model\Lists\Result; use Tmdb\Model\Movie; @@ -145,14 +144,6 @@ public function create(array $data = array()) $movie->setReleases($this->createGenericCollection($data['releases']['countries'], new Movie\Release())); } - /** - * @TODO actually implement more providers? - * ( Can't seem to find any quicktime related trailers anyways? ). For now KISS - */ - if (array_key_exists('trailers', $data) && array_key_exists('youtube', $data['trailers'])) { - $movie->setTrailers($this->createGenericCollection($data['trailers']['youtube'], new Youtube())); - } - if (array_key_exists('videos', $data)) { $movie->setVideos($this->getVideoFactory()->createCollection($data['videos'])); } diff --git a/lib/Tmdb/Factory/PeopleFactory.php b/lib/Tmdb/Factory/PeopleFactory.php index f4db86bc..8a878e32 100644 --- a/lib/Tmdb/Factory/PeopleFactory.php +++ b/lib/Tmdb/Factory/PeopleFactory.php @@ -91,7 +91,8 @@ public function create(array $data = array(), $person = null) if (array_key_exists('tagged_images', $data)) { $person->setTaggedImages( $this->getImageFactory()->createResultCollection( - $data['tagged_images'] + $data['tagged_images'], + 'createMediaImage' ) ); } @@ -115,9 +116,10 @@ protected function applyCredits(array $data, Person $person) $method = $hydrator->camelize(sprintf('get_%s', $type)); if (array_key_exists('cast', $data[$type])) { - $cast = $this->createGenericCollection( + $cast = $this->createCustomCollection( $data[$type]['cast'], - new Person\MovieCredit() + new Person\MovieCredit(), + new People\Cast() ); foreach ($cast as $member) { @@ -128,9 +130,10 @@ protected function applyCredits(array $data, Person $person) } if (array_key_exists('crew', $data[$type])) { - $crew = $this->createGenericCollection( + $crew = $this->createCustomCollection( $data[$type]['crew'], - new Person\MovieCredit() + new Person\MovieCredit(), + new People\Crew() ); foreach ($crew as $member) { diff --git a/lib/Tmdb/HttpClient/HttpClient.php b/lib/Tmdb/HttpClient/HttpClient.php index 6b1c8049..0ef1ef8e 100644 --- a/lib/Tmdb/HttpClient/HttpClient.php +++ b/lib/Tmdb/HttpClient/HttpClient.php @@ -13,7 +13,7 @@ namespace Tmdb\HttpClient; use Guzzle\Http\ClientInterface; -use Guzzle\Http\Message\Request; +use Guzzle\Http\Exception\ClientErrorResponseException; use Guzzle\Http\Message\RequestInterface; use Guzzle\Http\Message\Response; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -52,7 +52,7 @@ class HttpClient implements HttpClientInterface private $lastResponse; /** - * @var Request + * @var RequestInterface */ private $lastRequest; @@ -186,7 +186,7 @@ public function request(RequestInterface $request) try { $response = $request->send(); - } catch (\Exception $e) { + } catch (ClientErrorResponseException $e) { $error = $e->getResponse()->json(); throw new TmdbApiException($error['status_message'], $error['status_code']); } diff --git a/lib/Tmdb/HttpClient/Plugin/SessionTokenPlugin.php b/lib/Tmdb/HttpClient/Plugin/SessionTokenPlugin.php index 6a84979d..785d1d6e 100644 --- a/lib/Tmdb/HttpClient/Plugin/SessionTokenPlugin.php +++ b/lib/Tmdb/HttpClient/Plugin/SessionTokenPlugin.php @@ -24,7 +24,7 @@ class SessionTokenPlugin implements EventSubscriberInterface { /** - * @var \Tmdb\ApiToken + * @var \Tmdb\SessionToken */ private $token; diff --git a/lib/Tmdb/Model/Collection/CreditsCollection.php b/lib/Tmdb/Model/Collection/CreditsCollection.php index 69d71747..6899a136 100644 --- a/lib/Tmdb/Model/Collection/CreditsCollection.php +++ b/lib/Tmdb/Model/Collection/CreditsCollection.php @@ -14,7 +14,6 @@ use Tmdb\Model\Collection\People\Cast; use Tmdb\Model\Collection\People\Crew; -use Tmdb\Model\Common\GenericCollection; /** * Class CreditsCollection @@ -42,10 +41,10 @@ public function __construct() } /** - * @param Cast|GenericCollection $cast + * @param Cast $cast * @return $this */ - public function setCast(GenericCollection $cast) + public function setCast(Cast $cast) { $this->cast = $cast; @@ -61,10 +60,10 @@ public function getCast() } /** - * @param Crew|GenericCollection $crew + * @param Crew $crew * @return $this */ - public function setCrew(GenericCollection $crew) + public function setCrew(Crew $crew) { $this->crew = $crew; diff --git a/lib/Tmdb/Model/Movie.php b/lib/Tmdb/Model/Movie.php index 8e7e4f9c..33072a6a 100644 --- a/lib/Tmdb/Model/Movie.php +++ b/lib/Tmdb/Model/Movie.php @@ -46,9 +46,9 @@ class Movie extends AbstractModel private $backdrop; /** - * @var Collection + * @var GenericCollection */ - private $belongsToCollection = null; + private $belongsToCollection; /** * @var int @@ -101,12 +101,12 @@ class Movie extends AbstractModel private $posterPath; /** - * @var Collection + * @var GenericCollection */ private $productionCompanies; /** - * @var Collection + * @var GenericCollection */ private $productionCountries; @@ -126,7 +126,7 @@ class Movie extends AbstractModel private $runtime; /** - * @var Collection + * @var GenericCollection */ private $spokenLanguages; @@ -156,19 +156,19 @@ class Movie extends AbstractModel private $voteCount; /** - * @var Collection + * @var GenericCollection */ protected $alternativeTitles; /** - * @var Collection + * @var GenericCollection */ protected $changes; /** * Credits * - * @var Credits + * @var CreditsCollection */ protected $credits; @@ -180,32 +180,27 @@ class Movie extends AbstractModel protected $images; /** - * @var Collection + * @var GenericCollection */ protected $keywords; /** - * @var Collection + * @var GenericCollection */ protected $lists; /** - * @var Collection + * @var GenericCollection */ protected $releases; /** - * @var Collection + * @var GenericCollection */ protected $similar; /** - * @var Collection - */ - protected $trailers; - - /** - * @var Collection + * @var GenericCollection */ protected $translations; @@ -267,7 +262,6 @@ public function __construct() $this->lists = new GenericCollection(); $this->releases = new GenericCollection(); $this->similar = new GenericCollection(); - $this->trailers = new GenericCollection(); $this->translations = new GenericCollection(); $this->videos = new Videos(); } @@ -292,7 +286,7 @@ public function getAdult() } /** - * @param mixed $backdropPath + * @param string $backdropPath * @return $this */ public function setBackdropPath($backdropPath) @@ -303,7 +297,7 @@ public function setBackdropPath($backdropPath) } /** - * @return mixed + * @return string */ public function getBackdropPath() { @@ -368,7 +362,7 @@ public function getGenres() } /** - * @param mixed $homepage + * @param string $homepage * @return $this */ public function setHomepage($homepage) @@ -379,7 +373,7 @@ public function setHomepage($homepage) } /** - * @return mixed + * @return string */ public function getHomepage() { @@ -425,7 +419,7 @@ public function getImages() } /** - * @param mixed $imdbId + * @param string $imdbId * @return $this */ public function setImdbId($imdbId) @@ -436,7 +430,7 @@ public function setImdbId($imdbId) } /** - * @return mixed + * @return string */ public function getImdbId() { @@ -444,7 +438,7 @@ public function getImdbId() } /** - * @param mixed $originalTitle + * @param string $originalTitle * @return $this */ public function setOriginalTitle($originalTitle) @@ -455,7 +449,7 @@ public function setOriginalTitle($originalTitle) } /** - * @return mixed + * @return string */ public function getOriginalTitle() { @@ -501,7 +495,7 @@ public function getPopularity() } /** - * @param mixed $posterPath + * @param string $posterPath * @return $this */ public function setPosterPath($posterPath) @@ -512,7 +506,7 @@ public function setPosterPath($posterPath) } /** - * @return mixed + * @return string */ public function getPosterPath() { @@ -638,7 +632,7 @@ public function getSpokenLanguages() } /** - * @param mixed $status + * @param string $status * @return $this */ public function setStatus($status) @@ -649,7 +643,7 @@ public function setStatus($status) } /** - * @return mixed + * @return string */ public function getStatus() { @@ -657,7 +651,7 @@ public function getStatus() } /** - * @param mixed $tagline + * @param string $tagline * @return $this */ public function setTagline($tagline) @@ -668,7 +662,7 @@ public function setTagline($tagline) } /** - * @return mixed + * @return string */ public function getTagline() { @@ -676,7 +670,7 @@ public function getTagline() } /** - * @param mixed $title + * @param string $title * @return $this */ public function setTitle($title) @@ -687,7 +681,7 @@ public function setTitle($title) } /** - * @return mixed + * @return string */ public function getTitle() { @@ -874,25 +868,6 @@ public function getSimilarMovies() return $this->getSimilar(); } - /** - * @param GenericCollection $trailers - * @return $this - */ - public function setTrailers($trailers) - { - $this->trailers = $trailers; - - return $this; - } - - /** - * @return \Tmdb\Model\Common\Trailer\Youtube[] - */ - public function getTrailers() - { - return $this->trailers; - } - /** * @param GenericCollection $translations * @return $this diff --git a/lib/Tmdb/Model/Network.php b/lib/Tmdb/Model/Network.php index d71d64a9..5556ad5b 100644 --- a/lib/Tmdb/Model/Network.php +++ b/lib/Tmdb/Model/Network.php @@ -60,7 +60,7 @@ public function getId() } /** - * @param mixed $name + * @param string $name * @return $this */ public function setName($name) diff --git a/lib/Tmdb/Model/Person.php b/lib/Tmdb/Model/Person.php index c396cd36..a653e73d 100644 --- a/lib/Tmdb/Model/Person.php +++ b/lib/Tmdb/Model/Person.php @@ -145,7 +145,7 @@ public function __construct() } /** - * @param mixed $adult + * @param boolean $adult * @return $this */ public function setAdult($adult) @@ -164,7 +164,7 @@ public function getAdult() } /** - * @param mixed $alsoKnownAs + * @param array $alsoKnownAs * @return $this */ public function setAlsoKnownAs($alsoKnownAs) @@ -183,7 +183,7 @@ public function getAlsoKnownAs() } /** - * @param mixed $biography + * @param string $biography * @return $this */ public function setBiography($biography) @@ -225,10 +225,10 @@ public function getBirthday() } /** - * @param mixed $changes + * @param GenericCollection $changes * @return $this */ - public function setChanges($changes) + public function setChanges(GenericCollection $changes) { $this->changes = $changes; @@ -271,7 +271,7 @@ public function getDeathday() } /** - * @param mixed $homepage + * @param string $homepage * @return $this */ public function setHomepage($homepage) @@ -328,7 +328,7 @@ public function getImages() } /** - * @param mixed $name + * @param string $name * @return $this */ public function setName($name) @@ -347,7 +347,7 @@ public function getName() } /** - * @param mixed $placeOfBirth + * @param string $placeOfBirth * @return $this */ public function setPlaceOfBirth($placeOfBirth) @@ -366,7 +366,7 @@ public function getPlaceOfBirth() } /** - * @param mixed $profilePath + * @param string $profilePath * @return $this */ public function setProfilePath($profilePath) @@ -480,7 +480,7 @@ public function getExternalIds() } /** - * @param mixed $taggedImages + * @param GenericCollection $taggedImages * @return $this */ public function setTaggedImages($taggedImages) diff --git a/lib/Tmdb/Model/Person/AbstractMember.php b/lib/Tmdb/Model/Person/AbstractMember.php index a4c79282..582a3e0d 100644 --- a/lib/Tmdb/Model/Person/AbstractMember.php +++ b/lib/Tmdb/Model/Person/AbstractMember.php @@ -67,7 +67,7 @@ public function getId() } /** - * @param mixed $name + * @param string $name * @return $this */ public function setName($name) @@ -86,7 +86,7 @@ public function getName() } /** - * @param mixed $profilePath + * @param string $profilePath * @return $this */ public function setProfilePath($profilePath) diff --git a/lib/Tmdb/Model/Person/CastMember.php b/lib/Tmdb/Model/Person/CastMember.php index adca6dfe..37d478c7 100644 --- a/lib/Tmdb/Model/Person/CastMember.php +++ b/lib/Tmdb/Model/Person/CastMember.php @@ -51,7 +51,7 @@ class CastMember extends AbstractMember implements PersonInterface ); /** - * @param mixed $character + * @param string $character * @return $this */ public function setCharacter($character) diff --git a/lib/Tmdb/Model/Person/CrewMember.php b/lib/Tmdb/Model/Person/CrewMember.php index 9f5277fb..030295da 100644 --- a/lib/Tmdb/Model/Person/CrewMember.php +++ b/lib/Tmdb/Model/Person/CrewMember.php @@ -45,7 +45,7 @@ class CrewMember extends AbstractMember implements PersonInterface ); /** - * @param mixed $department + * @param string $department * @return $this */ public function setDepartment($department) @@ -64,7 +64,7 @@ public function getDepartment() } /** - * @param mixed $job + * @param string $job * @return $this */ public function setJob($job) diff --git a/lib/Tmdb/Model/Timezone/CountryTimezone.php b/lib/Tmdb/Model/Timezone/CountryTimezone.php index f02a3335..0aec8f13 100644 --- a/lib/Tmdb/Model/Timezone/CountryTimezone.php +++ b/lib/Tmdb/Model/Timezone/CountryTimezone.php @@ -14,7 +14,6 @@ use Tmdb\Model\AbstractModel; use Tmdb\Model\Collection\Timezones; -use Tmdb\Model\Common\GenericCollection; /** * Class Timezone @@ -34,7 +33,7 @@ class CountryTimezone extends AbstractModel public function __construct() { - $this->timezones = new GenericCollection(); + $this->timezones = new Timezones(); } /** diff --git a/lib/Tmdb/Model/Tv.php b/lib/Tmdb/Model/Tv.php index 8087ee5f..869bdeae 100644 --- a/lib/Tmdb/Model/Tv.php +++ b/lib/Tmdb/Model/Tv.php @@ -28,12 +28,12 @@ class Tv extends AbstractModel { /** - * @var Image + * @var string */ private $backdropPath; /** - * @var Collection + * @var Common\GenericCollection */ private $createdBy = null; @@ -105,7 +105,7 @@ class Tv extends AbstractModel private $originalName; /** - * @var Collection + * @var Common\GenericCollection */ private $originCountry; @@ -120,12 +120,12 @@ class Tv extends AbstractModel private $popularity; /** - * @var Image + * @var string */ private $posterPath; /** - * @var Collection + * @var Common\GenericCollection */ private $seasons; @@ -147,7 +147,7 @@ class Tv extends AbstractModel /** * Credits * - * @var Credits + * @var CreditsCollection */ protected $credits; @@ -166,7 +166,7 @@ class Tv extends AbstractModel protected $images; /** - * @var Collection + * @var Common\GenericCollection */ protected $translations; diff --git a/lib/Tmdb/Model/Tv/Episode.php b/lib/Tmdb/Model/Tv/Episode.php index 84a7ebac..31c76edc 100644 --- a/lib/Tmdb/Model/Tv/Episode.php +++ b/lib/Tmdb/Model/Tv/Episode.php @@ -80,7 +80,7 @@ class Episode extends AbstractModel /** * Credits * - * @var Credits + * @var CreditsCollection */ protected $credits; diff --git a/lib/Tmdb/Model/Tv/Season.php b/lib/Tmdb/Model/Tv/Season.php index 5d3b11a8..140efc6c 100644 --- a/lib/Tmdb/Model/Tv/Season.php +++ b/lib/Tmdb/Model/Tv/Season.php @@ -34,7 +34,7 @@ class Season extends AbstractModel private $airDate; /** - * @var Episode[] + * @var GenericCollection|Episode[] */ private $episodes; @@ -66,7 +66,7 @@ class Season extends AbstractModel /** * Credits * - * @var Credits + * @var CreditsCollection */ protected $credits; @@ -224,7 +224,7 @@ public function getOverview() } /** - * @param \Tmdb\Model\Tv\Image $posterPath + * @param string $posterPath * @return $this */ public function setPosterPath($posterPath) diff --git a/lib/Tmdb/Repository/MovieRepository.php b/lib/Tmdb/Repository/MovieRepository.php index 9dc0b488..f84e7ba6 100644 --- a/lib/Tmdb/Repository/MovieRepository.php +++ b/lib/Tmdb/Repository/MovieRepository.php @@ -409,7 +409,7 @@ private function createCollection($data) } /** - * @param mixed $alternativeTitleFactory + * @param AlternativeTitleFactory $alternativeTitleFactory * @return $this */ public function setAlternativeTitleFactory($alternativeTitleFactory) @@ -428,7 +428,7 @@ public function getAlternativeTitleFactory() } /** - * @param mixed $imageFactory + * @param ImageFactory $imageFactory * @return $this */ public function setImageFactory($imageFactory) @@ -447,7 +447,7 @@ public function getImageFactory() } /** - * @param mixed $peopleFactory + * @param PeopleFactory $peopleFactory * @return $this */ public function setPeopleFactory($peopleFactory) diff --git a/lib/Tmdb/Repository/PeopleRepository.php b/lib/Tmdb/Repository/PeopleRepository.php index fec61ee3..7e9080d6 100644 --- a/lib/Tmdb/Repository/PeopleRepository.php +++ b/lib/Tmdb/Repository/PeopleRepository.php @@ -184,7 +184,7 @@ public function getTaggedImages($id, array $parameters = array(), array $headers $factory = new ImageFactory(); - return $factory->createResultCollection($data, 'createMediaImage', 'tagged_images'); + return $factory->createResultCollection($data, 'createMediaImage'); } /** diff --git a/lib/Tmdb/SessionToken.php b/lib/Tmdb/SessionToken.php index 093e0132..2bfe3a01 100644 --- a/lib/Tmdb/SessionToken.php +++ b/lib/Tmdb/SessionToken.php @@ -29,7 +29,7 @@ class SessionToken private $expiresAt; /** - * @var bool + * @var boolean */ private $success; @@ -86,7 +86,7 @@ public function getExpiresAt() } /** - * @param mixed $success + * @param boolean $success * @return $this */ public function setSuccess($success) diff --git a/test/Tmdb/Tests/Factory/AuthenticationFactoryTest.php b/test/Tmdb/Tests/Factory/AuthenticationFactoryTest.php index 839775e0..48acfbe4 100644 --- a/test/Tmdb/Tests/Factory/AuthenticationFactoryTest.php +++ b/test/Tmdb/Tests/Factory/AuthenticationFactoryTest.php @@ -68,7 +68,7 @@ public function shouldCreateGuestSessionToken() /** * @test - * @expectedException \Tmdb\Exception\NotImplementedException + * @expectedException \RuntimeException */ public function shouldThrowExceptionForCreate() { @@ -82,7 +82,7 @@ public function shouldThrowExceptionForCreate() /** * @test - * @expectedException \Tmdb\Exception\NotImplementedException + * @expectedException \RuntimeException */ public function shouldThrowExceptionForCreateCollection() { diff --git a/test/Tmdb/Tests/Factory/FindFactoryTest.php b/test/Tmdb/Tests/Factory/FindFactoryTest.php index b044f799..4bb4f970 100644 --- a/test/Tmdb/Tests/Factory/FindFactoryTest.php +++ b/test/Tmdb/Tests/Factory/FindFactoryTest.php @@ -67,7 +67,7 @@ public function shouldBeAbleToSetFactories() /** * @test - * @expectedException Tmdb\Exception\NotImplementedException + * @expectedException \RuntimeException */ public function shouldThrowExceptionForCreateCollection() { diff --git a/test/Tmdb/Tests/Factory/MovieFactoryTest.php b/test/Tmdb/Tests/Factory/MovieFactoryTest.php index 4380696e..01dc88f5 100644 --- a/test/Tmdb/Tests/Factory/MovieFactoryTest.php +++ b/test/Tmdb/Tests/Factory/MovieFactoryTest.php @@ -103,7 +103,7 @@ public function shouldBeFunctional() $this->assertInstanceOf('Tmdb\Model\Common\GenericCollection', $this->movie->getLists()); $this->assertInstanceOf('Tmdb\Model\Common\GenericCollection', $this->movie->getReleases()); $this->assertInstanceOf('Tmdb\Model\Common\GenericCollection', $this->movie->getSimilar()); - $this->assertInstanceOf('Tmdb\Model\Common\GenericCollection', $this->movie->getTrailers()); + $this->assertInstanceOf('Tmdb\Model\Collection\Videos', $this->movie->getVideos()); } /** diff --git a/test/Tmdb/Tests/Model/MovieTest.php b/test/Tmdb/Tests/Model/MovieTest.php index 65f7c7f6..7f6befbd 100644 --- a/test/Tmdb/Tests/Model/MovieTest.php +++ b/test/Tmdb/Tests/Model/MovieTest.php @@ -41,7 +41,6 @@ public function shouldConstructMovie() 'getLists' => 'Tmdb\Model\Common\GenericCollection', 'getReleases' => 'Tmdb\Model\Common\GenericCollection', 'getSimilar' => 'Tmdb\Model\Common\GenericCollection', - 'getTrailers' => 'Tmdb\Model\Common\GenericCollection', 'getTranslations' => 'Tmdb\Model\Common\GenericCollection', 'getVideos' => 'Tmdb\Model\Collection\Videos', ) diff --git a/test/Tmdb/Tests/Model/PersonTest.php b/test/Tmdb/Tests/Model/PersonTest.php index 0032f117..cfc1872d 100644 --- a/test/Tmdb/Tests/Model/PersonTest.php +++ b/test/Tmdb/Tests/Model/PersonTest.php @@ -27,7 +27,6 @@ public function shouldConstructPersons() $this->assertInstancesOf( $person, array( - 'getCredits' => 'Tmdb\Model\Collection\CreditsCollection', 'getImages' => 'Tmdb\Model\Collection\Images', 'getChanges' => 'Tmdb\Model\Common\GenericCollection', 'getCombinedCredits' => 'Tmdb\Model\Collection\CreditsCollection\CombinedCredits', @@ -65,14 +64,12 @@ public function shouldAllowOverridingDefaultCollectionObjects() $className = get_class($class); $movie->setChanges($class); - $movie->setCredits($class); $this->assertInstancesOf( $movie, array( /** Constructor */ - 'getChanges' => $className, - 'getCredits' => $className + 'getChanges' => $className ) ); } diff --git a/test/Tmdb/Tests/Repository/MovieRepositoryTest.php b/test/Tmdb/Tests/Repository/MovieRepositoryTest.php index 885a528d..91dc045a 100644 --- a/test/Tmdb/Tests/Repository/MovieRepositoryTest.php +++ b/test/Tmdb/Tests/Repository/MovieRepositoryTest.php @@ -78,16 +78,6 @@ public function shouldGetReleases() $repository->getReleases(self::MOVIE_ID); } - /** - * @test - */ - public function shouldGetTrailers() - { - $repository = $this->getRepositoryWithMockedHttpClient(); - - $repository->getTrailers(self::MOVIE_ID); - } - /** * @test */ From 5c1f3d2517ba7b115c938d10c3c43091b3ba29af Mon Sep 17 00:00:00 2001 From: Michael Roterman Date: Sat, 12 Jul 2014 13:18:41 +0200 Subject: [PATCH 09/19] Fix searchQuery --- lib/Tmdb/Model/Search/SearchQuery.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Tmdb/Model/Search/SearchQuery.php b/lib/Tmdb/Model/Search/SearchQuery.php index 732e44fa..c822e22f 100644 --- a/lib/Tmdb/Model/Search/SearchQuery.php +++ b/lib/Tmdb/Model/Search/SearchQuery.php @@ -31,7 +31,7 @@ public function __construct() /** * CGI escaped string * - * @param string + * @param string $query * @return $this */ public function query($query) @@ -44,7 +44,7 @@ public function query($query) /** * Minimum 1, maximum 1000. * - * @param int + * @param int $page * @return $this */ public function page($page) From 15f780bad5f866616ec0fe623787895a41b72f94 Mon Sep 17 00:00:00 2001 From: Michael Roterman Date: Sat, 12 Jul 2014 13:20:06 +0200 Subject: [PATCH 10/19] Fixing docblocks --- lib/Tmdb/Api/AbstractApi.php | 16 +++---- lib/Tmdb/Api/Authentication.php | 8 ++-- lib/Tmdb/Api/Lists.php | 6 +-- lib/Tmdb/Api/Movies.php | 3 ++ lib/Tmdb/Api/Search.php | 42 +++++++++---------- lib/Tmdb/ApiToken.php | 2 +- lib/Tmdb/Factory/PeopleFactory.php | 2 +- lib/Tmdb/HttpClient/HttpClientInterface.php | 20 +++++++-- lib/Tmdb/Model/Collection/Images.php | 2 +- .../Collection/People/PersonInterface.php | 3 ++ lib/Tmdb/Model/Movie.php | 10 ++--- lib/Tmdb/Model/Network.php | 2 +- lib/Tmdb/Model/Person.php | 18 ++++---- lib/Tmdb/Model/Person/AbstractMember.php | 6 +-- lib/Tmdb/Model/Person/CastMember.php | 2 +- lib/Tmdb/Model/Person/CrewMember.php | 4 +- lib/Tmdb/Model/Timezone/CountryTimezone.php | 2 +- lib/Tmdb/Model/Tv.php | 8 ++-- lib/Tmdb/Model/Tv/Episode.php | 3 +- lib/Tmdb/Model/Tv/Season.php | 5 +-- lib/Tmdb/Repository/AccountRepository.php | 10 ++--- .../Repository/AuthenticationRepository.php | 10 ++--- .../Repository/CertificationRepository.php | 2 +- lib/Tmdb/Repository/CompanyRepository.php | 12 +++--- lib/Tmdb/Repository/CreditsRepository.php | 4 +- lib/Tmdb/Repository/DiscoverRepository.php | 7 +--- lib/Tmdb/Repository/GenreRepository.php | 4 +- lib/Tmdb/Repository/MovieRepository.php | 6 +-- lib/Tmdb/Repository/PeopleRepository.php | 30 ++++++------- lib/Tmdb/Repository/SearchRepository.php | 4 +- lib/Tmdb/Repository/TvSeasonRepository.php | 1 - lib/Tmdb/RequestToken.php | 6 +-- lib/Tmdb/SessionToken.php | 4 +- 33 files changed, 135 insertions(+), 129 deletions(-) diff --git a/lib/Tmdb/Api/AbstractApi.php b/lib/Tmdb/Api/AbstractApi.php index 51396204..49c961bf 100644 --- a/lib/Tmdb/Api/AbstractApi.php +++ b/lib/Tmdb/Api/AbstractApi.php @@ -77,10 +77,10 @@ public function head($path, array $parameters = array(), $headers = array()) /** * Send a POST request * - * @param $path - * @param null $postBody - * @param array $parameters - * @param array $headers + * @param string $path + * @param null $postBody + * @param array $parameters + * @param array $headers * @return mixed */ public function post($path, $postBody = null, array $parameters = array(), $headers = array()) @@ -138,10 +138,10 @@ public function put($path, $body = null, array $parameters = array(), $headers = /** * Send a DELETE request * - * @param $path - * @param null $body - * @param array $parameters - * @param array $headers + * @param string $path + * @param null $body + * @param array $parameters + * @param array $headers * @return mixed */ public function delete($path, $body = null, array $parameters = array(), $headers = array()) diff --git a/lib/Tmdb/Api/Authentication.php b/lib/Tmdb/Api/Authentication.php index 2078326d..c697e208 100644 --- a/lib/Tmdb/Api/Authentication.php +++ b/lib/Tmdb/Api/Authentication.php @@ -41,7 +41,7 @@ public function getNewToken() /** * Redirect the user to authenticate the request token * - * @param $token + * @param string $token */ public function authenticateRequestToken($token) { @@ -83,9 +83,9 @@ public function getNewSession($requestToken) /** * Helper method to validate the request_token and obtain a session_token * - * @param $requestToken - * @param $username - * @param $password + * @param RequestToken $requestToken + * @param string $username + * @param string $password * @return mixed * @throws \InvalidArgumentException */ diff --git a/lib/Tmdb/Api/Lists.php b/lib/Tmdb/Api/Lists.php index a36889db..b1345623 100644 --- a/lib/Tmdb/Api/Lists.php +++ b/lib/Tmdb/Api/Lists.php @@ -22,9 +22,9 @@ class Lists extends AbstractApi /** * Get a list by id. * - * @param $list_id - * @param array $parameters - * @param array $headers + * @param string $list_id + * @param array $parameters + * @param array $headers * @return mixed */ public function getList($list_id, array $parameters = array(), array $headers = array()) diff --git a/lib/Tmdb/Api/Movies.php b/lib/Tmdb/Api/Movies.php index 400d98e1..7f8d8928 100644 --- a/lib/Tmdb/Api/Movies.php +++ b/lib/Tmdb/Api/Movies.php @@ -260,6 +260,7 @@ public function getTopRated(array $parameters = array(), array $headers = array( * or added to their favourite or watch lists. * * A valid session id is required. + * @param integer $id */ public function getAccountStates($id) { @@ -270,6 +271,8 @@ public function getAccountStates($id) * TThis method lets users rate a movie. * * A valid session id or guest session id is required. + * @param integer $id + * @param double $rating */ public function rateMovie($id, $rating) { diff --git a/lib/Tmdb/Api/Search.php b/lib/Tmdb/Api/Search.php index 2c49f8e2..9e605d49 100644 --- a/lib/Tmdb/Api/Search.php +++ b/lib/Tmdb/Api/Search.php @@ -22,9 +22,9 @@ class Search extends AbstractApi /** * Search for movies by title. * - * @param $query - * @param array $parameters - * @param array $headers + * @param string $query + * @param array $parameters + * @param array $headers * @return mixed */ public function searchMovies($query, array $parameters = array(), array $headers = array()) @@ -37,9 +37,9 @@ public function searchMovies($query, array $parameters = array(), array $headers /** * Search for collections by name. * - * @param $query - * @param array $parameters - * @param array $headers + * @param string $query + * @param array $parameters + * @param array $headers * @return mixed */ public function searchCollection($query, array $parameters = array(), array $headers = array()) @@ -52,9 +52,9 @@ public function searchCollection($query, array $parameters = array(), array $hea /** * Search for TV shows by title. * - * @param $query - * @param array $parameters - * @param array $headers + * @param string $query + * @param array $parameters + * @param array $headers * @return mixed */ public function searchTv($query, array $parameters = array(), array $headers = array()) @@ -67,9 +67,9 @@ public function searchTv($query, array $parameters = array(), array $headers = a /** * Search for people by name. * - * @param $query - * @param array $parameters - * @param array $headers + * @param string $query + * @param array $parameters + * @param array $headers * @return mixed */ public function searchPersons($query, array $parameters = array(), array $headers = array()) @@ -82,9 +82,9 @@ public function searchPersons($query, array $parameters = array(), array $header /** * Search for lists by name and description. * - * @param $query - * @param array $parameters - * @param array $headers + * @param string $query + * @param array $parameters + * @param array $headers * @return mixed */ public function searchList($query, array $parameters = array(), array $headers = array()) @@ -112,9 +112,9 @@ public function searchCompany($query, array $parameters = array(), array $header /** * Search for companies by name. * - * @param $query - * @param array $parameters - * @param array $headers + * @param string $query + * @param array $parameters + * @param array $headers * @return mixed */ public function searchKeyword($query, array $parameters = array(), array $headers = array()) @@ -130,9 +130,9 @@ public function searchKeyword($query, array $parameters = array(), array $header * Each item returned in the result array has a media_type field that maps to either movie, tv or person. * Each mapped result is the same response you would get from each independent search. * - * @param $query - * @param array $parameters - * @param array $headers + * @param string $query + * @param array $parameters + * @param array $headers * @return mixed */ public function searchMulti($query, array $parameters = array(), array $headers = array()) diff --git a/lib/Tmdb/ApiToken.php b/lib/Tmdb/ApiToken.php index c79e4760..8e93ab55 100644 --- a/lib/Tmdb/ApiToken.php +++ b/lib/Tmdb/ApiToken.php @@ -48,7 +48,7 @@ public function setToken($apiToken) } /** - * @return null + * @return string */ public function getToken() { diff --git a/lib/Tmdb/Factory/PeopleFactory.php b/lib/Tmdb/Factory/PeopleFactory.php index 8a878e32..1fba7a63 100644 --- a/lib/Tmdb/Factory/PeopleFactory.php +++ b/lib/Tmdb/Factory/PeopleFactory.php @@ -45,7 +45,7 @@ public function __construct() * @param array $data * @param Person\AbstractMember|null $person * - * @return Person|CrewMember|CastMember + * @return Person */ public function create(array $data = array(), $person = null) { diff --git a/lib/Tmdb/HttpClient/HttpClientInterface.php b/lib/Tmdb/HttpClient/HttpClientInterface.php index a88d89f8..d264d4fb 100644 --- a/lib/Tmdb/HttpClient/HttpClientInterface.php +++ b/lib/Tmdb/HttpClient/HttpClientInterface.php @@ -48,10 +48,10 @@ public function post($path, $postBody, array $parameters = array(), array $heade /** * Compose a POST request but json_encode the body * - * @param string $path Request path - * @param array $postBody The post BODY - * @param array $parameters POST Parameters - * @param array $headers Reconfigure the request headers for this call only + * @param string $path Request path + * @param string|null $postBody The post BODY + * @param array $parameters POST Parameters + * @param array $headers Reconfigure the request headers for this call only * * @return Response Data */ @@ -101,8 +101,20 @@ public function delete($path, $body = null, array $parameters = array(), array $ */ public function request(RequestInterface $request); + /** + * @return string|null + */ public function getBaseUrl(); + + /** + * @param string $url + * + * @return \Guzzle\Http\ClientInterface + */ public function setBaseUrl($url); + /** + * @return void + */ public function setSessionToken(SessionToken $sessionToken); } diff --git a/lib/Tmdb/Model/Collection/Images.php b/lib/Tmdb/Model/Collection/Images.php index 7163afde..5377d011 100644 --- a/lib/Tmdb/Model/Collection/Images.php +++ b/lib/Tmdb/Model/Collection/Images.php @@ -36,7 +36,7 @@ public function getImages() * Retrieve a image from the collection * * @param $id - * @return null + * @return GenericCollection */ public function getImage($id) { diff --git a/lib/Tmdb/Model/Collection/People/PersonInterface.php b/lib/Tmdb/Model/Collection/People/PersonInterface.php index 3d3e0ad7..7dbdcf2c 100644 --- a/lib/Tmdb/Model/Collection/People/PersonInterface.php +++ b/lib/Tmdb/Model/Collection/People/PersonInterface.php @@ -18,6 +18,9 @@ */ interface PersonInterface { + /** + * @return string + */ public function getName(); /** diff --git a/lib/Tmdb/Model/Movie.php b/lib/Tmdb/Model/Movie.php index 33072a6a..41734f71 100644 --- a/lib/Tmdb/Model/Movie.php +++ b/lib/Tmdb/Model/Movie.php @@ -18,7 +18,6 @@ use Tmdb\Model\Collection\CreditsCollection; use Tmdb\Model\Collection\Genres; use Tmdb\Model\Collection\Images; -use Tmdb\Model\Common\Country; use Tmdb\Model\Common\SpokenLanguage; use Tmdb\Model\Common\Translation; use Tmdb\Model\Movie\AlternativeTitle; @@ -316,7 +315,7 @@ public function setBelongsToCollection($belongsToCollection) } /** - * @return Collection|null + * @return GenericCollection */ public function getBelongsToCollection() { @@ -336,6 +335,7 @@ public function setChanges(GenericCollection $changes) /** * @return mixed + * @return GenericCollection */ public function getChanges() { @@ -354,7 +354,7 @@ public function setGenres(Genres $genres) } /** - * @return Genre[] + * @return Genres */ public function getGenres() { @@ -468,7 +468,7 @@ public function setOverview($overview) } /** - * @return mixed + * @return string */ public function getOverview() { @@ -544,7 +544,7 @@ public function setProductionCountries(GenericCollection $productionCountries) } /** - * @return Country + * @return GenericCollection */ public function getProductionCountries() { diff --git a/lib/Tmdb/Model/Network.php b/lib/Tmdb/Model/Network.php index 5556ad5b..4391032c 100644 --- a/lib/Tmdb/Model/Network.php +++ b/lib/Tmdb/Model/Network.php @@ -71,7 +71,7 @@ public function setName($name) } /** - * @return mixed + * @return string */ public function getName() { diff --git a/lib/Tmdb/Model/Person.php b/lib/Tmdb/Model/Person.php index a653e73d..3dcc4d96 100644 --- a/lib/Tmdb/Model/Person.php +++ b/lib/Tmdb/Model/Person.php @@ -156,7 +156,7 @@ public function setAdult($adult) } /** - * @return mixed + * @return boolean */ public function getAdult() { @@ -194,7 +194,7 @@ public function setBiography($biography) } /** - * @return mixed + * @return string */ public function getBiography() { @@ -217,7 +217,7 @@ public function setBirthday($birthday) } /** - * @return mixed + * @return \DateTime */ public function getBirthday() { @@ -236,7 +236,7 @@ public function setChanges(GenericCollection $changes) } /** - * @return mixed + * @return GenericCollection */ public function getChanges() { @@ -282,7 +282,7 @@ public function setHomepage($homepage) } /** - * @return mixed + * @return string */ public function getHomepage() { @@ -339,7 +339,7 @@ public function setName($name) } /** - * @return mixed + * @return string */ public function getName() { @@ -358,7 +358,7 @@ public function setPlaceOfBirth($placeOfBirth) } /** - * @return mixed + * @return string */ public function getPlaceOfBirth() { @@ -377,7 +377,7 @@ public function setProfilePath($profilePath) } /** - * @return mixed + * @return string */ public function getProfilePath() { @@ -491,7 +491,7 @@ public function setTaggedImages($taggedImages) } /** - * @return mixed + * @return GenericCollection */ public function getTaggedImages() { diff --git a/lib/Tmdb/Model/Person/AbstractMember.php b/lib/Tmdb/Model/Person/AbstractMember.php index 582a3e0d..5bb1176c 100644 --- a/lib/Tmdb/Model/Person/AbstractMember.php +++ b/lib/Tmdb/Model/Person/AbstractMember.php @@ -78,7 +78,7 @@ public function setName($name) } /** - * @return mixed + * @return string */ public function getName() { @@ -97,7 +97,7 @@ public function setProfilePath($profilePath) } /** - * @return mixed + * @return string */ public function getProfilePath() { @@ -116,7 +116,7 @@ public function setProfileImage($profile = null) } /** - * @return Image\ProfileImage|null + * @return Image\ProfileImage */ public function getProfileImage() { diff --git a/lib/Tmdb/Model/Person/CastMember.php b/lib/Tmdb/Model/Person/CastMember.php index 37d478c7..9468f38d 100644 --- a/lib/Tmdb/Model/Person/CastMember.php +++ b/lib/Tmdb/Model/Person/CastMember.php @@ -62,7 +62,7 @@ public function setCharacter($character) } /** - * @return mixed + * @return string */ public function getCharacter() { diff --git a/lib/Tmdb/Model/Person/CrewMember.php b/lib/Tmdb/Model/Person/CrewMember.php index 030295da..0b3c00f2 100644 --- a/lib/Tmdb/Model/Person/CrewMember.php +++ b/lib/Tmdb/Model/Person/CrewMember.php @@ -56,7 +56,7 @@ public function setDepartment($department) } /** - * @return mixed + * @return string */ public function getDepartment() { @@ -75,7 +75,7 @@ public function setJob($job) } /** - * @return mixed + * @return string */ public function getJob() { diff --git a/lib/Tmdb/Model/Timezone/CountryTimezone.php b/lib/Tmdb/Model/Timezone/CountryTimezone.php index 0aec8f13..7d53d06d 100644 --- a/lib/Tmdb/Model/Timezone/CountryTimezone.php +++ b/lib/Tmdb/Model/Timezone/CountryTimezone.php @@ -78,7 +78,7 @@ public function getIso31661() * Verify if a country supports a certain timezone * * @param $timezone - * @return mixed + * @return boolean */ public function supports($timezone) { diff --git a/lib/Tmdb/Model/Tv.php b/lib/Tmdb/Model/Tv.php index 869bdeae..501a9fbf 100644 --- a/lib/Tmdb/Model/Tv.php +++ b/lib/Tmdb/Model/Tv.php @@ -286,7 +286,7 @@ public function setCreatedBy($createdBy) } /** - * @return \Tmdb\Model\Common\Collection + * @return GenericCollection */ public function getCreatedBy() { @@ -541,7 +541,7 @@ public function setOriginCountry($originCountry) } /** - * @return \Tmdb\Model\Common\Collection + * @return GenericCollection */ public function getOriginCountry() { @@ -636,7 +636,7 @@ public function setSeasons($seasons) } /** - * @return \Tmdb\Model\Common\Collection + * @return GenericCollection */ public function getSeasons() { @@ -712,7 +712,7 @@ public function setTranslations($translations) } /** - * @return \Tmdb\Model\Common\Collection + * @return GenericCollection */ public function getTranslations() { diff --git a/lib/Tmdb/Model/Tv/Episode.php b/lib/Tmdb/Model/Tv/Episode.php index 31c76edc..2efaec8b 100644 --- a/lib/Tmdb/Model/Tv/Episode.php +++ b/lib/Tmdb/Model/Tv/Episode.php @@ -18,7 +18,6 @@ use Tmdb\Model\Collection\Images; use Tmdb\Model\Collection\Videos; use Tmdb\Model\Common\ExternalIds; -use Tmdb\Model\Common\Video; use Tmdb\Model\Image\StillImage; /** @@ -424,7 +423,7 @@ public function setVideos($videos) } /** - * @return Videos|Video[] + * @return Videos */ public function getVideos() { diff --git a/lib/Tmdb/Model/Tv/Season.php b/lib/Tmdb/Model/Tv/Season.php index 140efc6c..9df86f18 100644 --- a/lib/Tmdb/Model/Tv/Season.php +++ b/lib/Tmdb/Model/Tv/Season.php @@ -19,7 +19,6 @@ use Tmdb\Model\Collection\Videos; use Tmdb\Model\Common\ExternalIds; use Tmdb\Model\Common\GenericCollection; -use Tmdb\Model\Common\Video; use Tmdb\Model\Image\PosterImage; /** @@ -235,7 +234,7 @@ public function setPosterPath($posterPath) } /** - * @return \Tmdb\Model\Tv\Image + * @return string */ public function getPosterPath() { @@ -349,7 +348,7 @@ public function setVideos($videos) } /** - * @return Videos|Video[] + * @return Videos */ public function getVideos() { diff --git a/lib/Tmdb/Repository/AccountRepository.php b/lib/Tmdb/Repository/AccountRepository.php index ae895f67..d3c6798a 100644 --- a/lib/Tmdb/Repository/AccountRepository.php +++ b/lib/Tmdb/Repository/AccountRepository.php @@ -28,7 +28,7 @@ class AccountRepository extends AbstractRepository * Get the basic information for an account. * You will need to have a valid session id. * - * @return null|\Tmdb\Model\AbstractModel + * @return \Tmdb\Model\Account */ public function getAccount() { @@ -85,10 +85,10 @@ public function getFavoriteTvShows($accountId, array $parameters = array(), arra /** * Add or remove a movie to an accounts favorite list. * - * @param string $accountId - * @param int|Movie|Tv $media - * @param boolean $isFavorite - * @return ResultCollection + * @param string $accountId + * @param int|Movie|Tv $media + * @param boolean $isFavorite + * @return \Tmdb\Model\Lists\Result */ public function favorite($accountId, $media, $isFavorite = true) { diff --git a/lib/Tmdb/Repository/AuthenticationRepository.php b/lib/Tmdb/Repository/AuthenticationRepository.php index 43819581..266f8ee5 100644 --- a/lib/Tmdb/Repository/AuthenticationRepository.php +++ b/lib/Tmdb/Repository/AuthenticationRepository.php @@ -43,8 +43,8 @@ public function getRequestToken() * This method is used to generate a session id for user based authentication. * A session id is required in order to use any of the write methods. * - * @param RequestToken $requestToken - * @return RequestToken + * @param RequestToken $requestToken + * @return \Tmdb\SessionToken */ public function getSessionToken(RequestToken $requestToken) { @@ -61,7 +61,7 @@ public function getSessionToken(RequestToken $requestToken) * @param string $username * @param string $password * @throws UnauthorizedRequestTokenException - * @return mixed + * @return RequestToken */ public function validateRequestTokenWithLogin(RequestToken $requestToken, $username, $password) { @@ -82,7 +82,7 @@ public function validateRequestTokenWithLogin(RequestToken $requestToken, $usern * @param string $username * @param string $password * @throws UnauthorizedRequestTokenException - * @return mixed + * @return \Tmdb\SessionToken */ public function getSessionTokenWithLogin(RequestToken $requestToken, $username, $password) { @@ -108,7 +108,7 @@ public function getSessionTokenWithLogin(RequestToken $requestToken, $username, * If a guest session is not used for the first time within 24 hours, * it will be automatically discarded. * - * @return RequestToken + * @return \Tmdb\GuestSessionToken */ public function getGuestSessionToken() { diff --git a/lib/Tmdb/Repository/CertificationRepository.php b/lib/Tmdb/Repository/CertificationRepository.php index 8738535f..80f185c8 100644 --- a/lib/Tmdb/Repository/CertificationRepository.php +++ b/lib/Tmdb/Repository/CertificationRepository.php @@ -29,7 +29,7 @@ class CertificationRepository extends AbstractRepository * * @param $parameters * @param $headers - * @return null|\Tmdb\Model\AbstractModel + * @return \Tmdb\Model\Common\GenericCollection */ public function getMovieList(array $parameters = array(), array $headers = array()) { diff --git a/lib/Tmdb/Repository/CompanyRepository.php b/lib/Tmdb/Repository/CompanyRepository.php index a7538250..2f650137 100644 --- a/lib/Tmdb/Repository/CompanyRepository.php +++ b/lib/Tmdb/Repository/CompanyRepository.php @@ -15,9 +15,7 @@ use Tmdb\Factory\CompanyFactory; use Tmdb\Factory\MovieFactory; use Tmdb\Model\Collection\ResultCollection; -use Tmdb\Model\Common\GenericCollection; use Tmdb\Model\Company; -use Tmdb\Model\Movie; /** * Class CompanyRepository @@ -44,10 +42,10 @@ public function load($id, array $parameters = array(), array $headers = array()) /** * Get the list of movies associated with a particular company. * - * @param integer $id - * @param array $parameters - * @param array $headers - * @return GenericCollection|Movie[] + * @param integer $id + * @param array $parameters + * @param array $headers + * @return ResultCollection */ public function getMovies($id, array $parameters = array(), array $headers = array()) { @@ -86,7 +84,7 @@ public function getMovieFactory() * Create an collection of an array * * @param $data - * @return Movie[] + * @return ResultCollection */ public function createMovieCollection($data) { diff --git a/lib/Tmdb/Repository/CreditsRepository.php b/lib/Tmdb/Repository/CreditsRepository.php index 63c79688..e68c4e3e 100644 --- a/lib/Tmdb/Repository/CreditsRepository.php +++ b/lib/Tmdb/Repository/CreditsRepository.php @@ -12,9 +12,7 @@ */ namespace Tmdb\Repository; -use Tmdb\Factory\CompanyFactory; use Tmdb\Factory\CreditsFactory; -use Tmdb\Model\Company; /** * Class CreditsRepository @@ -49,7 +47,7 @@ public function getApi() } /** - * @return CompanyFactory + * @return CreditsFactory */ public function getFactory() { diff --git a/lib/Tmdb/Repository/DiscoverRepository.php b/lib/Tmdb/Repository/DiscoverRepository.php index 6d7ec6c6..f9804677 100644 --- a/lib/Tmdb/Repository/DiscoverRepository.php +++ b/lib/Tmdb/Repository/DiscoverRepository.php @@ -16,10 +16,8 @@ use Tmdb\Exception\RuntimeException; use Tmdb\Factory\MovieFactory; use Tmdb\Factory\TvFactory; -use Tmdb\Model\Movie; use Tmdb\Model\Query\Discover\DiscoverMoviesQuery; use Tmdb\Model\Query\Discover\DiscoverTvQuery; -use Tmdb\Model\Tv; /** * Class DiscoverRepository @@ -56,10 +54,9 @@ public function discoverMovies(DiscoverMoviesQuery $query, array $headers = arra * Discover TV shows by different types of data like average rating, * number of votes, genres, the network they aired on and air dates. * - * @param DiscoverTvQuery $query - * @param array $headers + * @param DiscoverTvQuery $query + * @param array $headers * @return Tv[] - * @return \Tmdb\Model\Common\GenericCollection */ public function discoverTv(DiscoverTvQuery $query, array $headers = array()) { diff --git a/lib/Tmdb/Repository/GenreRepository.php b/lib/Tmdb/Repository/GenreRepository.php index 96e171a2..04b9196c 100644 --- a/lib/Tmdb/Repository/GenreRepository.php +++ b/lib/Tmdb/Repository/GenreRepository.php @@ -56,8 +56,8 @@ public function loadCollection(array $parameters = array(), array $headers = arr * * @param $id * @param array $parameters - * @param array $headers * @return Genre[] + * @param array $headers */ public function getMovies($id, array $parameters = array(), array $headers = array()) { @@ -71,7 +71,7 @@ public function getMovies($id, array $parameters = array(), array $headers = arr * Create an collection of an array * * @param $data - * @return GenericCollection|Genre[] + * @return \Tmdb\Model\Collection\Genres */ private function createCollection($data) { diff --git a/lib/Tmdb/Repository/MovieRepository.php b/lib/Tmdb/Repository/MovieRepository.php index f84e7ba6..7c67f018 100644 --- a/lib/Tmdb/Repository/MovieRepository.php +++ b/lib/Tmdb/Repository/MovieRepository.php @@ -420,7 +420,7 @@ public function setAlternativeTitleFactory($alternativeTitleFactory) } /** - * @return mixed + * @return AlternativeTitleFactory */ public function getAlternativeTitleFactory() { @@ -439,7 +439,7 @@ public function setImageFactory($imageFactory) } /** - * @return mixed + * @return ImageFactory */ public function getImageFactory() { @@ -458,7 +458,7 @@ public function setPeopleFactory($peopleFactory) } /** - * @return mixed + * @return PeopleFactory */ public function getPeopleFactory() { diff --git a/lib/Tmdb/Repository/PeopleRepository.php b/lib/Tmdb/Repository/PeopleRepository.php index 7e9080d6..0f7b7add 100644 --- a/lib/Tmdb/Repository/PeopleRepository.php +++ b/lib/Tmdb/Repository/PeopleRepository.php @@ -62,7 +62,7 @@ public function load($id, array $parameters = array(), array $headers = array()) * @param $id * @param $parameters * @param $headers - * @return null|\Tmdb\Model\AbstractModel + * @return \Tmdb\Model\Collection\CreditsCollection\MovieCredits */ public function getMovieCredits($id, array $parameters = array(), array $headers = array()) { @@ -83,7 +83,7 @@ public function getMovieCredits($id, array $parameters = array(), array $headers * @param $id * @param $parameters * @param $headers - * @return null|\Tmdb\Model\AbstractModel + * @return \Tmdb\Model\Collection\CreditsCollection\TvCredits */ public function getTvCredits($id, array $parameters = array(), array $headers = array()) { @@ -104,7 +104,7 @@ public function getTvCredits($id, array $parameters = array(), array $headers = * @param $id * @param $parameters * @param $headers - * @return null|\Tmdb\Model\AbstractModel + * @return \Tmdb\Model\Collection\CreditsCollection\CombinedCredits */ public function getCombinedCredits($id, array $parameters = array(), array $headers = array()) { @@ -118,7 +118,7 @@ public function getCombinedCredits($id, array $parameters = array(), array $head * Get the external ids for a specific person id. * * @param $id - * @return null|\Tmdb\Model\AbstractModel + * @return \Tmdb\Model\Common\ExternalIds */ public function getExternalIds($id) { @@ -132,7 +132,7 @@ public function getExternalIds($id) * Get the images for a specific person id. * * @param $id - * @return null|\Tmdb\Model\AbstractModel + * @return \Tmdb\Model\Collection\Images */ public function getImages($id) { @@ -152,9 +152,9 @@ public function getImages($id) * The language is present on fields that are translatable. * * @param $id - * @param array $parameters - * @param array $headers - * @return null|\Tmdb\Model\AbstractModel + * @param array $parameters + * @param array $headers + * @return \Tmdb\Model\Common\GenericCollection */ public function getChanges($id, array $parameters = array(), array $headers = array()) { @@ -174,9 +174,9 @@ public function getChanges($id, array $parameters = array(), array $headers = ar * The language is present on fields that are translatable. * * @param $id - * @param array $parameters - * @param array $headers - * @return null|\Tmdb\Model\AbstractModel + * @param array $parameters + * @param array $headers + * @return \Tmdb\Model\Collection\ResultCollection */ public function getTaggedImages($id, array $parameters = array(), array $headers = array()) { @@ -192,9 +192,9 @@ public function getTaggedImages($id, array $parameters = array(), array $headers * * This list refreshes every day. * - * @param array $parameters - * @param array $headers - * @return null|\Tmdb\Model\AbstractModel + * @param array $parameters + * @param array $headers + * @return \Tmdb\Model\Collection\ResultCollection */ public function getPopular(array $parameters = array(), array $headers = array()) { @@ -206,7 +206,7 @@ public function getPopular(array $parameters = array(), array $headers = array() /** * Get the latest person id. * - * @return null|\Tmdb\Model\AbstractModel + * @return Person */ public function getLatest() { diff --git a/lib/Tmdb/Repository/SearchRepository.php b/lib/Tmdb/Repository/SearchRepository.php index 3386587b..d17bd1b7 100644 --- a/lib/Tmdb/Repository/SearchRepository.php +++ b/lib/Tmdb/Repository/SearchRepository.php @@ -12,7 +12,6 @@ */ namespace Tmdb\Repository; -use Guzzle\Common\Exception\RuntimeException; use Tmdb\Client; use Tmdb\Exception\NotImplementedException; use Tmdb\Factory\CollectionFactory; @@ -23,7 +22,6 @@ use Tmdb\Factory\PeopleFactory; use Tmdb\Factory\TvFactory; use Tmdb\Model\Collection\ResultCollection; -use Tmdb\Model\Collection; use Tmdb\Model\Company; use Tmdb\Model\Keyword; use Tmdb\Model\Movie; @@ -112,7 +110,7 @@ public function searchMovie($query, MovieSearchQuery $parameters, array $headers * @param CollectionSearchQuery $parameters * @param array $headers * - * @return ResultCollection|Collection[] + * @return ResultCollection[] */ public function searchCollection($query, CollectionSearchQuery $parameters, array $headers = array()) { diff --git a/lib/Tmdb/Repository/TvSeasonRepository.php b/lib/Tmdb/Repository/TvSeasonRepository.php index 7937ea95..4ecd3936 100644 --- a/lib/Tmdb/Repository/TvSeasonRepository.php +++ b/lib/Tmdb/Repository/TvSeasonRepository.php @@ -14,7 +14,6 @@ use Tmdb\Exception\RuntimeException; use Tmdb\Factory\TvSeasonFactory; - use Tmdb\Model\Collection\Videos; use Tmdb\Model\Common\Video; use \Tmdb\Model\Tv\Season\QueryParameter\AppendToResponse; diff --git a/lib/Tmdb/RequestToken.php b/lib/Tmdb/RequestToken.php index f791a8a0..025041d7 100644 --- a/lib/Tmdb/RequestToken.php +++ b/lib/Tmdb/RequestToken.php @@ -59,7 +59,7 @@ public function setToken($token) } /** - * @return null + * @return string */ public function getToken() { @@ -67,7 +67,7 @@ public function getToken() } /** - * @param mixed $expiresAt + * @param \DateTime $expiresAt * @return $this */ public function setExpiresAt($expiresAt) @@ -82,7 +82,7 @@ public function setExpiresAt($expiresAt) } /** - * @return mixed + * @return \DateTime */ public function getExpiresAt() { diff --git a/lib/Tmdb/SessionToken.php b/lib/Tmdb/SessionToken.php index 2bfe3a01..8cc5ee10 100644 --- a/lib/Tmdb/SessionToken.php +++ b/lib/Tmdb/SessionToken.php @@ -55,7 +55,7 @@ public function setToken($sessionToken) } /** - * @return null + * @return string */ public function getToken() { @@ -97,7 +97,7 @@ public function setSuccess($success) } /** - * @return mixed + * @return boolean */ public function getSuccess() { From e1f97c98be86a502a7f0c60eca6be38d461a8997 Mon Sep 17 00:00:00 2001 From: Michael Roterman Date: Sat, 12 Jul 2014 15:10:10 +0200 Subject: [PATCH 11/19] More fixes and moving some classes up to common. --- lib/Tmdb/Factory/AbstractFactory.php | 32 +++++++++++++++++++ lib/Tmdb/Factory/ImageFactory.php | 6 ++-- lib/Tmdb/Factory/MovieFactory.php | 30 ----------------- .../Model/{Movie => Common}/AccountStates.php | 12 +++++-- lib/Tmdb/Model/{Movie => Common}/Rating.php | 2 +- lib/Tmdb/Model/Movie.php | 2 +- lib/Tmdb/Model/Tv.php | 5 +-- test/Tmdb/Tests/Model/TvTest.php | 6 ++-- 8 files changed, 50 insertions(+), 45 deletions(-) rename lib/Tmdb/Model/{Movie => Common}/AccountStates.php (91%) rename lib/Tmdb/Model/{Movie => Common}/Rating.php (96%) diff --git a/lib/Tmdb/Factory/AbstractFactory.php b/lib/Tmdb/Factory/AbstractFactory.php index ccb62a4b..dc8bf7fd 100644 --- a/lib/Tmdb/Factory/AbstractFactory.php +++ b/lib/Tmdb/Factory/AbstractFactory.php @@ -15,7 +15,9 @@ use Tmdb\Common\ObjectHydrator; use Tmdb\Model\AbstractModel; use Tmdb\Model\Collection\ResultCollection; +use Tmdb\Model\Common\AccountStates; use Tmdb\Model\Common\GenericCollection; +use Tmdb\Model\Common\Rating; /** * Class AbstractFactory @@ -128,6 +130,36 @@ protected function createCustomCollection($data = array(), $class, $collection) return $collection; } + /** + * Create rating + * + * @param array $data + * @return \Tmdb\Model\AbstractModel + */ + public function createRating(array $data = array()) + { + return $this->hydrate(new Rating(), $data); + } + + /** + * Create the account states + * + * @param array $data + * @return \Tmdb\Model\AbstractModel + */ + public function createAccountStates(array $data = array()) + { + $accountStates = new AccountStates(); + + if (array_key_exists('rated', $data)) { + $rating = new Rating(); + + $accountStates->setRated($this->hydrate($rating, $data['rated'])); + } + + return $this->hydrate($accountStates, $data); + } + /** * Hydrate the object with data * diff --git a/lib/Tmdb/Factory/ImageFactory.php b/lib/Tmdb/Factory/ImageFactory.php index 0c64e61f..35a95db4 100644 --- a/lib/Tmdb/Factory/ImageFactory.php +++ b/lib/Tmdb/Factory/ImageFactory.php @@ -57,13 +57,12 @@ public function createFromPath($path, $key) * Create an Media/Image type which is used in calls like person/tagged_images, which contains an getMedia() * reference either referring to movies / tv shows etc. * - * @param array $data - * @param string|null $key + * @param array $data * @return Image * * @throws \RuntimeException */ - public function createMediaImage(array $data = array(), $key = null) + public function createMediaImage(array $data = array()) { if (!array_key_exists('image_type', $data)) { throw new \RuntimeException('Unable to detect the image type.'); @@ -71,7 +70,6 @@ public function createMediaImage(array $data = array(), $key = null) $type = $this->resolveImageType($data['image_type']); $image = $this->hydrate($type, $data); - $media = null; if (array_key_exists('media', $data) && array_key_exists('media_type', $data)) { switch ($data['media_type']) { diff --git a/lib/Tmdb/Factory/MovieFactory.php b/lib/Tmdb/Factory/MovieFactory.php index 44e87388..f43a89ba 100644 --- a/lib/Tmdb/Factory/MovieFactory.php +++ b/lib/Tmdb/Factory/MovieFactory.php @@ -205,36 +205,6 @@ public function createResult(array $data = array()) return $this->hydrate(new Result(), $data); } - /** - * Create rating - * - * @param array $data - * @return \Tmdb\Model\AbstractModel - */ - public function createRating(array $data = array()) - { - return $this->hydrate(new Movie\Rating(), $data); - } - - /** - * Create the account states - * - * @param array $data - * @return \Tmdb\Model\AbstractModel - */ - public function createAccountStates(array $data = array()) - { - $accountStates = new Movie\AccountStates(); - - if (array_key_exists('rated', $data)) { - $rating = new Movie\Rating(); - - $accountStates->setRated($this->hydrate($rating, $data['rated'])); - } - - return $this->hydrate($accountStates, $data); - } - /** * @param \Tmdb\Factory\People\CastFactory $castFactory * @return $this diff --git a/lib/Tmdb/Model/Movie/AccountStates.php b/lib/Tmdb/Model/Common/AccountStates.php similarity index 91% rename from lib/Tmdb/Model/Movie/AccountStates.php rename to lib/Tmdb/Model/Common/AccountStates.php index 6d64bcc9..23d9dfff 100644 --- a/lib/Tmdb/Model/Movie/AccountStates.php +++ b/lib/Tmdb/Model/Common/AccountStates.php @@ -10,13 +10,13 @@ * @copyright (c) 2013, Michael Roterman * @version 0.0.1 */ -namespace Tmdb\Model\Movie; +namespace Tmdb\Model\Common; use Tmdb\Model\AbstractModel; /** * Class AccountStates - * @package Tmdb\Model\Movie + * @package Tmdb\Model\Common */ class AccountStates extends AbstractModel { @@ -46,6 +46,14 @@ class AccountStates extends AbstractModel 'watchlist', ); + /** + * Constructor + */ + public function __construct() + { + $this->rated = new Rating(); + } + /** * @param boolean $favorite * @return $this diff --git a/lib/Tmdb/Model/Movie/Rating.php b/lib/Tmdb/Model/Common/Rating.php similarity index 96% rename from lib/Tmdb/Model/Movie/Rating.php rename to lib/Tmdb/Model/Common/Rating.php index 71af8de6..46eaf002 100644 --- a/lib/Tmdb/Model/Movie/Rating.php +++ b/lib/Tmdb/Model/Common/Rating.php @@ -10,7 +10,7 @@ * @copyright (c) 2013, Michael Roterman * @version 0.0.1 */ -namespace Tmdb\Model\Movie; +namespace Tmdb\Model\Common; use Tmdb\Model\AbstractModel; diff --git a/lib/Tmdb/Model/Movie.php b/lib/Tmdb/Model/Movie.php index 41734f71..563d8ed3 100644 --- a/lib/Tmdb/Model/Movie.php +++ b/lib/Tmdb/Model/Movie.php @@ -457,7 +457,7 @@ public function getOriginalTitle() } /** - * @param mixed $overview + * @param string $overview * @return $this */ public function setOverview($overview) diff --git a/lib/Tmdb/Model/Tv.php b/lib/Tmdb/Model/Tv.php index 501a9fbf..d1213eb3 100644 --- a/lib/Tmdb/Model/Tv.php +++ b/lib/Tmdb/Model/Tv.php @@ -85,7 +85,7 @@ class Tv extends AbstractModel private $name; /** - * @var Network[] + * @var GenericCollection|Network[] */ private $networks; @@ -237,10 +237,7 @@ class Tv extends AbstractModel */ public function __construct() { - $this->createdBy = new Images(); - $this->episodeRunTime = new GenericCollection(); $this->genres = new Genres(); - $this->languages = new GenericCollection(); $this->networks = new GenericCollection(); $this->originCountry = new GenericCollection(); $this->seasons = new GenericCollection(); diff --git a/test/Tmdb/Tests/Model/TvTest.php b/test/Tmdb/Tests/Model/TvTest.php index d44c82ab..62660eb7 100644 --- a/test/Tmdb/Tests/Model/TvTest.php +++ b/test/Tmdb/Tests/Model/TvTest.php @@ -26,10 +26,10 @@ public function shouldConstructMovie() $this->assertInstancesOf( $tv, array( - 'getCreatedBy' => 'Tmdb\Model\Collection\Images', - 'getEpisodeRuntime' => 'Tmdb\Model\Common\GenericCollection', +// 'getCreatedBy' => 'Tmdb\Model\Collection\Images', +// 'getEpisodeRuntime' => 'Tmdb\Model\Common\GenericCollection', 'getGenres' => 'Tmdb\Model\Collection\Genres', - 'getLanguages' => 'Tmdb\Model\Common\GenericCollection', +// 'getLanguages' => 'Tmdb\Model\Common\GenericCollection', 'getNetworks' => 'Tmdb\Model\Common\GenericCollection', 'getOriginCountry' => 'Tmdb\Model\Common\GenericCollection', 'getSeasons' => 'Tmdb\Model\Common\GenericCollection', From d4b5d9946a3c1287a544c8b63efadeef5be2c899 Mon Sep 17 00:00:00 2001 From: Michael Roterman Date: Sat, 12 Jul 2014 15:21:56 +0200 Subject: [PATCH 12/19] Adding account_states and rate for TV shows. --- examples/tv/api/tv/account_states.php | 24 +++++++++++++++++++++++ examples/tv/api/tv/rate.php | 25 ++++++++++++++++++++++++ lib/Tmdb/Api/Tv.php | 28 +++++++++++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 examples/tv/api/tv/account_states.php create mode 100644 examples/tv/api/tv/rate.php diff --git a/examples/tv/api/tv/account_states.php b/examples/tv/api/tv/account_states.php new file mode 100644 index 00000000..6f04d0c0 --- /dev/null +++ b/examples/tv/api/tv/account_states.php @@ -0,0 +1,24 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +require_once '../../../../vendor/autoload.php'; +require_once '../../../../apikey.php'; + +$token = new \Tmdb\ApiToken(TMDB_API_KEY); +$client = new \Tmdb\Client($token); + +$sessionToken = new \Tmdb\SessionToken(TMDB_SESSION_TOKEN); +$client->setSessionToken($sessionToken); + +$result = $client->getTvApi()->getAccountStates(1396); + +var_dump($result); diff --git a/examples/tv/api/tv/rate.php b/examples/tv/api/tv/rate.php new file mode 100644 index 00000000..04fe97d7 --- /dev/null +++ b/examples/tv/api/tv/rate.php @@ -0,0 +1,25 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +ini_set('display_errors', 'On'); +require_once '../../../../vendor/autoload.php'; +require_once '../../../../apikey.php'; + +$token = new \Tmdb\ApiToken(TMDB_API_KEY); +$client = new \Tmdb\Client($token); + +$sessionToken = new \Tmdb\SessionToken(TMDB_SESSION_TOKEN); +$client->setSessionToken($sessionToken); + +$result = $client->getTvApi()->rateTvShow(1396, 9.5); + +var_dump($result); diff --git a/lib/Tmdb/Api/Tv.php b/lib/Tmdb/Api/Tv.php index af809291..8290d637 100644 --- a/lib/Tmdb/Api/Tv.php +++ b/lib/Tmdb/Api/Tv.php @@ -216,4 +216,32 @@ public function getSimilar($tvshow_id, array $parameters = array(), array $heade { return $this->get('tv/' . $tvshow_id . '/similar', $parameters, $headers); } + + /** + * This method lets users get the status of whether or not the TV show has been rated + * or added to their favourite or watch lists. + * + * A valid session id is required. + * + * @param integer $id + * @return mixed + */ + public function getAccountStates($id) + { + return $this->get('tv/' . $id . '/account_states'); + } + + /** + * This method lets users rate a TV show. + * + * A valid session id or guest session id is required. + * + * @param integer $id + * @param double $rating + * @return mixed + */ + public function rateTvShow($id, $rating) + { + return $this->postJson('tv/' . $id . '/rating', array('value' => (float) $rating)); + } } From 312195ceb7cf42f43f91f1749340e7c2c6f64425 Mon Sep 17 00:00:00 2001 From: Michael Roterman Date: Sat, 12 Jul 2014 15:30:39 +0200 Subject: [PATCH 13/19] Implementing model side for the account_states and rate methods --- examples/tv/model/tv/account_states.php | 25 +++++++++++++++++ examples/tv/model/tv/rate.php | 26 ++++++++++++++++++ lib/Tmdb/Factory/AbstractFactory.php | 12 +++++++++ lib/Tmdb/Factory/MovieFactory.php | 12 --------- lib/Tmdb/Repository/TvRepository.php | 36 ++++++++++++++++++++++++- 5 files changed, 98 insertions(+), 13 deletions(-) create mode 100644 examples/tv/model/tv/account_states.php create mode 100644 examples/tv/model/tv/rate.php diff --git a/examples/tv/model/tv/account_states.php b/examples/tv/model/tv/account_states.php new file mode 100644 index 00000000..25b56a67 --- /dev/null +++ b/examples/tv/model/tv/account_states.php @@ -0,0 +1,25 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +require_once '../../../../vendor/autoload.php'; +require_once '../../../../apikey.php'; + +$token = new \Tmdb\ApiToken(TMDB_API_KEY); +$client = new \Tmdb\Client($token); + +$sessionToken = new \Tmdb\SessionToken(TMDB_SESSION_TOKEN); +$client->setSessionToken($sessionToken); + +$repository = new \Tmdb\Repository\TvRepository($client); +$tvShow = $repository->getAccountStates(1396); + +var_dump($tvShow); diff --git a/examples/tv/model/tv/rate.php b/examples/tv/model/tv/rate.php new file mode 100644 index 00000000..b30060d0 --- /dev/null +++ b/examples/tv/model/tv/rate.php @@ -0,0 +1,26 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +ini_set('display_errors','on'); +require_once '../../../../vendor/autoload.php'; +require_once '../../../../apikey.php'; + +$token = new \Tmdb\ApiToken(TMDB_API_KEY); +$client = new \Tmdb\Client($token); + +$sessionToken = new \Tmdb\SessionToken(TMDB_SESSION_TOKEN); +$client->setSessionToken($sessionToken); + +$repository = new \Tmdb\Repository\TvRepository($client); +$rate = $repository->rate(1396, 9.5); + +var_dump($rate); diff --git a/lib/Tmdb/Factory/AbstractFactory.php b/lib/Tmdb/Factory/AbstractFactory.php index dc8bf7fd..dc8c4fe6 100644 --- a/lib/Tmdb/Factory/AbstractFactory.php +++ b/lib/Tmdb/Factory/AbstractFactory.php @@ -18,6 +18,7 @@ use Tmdb\Model\Common\AccountStates; use Tmdb\Model\Common\GenericCollection; use Tmdb\Model\Common\Rating; +use Tmdb\Model\Lists\Result; /** * Class AbstractFactory @@ -160,6 +161,17 @@ public function createAccountStates(array $data = array()) return $this->hydrate($accountStates, $data); } + /** + * Create result + * + * @param array $data + * @return \Tmdb\Model\AbstractModel + */ + public function createResult(array $data = array()) + { + return $this->hydrate(new Result(), $data); + } + /** * Hydrate the object with data * diff --git a/lib/Tmdb/Factory/MovieFactory.php b/lib/Tmdb/Factory/MovieFactory.php index f43a89ba..bce9d883 100644 --- a/lib/Tmdb/Factory/MovieFactory.php +++ b/lib/Tmdb/Factory/MovieFactory.php @@ -19,7 +19,6 @@ use Tmdb\Factory\People\CrewFactory; use Tmdb\Model\Common\GenericCollection; use Tmdb\Model\Common\Translation; -use Tmdb\Model\Lists\Result; use Tmdb\Model\Movie; /** @@ -194,17 +193,6 @@ public function createCollection(array $data = array()) return $collection; } - /** - * Create result - * - * @param array $data - * @return \Tmdb\Model\AbstractModel - */ - public function createResult(array $data = array()) - { - return $this->hydrate(new Result(), $data); - } - /** * @param \Tmdb\Factory\People\CastFactory $castFactory * @return $this diff --git a/lib/Tmdb/Repository/TvRepository.php b/lib/Tmdb/Repository/TvRepository.php index cc79b1e7..d20b68c6 100644 --- a/lib/Tmdb/Repository/TvRepository.php +++ b/lib/Tmdb/Repository/TvRepository.php @@ -14,7 +14,9 @@ use Tmdb\Factory\TvFactory; use Tmdb\Model\Collection\Videos; +use Tmdb\Model\Common\AccountStates; use Tmdb\Model\Common\Video; +use Tmdb\Model\Lists\Result; use Tmdb\Model\Tv; use Tmdb\Model\Tv\QueryParameter\AppendToResponse; @@ -223,7 +225,7 @@ public function getAiringToday(array $options = array(), array $headers = array( /** * Get the latest tv-show. * - * @param array $options + * @param array $options * @return null|\Tmdb\Model\AbstractModel */ public function getLatest(array $options = array()) @@ -232,4 +234,36 @@ public function getLatest(array $options = array()) $this->getApi()->getLatest($options) ); } + + /** + * This method lets users get the status of whether or not the TV show has been rated + * or added to their favourite or watch lists. + * + * A valid session id is required. + * + * @param integer $id + * @return AccountStates + */ + public function getAccountStates($id) + { + return $this->getFactory()->createAccountStates( + $this->getApi()->getAccountStates($id) + ); + } + + /** + * This method lets users rate a TV show. + * + * A valid session id or guest session id is required. + * + * @param integer $id + * @param float $rating + * @return Result + */ + public function rate($id, $rating) + { + return $this->getFactory()->createResult( + $this->getApi()->rateTvShow($id, $rating) + ); + } } From 49ef0264fdd568b58535fcf9df418719c0d1e9ef Mon Sep 17 00:00:00 2001 From: Michael Roterman Date: Sat, 12 Jul 2014 16:08:30 +0200 Subject: [PATCH 14/19] Adding episode level account_states and rating --- examples/tv/api/episode/account_states.php | 24 +++++++++ examples/tv/api/episode/rate.php | 25 +++++++++ examples/tv/model/episode/account_states.php | 25 +++++++++ examples/tv/model/episode/rate.php | 26 +++++++++ lib/Tmdb/Api/TvEpisode.php | 55 ++++++++++++++++++++ lib/Tmdb/Repository/TvEpisodeRepository.php | 34 ++++++++++++ 6 files changed, 189 insertions(+) create mode 100644 examples/tv/api/episode/account_states.php create mode 100644 examples/tv/api/episode/rate.php create mode 100644 examples/tv/model/episode/account_states.php create mode 100644 examples/tv/model/episode/rate.php diff --git a/examples/tv/api/episode/account_states.php b/examples/tv/api/episode/account_states.php new file mode 100644 index 00000000..f34fc976 --- /dev/null +++ b/examples/tv/api/episode/account_states.php @@ -0,0 +1,24 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +require_once '../../../../vendor/autoload.php'; +require_once '../../../../apikey.php'; + +$token = new \Tmdb\ApiToken(TMDB_API_KEY); +$client = new \Tmdb\Client($token); + +$sessionToken = new \Tmdb\SessionToken(TMDB_SESSION_TOKEN); +$client->setSessionToken($sessionToken); + +$result = $client->getTvApi()->getAccountStates(1396, 1, 1); + +var_dump($result); diff --git a/examples/tv/api/episode/rate.php b/examples/tv/api/episode/rate.php new file mode 100644 index 00000000..d626ae46 --- /dev/null +++ b/examples/tv/api/episode/rate.php @@ -0,0 +1,25 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +ini_set('display_errors', 'On'); +require_once '../../../../vendor/autoload.php'; +require_once '../../../../apikey.php'; + +$token = new \Tmdb\ApiToken(TMDB_API_KEY); +$client = new \Tmdb\Client($token); + +$sessionToken = new \Tmdb\SessionToken(TMDB_SESSION_TOKEN); +$client->setSessionToken($sessionToken); + +$result = $client->getTvApi()->rateTvShow(1396, 1, 1, 9.5); + +var_dump($result); diff --git a/examples/tv/model/episode/account_states.php b/examples/tv/model/episode/account_states.php new file mode 100644 index 00000000..600d3636 --- /dev/null +++ b/examples/tv/model/episode/account_states.php @@ -0,0 +1,25 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +require_once '../../../../vendor/autoload.php'; +require_once '../../../../apikey.php'; + +$token = new \Tmdb\ApiToken(TMDB_API_KEY); +$client = new \Tmdb\Client($token); + +$sessionToken = new \Tmdb\SessionToken(TMDB_SESSION_TOKEN); +$client->setSessionToken($sessionToken); + +$repository = new \Tmdb\Repository\TvEpisodeRepository($client); +$tvShow = $repository->getAccountStates(1396, 1, 1); + +var_dump($tvShow); diff --git a/examples/tv/model/episode/rate.php b/examples/tv/model/episode/rate.php new file mode 100644 index 00000000..cb7685f1 --- /dev/null +++ b/examples/tv/model/episode/rate.php @@ -0,0 +1,26 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +ini_set('display_errors','on'); +require_once '../../../../vendor/autoload.php'; +require_once '../../../../apikey.php'; + +$token = new \Tmdb\ApiToken(TMDB_API_KEY); +$client = new \Tmdb\Client($token); + +$sessionToken = new \Tmdb\SessionToken(TMDB_SESSION_TOKEN); +$client->setSessionToken($sessionToken); + +$repository = new \Tmdb\Repository\TvEpisodeRepository($client); +$rate = $repository->rate(1396, 1, 9.5); + +var_dump($rate); diff --git a/lib/Tmdb/Api/TvEpisode.php b/lib/Tmdb/Api/TvEpisode.php index 262f6007..3951e531 100644 --- a/lib/Tmdb/Api/TvEpisode.php +++ b/lib/Tmdb/Api/TvEpisode.php @@ -196,4 +196,59 @@ 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 + ) { + return $this->get( + sprintf( + 'tv/%s/season/%s/episode/%s/account_states', + $tvshow_id, + $season_number, + $episode_number + ) + ); + } + + /** + * This method lets users rate a TV episode. + * + * A valid session id or guest session id is required. + * + * @param $tvshow_id + * @param $season_number + * @param $episode_number + * @param double $rating + * + * @return mixed + */ + public function rate( + $tvshow_id, + $season_number, + $episode_number, + $rating + ) { + return $this->postJson( + sprintf( + 'tv/%s/season/%s/episode/%s/rating', + $tvshow_id, + $season_number, + $episode_number, + array('value' => (float) $rating) + ) + ); + } + } diff --git a/lib/Tmdb/Repository/TvEpisodeRepository.php b/lib/Tmdb/Repository/TvEpisodeRepository.php index d639b0e0..e74ae19b 100644 --- a/lib/Tmdb/Repository/TvEpisodeRepository.php +++ b/lib/Tmdb/Repository/TvEpisodeRepository.php @@ -15,7 +15,9 @@ use Tmdb\Exception\RuntimeException; use Tmdb\Factory\TvEpisodeFactory; use Tmdb\Model\Collection\Videos; +use Tmdb\Model\Common\AccountStates; use Tmdb\Model\Common\Video; +use Tmdb\Model\Lists\Result; use Tmdb\Model\Tv\Episode\QueryParameter\AppendToResponse; use Tmdb\Model\Tv; use Tmdb\Model\Tv\Season; @@ -232,6 +234,38 @@ public function getVideos($tvShow, $season, $episode, array $parameters = array( return $episode->getVideos(); } + /** + * This method lets users get the status of whether or not the TV show has been rated + * or added to their favourite or watch lists. + * + * A valid session id is required. + * + * @param integer $id + * @return AccountStates + */ + public function getAccountStates($id) + { + return $this->getFactory()->createAccountStates( + $this->getApi()->getAccountStates($id) + ); + } + + /** + * This method lets users rate a TV show. + * + * A valid session id or guest session id is required. + * + * @param integer $id + * @param float $rating + * @return Result + */ + public function rate($id, $rating) + { + return $this->getFactory()->createResult( + $this->getApi()->rateTvEpisode($id, $rating) + ); + } + /** * Return the Seasons API Class * From 0f50a4d7223f27552dbe378fafa1e4df03579c48 Mon Sep 17 00:00:00 2001 From: Michael Roterman Date: Sat, 12 Jul 2014 15:16:27 +0200 Subject: [PATCH 15/19] Fix docblocks --- lib/Tmdb/Api/Movies.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/Tmdb/Api/Movies.php b/lib/Tmdb/Api/Movies.php index 7f8d8928..fd76f65c 100644 --- a/lib/Tmdb/Api/Movies.php +++ b/lib/Tmdb/Api/Movies.php @@ -260,7 +260,9 @@ public function getTopRated(array $parameters = array(), array $headers = array( * or added to their favourite or watch lists. * * A valid session id is required. - * @param integer $id + * + * @param integer $id + * @return mixed */ public function getAccountStates($id) { @@ -271,8 +273,10 @@ public function getAccountStates($id) * TThis method lets users rate a movie. * * A valid session id or guest session id is required. - * @param integer $id - * @param double $rating + * + * @param integer $id + * @param double $rating + * @return mixed */ public function rateMovie($id, $rating) { From d5c39a0fa2089645d68bd29000a226511e0010a2 Mon Sep 17 00:00:00 2001 From: Michael Roterman Date: Sat, 12 Jul 2014 16:17:30 +0200 Subject: [PATCH 16/19] Hydrate actual SpokenLanguage objects for languages in TV Shows. Fixes #36 --- lib/Tmdb/Factory/TvFactory.php | 14 ++++++++++++++ lib/Tmdb/Model/Tv.php | 1 - 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/Tmdb/Factory/TvFactory.php b/lib/Tmdb/Factory/TvFactory.php index 6afee4de..89e964fd 100644 --- a/lib/Tmdb/Factory/TvFactory.php +++ b/lib/Tmdb/Factory/TvFactory.php @@ -17,6 +17,7 @@ use Tmdb\Factory\People\CastFactory; use Tmdb\Factory\People\CrewFactory; use Tmdb\Model\Common\GenericCollection; +use Tmdb\Model\Common\SpokenLanguage; use Tmdb\Model\Common\Translation; use Tmdb\Model\Person\CastMember; use Tmdb\Model\Person\CrewMember; @@ -194,6 +195,19 @@ public function create(array $data = array()) $tvShow->setSimilar($this->createResultCollection($data['similar'])); } + if (array_key_exists('languages', $data)) { + $collection = new GenericCollection(); + + foreach ($data['languages'] as $iso6391) { + $object = new SpokenLanguage(); + $object->setIso6391($iso6391); + + $collection->add(null, $object); + } + + $tvShow->setLanguages($collection); + } + return $this->hydrate($tvShow, $data); } diff --git a/lib/Tmdb/Model/Tv.php b/lib/Tmdb/Model/Tv.php index d1213eb3..e9e946a6 100644 --- a/lib/Tmdb/Model/Tv.php +++ b/lib/Tmdb/Model/Tv.php @@ -215,7 +215,6 @@ class Tv extends AbstractModel 'homepage', 'id', 'in_production', - 'languages', 'last_air_date', 'name', 'number_of_episodes', From ca99da4726794d1a21512055a2b87083375d0a01 Mon Sep 17 00:00:00 2001 From: Michael Roterman Date: Sat, 12 Jul 2014 16:20:25 +0200 Subject: [PATCH 17/19] Hydrate actual Country objects for origin_country in TV Shows. Fixes #38 --- lib/Tmdb/Factory/TvFactory.php | 14 ++++++++++++++ lib/Tmdb/Model/Tv.php | 1 - 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/Tmdb/Factory/TvFactory.php b/lib/Tmdb/Factory/TvFactory.php index 89e964fd..8519add2 100644 --- a/lib/Tmdb/Factory/TvFactory.php +++ b/lib/Tmdb/Factory/TvFactory.php @@ -16,6 +16,7 @@ use Tmdb\Factory\Common\VideoFactory; use Tmdb\Factory\People\CastFactory; use Tmdb\Factory\People\CrewFactory; +use Tmdb\Model\Common\Country; use Tmdb\Model\Common\GenericCollection; use Tmdb\Model\Common\SpokenLanguage; use Tmdb\Model\Common\Translation; @@ -208,6 +209,19 @@ public function create(array $data = array()) $tvShow->setLanguages($collection); } + if (array_key_exists('origin_country', $data)) { + $collection = new GenericCollection(); + + foreach ($data['origin_country'] as $iso31661) { + $object = new Country(); + $object->setIso31661($iso31661); + + $collection->add(null, $object); + } + + $tvShow->setOriginCountry($collection); + } + return $this->hydrate($tvShow, $data); } diff --git a/lib/Tmdb/Model/Tv.php b/lib/Tmdb/Model/Tv.php index e9e946a6..66d0fdce 100644 --- a/lib/Tmdb/Model/Tv.php +++ b/lib/Tmdb/Model/Tv.php @@ -220,7 +220,6 @@ class Tv extends AbstractModel 'number_of_episodes', 'number_of_seasons', 'original_name', - 'origin_country', 'overview', 'popularity', 'poster_path', From b18e1fe07b9b8d0b782d061d8a2c6e62c7d1843d Mon Sep 17 00:00:00 2001 From: Michael Roterman Date: Sat, 12 Jul 2014 16:23:35 +0200 Subject: [PATCH 18/19] Hydrate actual CastMember objects for created_by in TV Shows. Fixes #37 --- lib/Tmdb/Factory/TvFactory.php | 13 +++++++++++++ lib/Tmdb/Model/Tv.php | 1 - 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/Tmdb/Factory/TvFactory.php b/lib/Tmdb/Factory/TvFactory.php index 8519add2..78e13a88 100644 --- a/lib/Tmdb/Factory/TvFactory.php +++ b/lib/Tmdb/Factory/TvFactory.php @@ -222,6 +222,19 @@ public function create(array $data = array()) $tvShow->setOriginCountry($collection); } + if (array_key_exists('created_by', $data)) { + $collection = new GenericCollection(); + $factory = new PeopleFactory(); + + foreach ($data['created_by'] as $castMember) { + $object = $factory->create($castMember, new CastMember()); + + $collection->add(null, $object); + } + + $tvShow->setCreatedBy($collection); + } + return $this->hydrate($tvShow, $data); } diff --git a/lib/Tmdb/Model/Tv.php b/lib/Tmdb/Model/Tv.php index 66d0fdce..4b7db5b6 100644 --- a/lib/Tmdb/Model/Tv.php +++ b/lib/Tmdb/Model/Tv.php @@ -209,7 +209,6 @@ class Tv extends AbstractModel */ public static $properties = array( 'backdrop_path', - 'created_by', 'episode_run_time', 'first_air_date', 'homepage', From cd587ecc67a2ba41383a6cb5e34818f8a67e650a Mon Sep 17 00:00:00 2001 From: Michael Roterman Date: Sun, 13 Jul 2014 20:38:09 +0200 Subject: [PATCH 19/19] Fix bug in the account_states returned value and fixing some issues with the account related functions for tv episodes. --- README.md | 1 - examples/tv/api/episode/account_states.php | 2 +- examples/tv/api/episode/rate.php | 2 +- examples/tv/model/episode/rate.php | 2 +- lib/Tmdb/Api/TvEpisode.php | 8 ++-- lib/Tmdb/Factory/AbstractFactory.php | 8 +++- lib/Tmdb/Repository/TvEpisodeRepository.php | 42 +++++++++++++++++---- 7 files changed, 48 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 982f91a8..6e5fed3f 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,6 @@ A PHP Wrapper for use with the [TMDB API](http://http://docs.themoviedb.apiary.i --------------- [![Build Status Develop Branch](https://travis-ci.org/wtfzdotnet/php-tmdb-api.png?branch=develop)](https://travis-ci.org/wtfzdotnet/php-tmdb-api) [![Code Coverage](https://scrutinizer-ci.com/g/wtfzdotnet/php-tmdb-api/badges/coverage.png?s=d416e063debb3b400e9b1bc9db019f54cc1dc40e)](https://scrutinizer-ci.com/g/wtfzdotnet/php-tmdb-api/) -[![Scrutinizer Quality Score](https://scrutinizer-ci.com/g/wtfzdotnet/php-tmdb-api/badges/quality-score.png?s=dad36710f36335bdeffeaf2ac256c222862832fa)](https://scrutinizer-ci.com/g/wtfzdotnet/php-tmdb-api/) [![License](https://poser.pugx.org/wtfzdotnet/php-tmdb-api/license.png)](https://packagist.org/packages/wtfzdotnet/php-tmdb-api) Inspired by [php-github-api](https://github.com/KnpLabs/php-github-api), [php-gitlab-api](https://github.com/m4tthumphrey/php-gitlab-api/) and the Symfony2 Community. diff --git a/examples/tv/api/episode/account_states.php b/examples/tv/api/episode/account_states.php index f34fc976..3fac86b5 100644 --- a/examples/tv/api/episode/account_states.php +++ b/examples/tv/api/episode/account_states.php @@ -19,6 +19,6 @@ $sessionToken = new \Tmdb\SessionToken(TMDB_SESSION_TOKEN); $client->setSessionToken($sessionToken); -$result = $client->getTvApi()->getAccountStates(1396, 1, 1); +$result = $client->getTvEpisodeApi()->getAccountStates(1396, 1, 1); var_dump($result); diff --git a/examples/tv/api/episode/rate.php b/examples/tv/api/episode/rate.php index d626ae46..6f4e40aa 100644 --- a/examples/tv/api/episode/rate.php +++ b/examples/tv/api/episode/rate.php @@ -20,6 +20,6 @@ $sessionToken = new \Tmdb\SessionToken(TMDB_SESSION_TOKEN); $client->setSessionToken($sessionToken); -$result = $client->getTvApi()->rateTvShow(1396, 1, 1, 9.5); +$result = $client->getTvEpisodeApi()->rateTvEpisode(1396, 1, 1, 9.5); var_dump($result); diff --git a/examples/tv/model/episode/rate.php b/examples/tv/model/episode/rate.php index cb7685f1..2b55f280 100644 --- a/examples/tv/model/episode/rate.php +++ b/examples/tv/model/episode/rate.php @@ -21,6 +21,6 @@ $client->setSessionToken($sessionToken); $repository = new \Tmdb\Repository\TvEpisodeRepository($client); -$rate = $repository->rate(1396, 1, 9.5); +$rate = $repository->rate(1396, 1, 1, 9.5); var_dump($rate); diff --git a/lib/Tmdb/Api/TvEpisode.php b/lib/Tmdb/Api/TvEpisode.php index 3951e531..fb27a400 100644 --- a/lib/Tmdb/Api/TvEpisode.php +++ b/lib/Tmdb/Api/TvEpisode.php @@ -234,7 +234,7 @@ public function getAccountStates( * * @return mixed */ - public function rate( + public function rateTvEpisode( $tvshow_id, $season_number, $episode_number, @@ -245,9 +245,9 @@ public function rate( 'tv/%s/season/%s/episode/%s/rating', $tvshow_id, $season_number, - $episode_number, - array('value' => (float) $rating) - ) + $episode_number + ), + array('value' => (float) $rating) ); } diff --git a/lib/Tmdb/Factory/AbstractFactory.php b/lib/Tmdb/Factory/AbstractFactory.php index dc8c4fe6..fa21a6f0 100644 --- a/lib/Tmdb/Factory/AbstractFactory.php +++ b/lib/Tmdb/Factory/AbstractFactory.php @@ -153,9 +153,13 @@ public function createAccountStates(array $data = array()) $accountStates = new AccountStates(); if (array_key_exists('rated', $data)) { - $rating = new Rating(); + if ($data['rated']) { + $rating = new Rating(); - $accountStates->setRated($this->hydrate($rating, $data['rated'])); + $accountStates->setRated($this->hydrate($rating, $data['rated'])); + } else { + $accountStates->setRated(false); + } } return $this->hydrate($accountStates, $data); diff --git a/lib/Tmdb/Repository/TvEpisodeRepository.php b/lib/Tmdb/Repository/TvEpisodeRepository.php index e74ae19b..086b4d21 100644 --- a/lib/Tmdb/Repository/TvEpisodeRepository.php +++ b/lib/Tmdb/Repository/TvEpisodeRepository.php @@ -240,13 +240,27 @@ public function getVideos($tvShow, $season, $episode, array $parameters = array( * * A valid session id is required. * - * @param integer $id + * @param mixed $tvShow + * @param mixed $season + * @param mixed $episode * @return AccountStates */ - public function getAccountStates($id) + public function getAccountStates($tvShow, $season, $episode) { + if ($tvShow instanceof Tv) { + $tvShow = $tvShow->getId(); + } + + if ($season instanceof Season) { + $season = $season->getId(); + } + + if ($episode instanceof Tv\Episode) { + $episode = $episode->getId(); + } + return $this->getFactory()->createAccountStates( - $this->getApi()->getAccountStates($id) + $this->getApi()->getAccountStates($tvShow, $season, $episode) ); } @@ -255,14 +269,28 @@ public function getAccountStates($id) * * A valid session id or guest session id is required. * - * @param integer $id - * @param float $rating + * @param mixed $tvShow + * @param mixed $season + * @param mixed $episode + * @param double $rating * @return Result */ - public function rate($id, $rating) + public function rate($tvShow, $season, $episode, $rating) { + if ($tvShow instanceof Tv) { + $tvShow = $tvShow->getId(); + } + + if ($season instanceof Season) { + $season = $season->getId(); + } + + if ($episode instanceof Tv\Episode) { + $episode = $episode->getId(); + } + return $this->getFactory()->createResult( - $this->getApi()->rateTvEpisode($id, $rating) + $this->getApi()->rateTvEpisode($tvShow, $season, $episode, $rating) ); }