From d634b85f4ade84e49939c40847cda9a2e643a41a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vincent=20Fali=C3=A8s?= Date: Fri, 2 Jun 2017 21:22:44 +0200 Subject: [PATCH 1/7] Refactoring itme getter and genres class to catalogs --- src/Catalog.php | 40 ++++++++++++ src/{ => Catalogs}/Genres.php | 8 +-- src/Item.php | 59 +++++++++++++++++ src/Search.php | 39 ------------ tests/{genresTest.php => catalogTest.php} | 24 +++---- tests/itemTest.php | 77 +++++++++++++++++++++++ tests/searchTest.php | 45 ------------- 7 files changed, 192 insertions(+), 100 deletions(-) create mode 100644 src/Catalog.php rename src/{ => Catalogs}/Genres.php (88%) create mode 100644 src/Item.php rename tests/{genresTest.php => catalogTest.php} (76%) create mode 100644 tests/itemTest.php diff --git a/src/Catalog.php b/src/Catalog.php new file mode 100644 index 0000000..3b9250c --- /dev/null +++ b/src/Catalog.php @@ -0,0 +1,40 @@ +tmdb = $tmdb; + } + + /** + * Get movie genres list + * @param array $options + * @return \Generator + */ + public function getMovieGenres(array $options = array()): \Generator + { + $catalog = new Catalogs\Genres($this->tmdb); + return $catalog->getMovieList($options); + } + + /** + * Get TVShow genres list + * @param array $options + * @return \Generator + */ + public function getTVShowGenres(array $options = array()): \Generator + { + $catalog = new Catalogs\Genres($this->tmdb); + return $catalog->getTVList($options); + } +} diff --git a/src/Genres.php b/src/Catalogs/Genres.php similarity index 88% rename from src/Genres.php rename to src/Catalogs/Genres.php index 56ac6f4..07915d1 100644 --- a/src/Genres.php +++ b/src/Catalogs/Genres.php @@ -1,8 +1,8 @@ tmdb = $tmdb; } @@ -63,7 +63,7 @@ private function getList(string $type, array $options): \Generator try { $params = $this->tmdb->checkOptions($options); - $response = $this->tmdb->sendRequest(new CurlRequest(), $type, null, $params); + $response = $this->tmdb->sendRequest(new \vfalies\tmdb\CurlRequest(), $type, null, $params); $genres = []; if (isset($response->genres)) diff --git a/src/Item.php b/src/Item.php new file mode 100644 index 0000000..6a8ba12 --- /dev/null +++ b/src/Item.php @@ -0,0 +1,59 @@ +tmdb = $tmdb; + } + + /** + * Get movie details + * @param int $movie_id + * @param array $options + * @return \vfalies\tmdb\Items\Movie + */ + public function getMovie(int $movie_id, array $options = array()): Items\Movie + { + $movie = new Items\Movie($this->tmdb, $movie_id, $options); + + return $movie; + } + + /** + * Get collection details + * @param int $collection_id + * @param array $options + * @return \vfalies\tmdb\Items\Collection + */ + public function getCollection(int $collection_id, array $options = array()): Items\Collection + { + $collection = new Items\Collection($this->tmdb, $collection_id, $options); + + return $collection; + } + + /** + * Get TV Show details + * @param int $tv_id + * @param array $options + * @return \vfalies\tmdb\Items\TVShow + */ + public function getTVShow(int $tv_id, array $options = array()): Items\TVShow + { + $tv = new Items\TVShow($this->tmdb, $tv_id, $options); + + return $tv; + } + + +} diff --git a/src/Search.php b/src/Search.php index 57587c0..96c8050 100644 --- a/src/Search.php +++ b/src/Search.php @@ -124,45 +124,6 @@ public function searchCollection(string $query, array $options = array()): \Gene } } - /** - * Get movie details - * @param int $movie_id - * @param array $options - * @return \vfalies\tmdb\Items\Movie - */ - public function getMovie(int $movie_id, array $options = array()): Items\Movie - { - $movie = new Items\Movie($this->tmdb, $movie_id, $options); - - return $movie; - } - - /** - * Get collection details - * @param int $collection_id - * @param array $options - * @return \vfalies\tmdb\Items\Collection - */ - public function getCollection(int $collection_id, array $options = array()): Items\Collection - { - $collection = new Items\Collection($this->tmdb, $collection_id, $options); - - return $collection; - } - - /** - * Get TV Show details - * @param int $tv_id - * @param array $options - * @return \vfalies\tmdb\Items\TVShow - */ - public function getTVShow(int $tv_id, array $options = array()): Items\TVShow - { - $tv = new Items\TVShow($this->tmdb, $tv_id, $options); - - return $tv; - } - /** * Get page from result search * @return int diff --git a/tests/genresTest.php b/tests/catalogTest.php similarity index 76% rename from tests/genresTest.php rename to tests/catalogTest.php index 588b3d8..d8e63da 100644 --- a/tests/genresTest.php +++ b/tests/catalogTest.php @@ -5,9 +5,9 @@ use PHPUnit\Framework\TestCase; /** - * @cover Genres + * @cover Catalog */ -class GenresTest extends TestCase +class CatalogTest extends TestCase { protected $tmdb = null; @@ -37,8 +37,8 @@ public function testGetMovieList() $json_object = json_decode(file_get_contents('tests/json/genresOk.json')); $this->tmdb->method('sendRequest')->willReturn($json_object); - $genres = new Genres($this->tmdb); - $list = $genres->getMovieList(array('language' => 'fr-FR')); + $genres = new Catalog($this->tmdb); + $list = $genres->getMovieGenres(array('language' => 'fr-FR')); $genre = $list->current(); @@ -54,8 +54,8 @@ public function testGetMovieListNoResult() $json_object = json_decode(file_get_contents('tests/json/genresEmptyOk.json')); $this->tmdb->method('sendRequest')->willReturn($json_object); - $genres = new Genres($this->tmdb); - $list = $genres->getMovieList(array('language' => 'fr-FR')); + $genres = new Catalog($this->tmdb); + $list = $genres->getMovieGenres(array('language' => 'fr-FR')); $genre = $list->current(); @@ -70,8 +70,8 @@ public function testGetMovieListNok() { $this->tmdb->method('sendRequest')->will($this->throwException(new \Exception())); - $genres = new Genres($this->tmdb); - $genres->getMovieList(array('language' => 'fr-FR')); + $genres = new Catalog($this->tmdb); + $genres->getMovieGenres(array('language' => 'fr-FR')); } /** @@ -82,8 +82,8 @@ public function testGetTVListNok() { $this->tmdb->method('sendRequest')->will($this->throwException(new \Exception())); - $genres = new Genres($this->tmdb); - $genres->getTVList(array('language' => 'fr-FR')); + $genres = new Catalog($this->tmdb); + $genres->getTVShowGenres(array('language' => 'fr-FR')); } /** @@ -94,8 +94,8 @@ public function testGetTVList() $json_object = json_decode(file_get_contents('tests/json/genresTVOk.json')); $this->tmdb->method('sendRequest')->willReturn($json_object); - $genres = new Genres($this->tmdb); - $list = $genres->getTVList(array('language' => 'fr-FR')); + $genres = new Catalog($this->tmdb); + $list = $genres->getTVShowGenres(array('language' => 'fr-FR')); $genre = $list->current(); diff --git a/tests/itemTest.php b/tests/itemTest.php new file mode 100644 index 0000000..5e9d19f --- /dev/null +++ b/tests/itemTest.php @@ -0,0 +1,77 @@ +tmdb = $this->getMockBuilder(Tmdb::class) + ->setConstructorArgs(array('fake_api_key')) + ->setMethods(['sendRequest']) + ->getMock(); + } + + public function tearDown() + { + parent::tearDown(); + + $this->tmdb = null; + } + + /** + * @test + */ + public function testGetMovie() + { + $json_object = json_decode(file_get_contents('tests/json/movieOk.json')); + $this->tmdb->method('sendRequest')->willReturn($json_object); + + $get = new Item($this->tmdb); + $responses = $get->getMovie(11); // Id: 11 => Star Wars + + $this->assertInstanceOf(Items\Movie::class, $responses); + $this->assertEquals(11, $responses->getId()); + } + + /** + * @test + */ + public function testGetTVShow() + { + $json_object = json_decode(file_get_contents('tests/json/TVShowOk.json')); + $this->tmdb->method('sendRequest')->willReturn($json_object); + + $get = new Item($this->tmdb); + $responses = $get->getTVShow(253); // Id: 253 => Star Trek + + $this->assertInstanceOf(Items\TVShow::class, $responses); + $this->assertEquals(253, $responses->getId()); + } + + /** + * @test + */ + public function testGetCollection() + { + $json_object = json_decode(file_get_contents('tests/json/collectionOk.json')); + $this->tmdb->method('sendRequest')->willReturn($json_object); + + $get = new Item($this->tmdb); + $responses = $get->getCollection(10); // Id: 10 => Star Wars saga + + $this->assertInstanceOf(Items\Collection::class, $responses); + $this->assertEquals(10, $responses->getId()); + } + +} diff --git a/tests/searchTest.php b/tests/searchTest.php index 8598056..aacc435 100644 --- a/tests/searchTest.php +++ b/tests/searchTest.php @@ -188,49 +188,4 @@ public function testTotalResults($search) $this->assertEquals(106, $search->getTotalResults()); } - /** - * @test - */ - public function testGetMovie() - { - $json_object = json_decode(file_get_contents('tests/json/movieOk.json')); - $this->tmdb->method('sendRequest')->willReturn($json_object); - - $search = new Search($this->tmdb); - $responses = $search->getMovie(11); // Id: 11 => Star Wars - - $this->assertInstanceOf(Items\Movie::class, $responses); - $this->assertEquals(11, $responses->getId()); - } - - /** - * @test - */ - public function testGetTVShow() - { - $json_object = json_decode(file_get_contents('tests/json/TVShowOk.json')); - $this->tmdb->method('sendRequest')->willReturn($json_object); - - $search = new Search($this->tmdb); - $responses = $search->getTVShow(253); // Id: 253 => Star Trek - - $this->assertInstanceOf(Items\TVShow::class, $responses); - $this->assertEquals(253, $responses->getId()); - } - - /** - * @test - */ - public function testGetCollection() - { - $json_object = json_decode(file_get_contents('tests/json/collectionOk.json')); - $this->tmdb->method('sendRequest')->willReturn($json_object); - - $search = new Search($this->tmdb); - $responses = $search->getCollection(10); // Id: 10 => Star Wars saga - - $this->assertInstanceOf(Items\Collection::class, $responses); - $this->assertEquals(10, $responses->getId()); - } - } From f51eec5a02d89abb377aa56f0d75989176e733d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vincent=20Fali=C3=A8s?= Date: Fri, 2 Jun 2017 21:35:42 +0200 Subject: [PATCH 2/7] Refactoring CurlRequest in lib folder --- src/Catalogs/Genres.php | 2 +- src/Items/Item.php | 2 +- src/Search.php | 2 +- src/Tmdb.php | 2 +- src/{ => lib}/CurlRequest.php | 6 +++--- tests/curlRequestTest.php | 2 +- tests/tmdbTest.php | 10 +++++----- 7 files changed, 13 insertions(+), 13 deletions(-) rename src/{ => lib}/CurlRequest.php (88%) diff --git a/src/Catalogs/Genres.php b/src/Catalogs/Genres.php index 07915d1..5f9a8b1 100644 --- a/src/Catalogs/Genres.php +++ b/src/Catalogs/Genres.php @@ -63,7 +63,7 @@ private function getList(string $type, array $options): \Generator try { $params = $this->tmdb->checkOptions($options); - $response = $this->tmdb->sendRequest(new \vfalies\tmdb\CurlRequest(), $type, null, $params); + $response = $this->tmdb->sendRequest(new \vfalies\tmdb\lib\CurlRequest(), $type, null, $params); $genres = []; if (isset($response->genres)) diff --git a/src/Items/Item.php b/src/Items/Item.php index cc1b96e..fa7a6d7 100644 --- a/src/Items/Item.php +++ b/src/Items/Item.php @@ -25,7 +25,7 @@ public function __construct(\vfalies\tmdb\Tmdb $tmdb, int $item_id, array $optio $this->tmdb = $tmdb; $this->conf = $this->tmdb->getConfiguration(); $params = $this->tmdb->checkOptions($options); - $this->data = $this->tmdb->sendRequest(new \vfalies\tmdb\CurlRequest(), $item_name . '/'.(int) $item_id, null, $params); + $this->data = $this->tmdb->sendRequest(new \vfalies\tmdb\lib\CurlRequest(), $item_name . '/'.(int) $item_id, null, $params); } catch (\Exception $ex) { diff --git a/src/Search.php b/src/Search.php index 96c8050..7193548 100644 --- a/src/Search.php +++ b/src/Search.php @@ -39,7 +39,7 @@ private function searchItem(string $item, string $query, array $options, $result throw new \Exception('query parameter can not be empty'); } $params = $this->tmdb->checkOptions($options); - $response = $this->tmdb->sendRequest(new CurlRequest(), 'search/' . $item, $query, $params); + $response = $this->tmdb->sendRequest(new lib\CurlRequest(), 'search/' . $item, $query, $params); $this->page = (int) $response->page; $this->total_pages = (int) $response->total_pages; diff --git a/src/Tmdb.php b/src/Tmdb.php index 0547fb9..2f2e28e 100644 --- a/src/Tmdb.php +++ b/src/Tmdb.php @@ -101,7 +101,7 @@ public function getConfiguration(): \stdClass { if (is_null($this->configuration)) { - $this->configuration = $this->sendRequest(new CurlRequest(), 'configuration'); + $this->configuration = $this->sendRequest(new lib\CurlRequest(), 'configuration'); } return $this->configuration; } catch (\Exception $ex) diff --git a/src/CurlRequest.php b/src/lib/CurlRequest.php similarity index 88% rename from src/CurlRequest.php rename to src/lib/CurlRequest.php index 51c6f7f..9c4f599 100644 --- a/src/CurlRequest.php +++ b/src/lib/CurlRequest.php @@ -1,8 +1,8 @@ handle, $name, $value); return $this; diff --git a/tests/curlRequestTest.php b/tests/curlRequestTest.php index 066674c..e19cea2 100644 --- a/tests/curlRequestTest.php +++ b/tests/curlRequestTest.php @@ -13,7 +13,7 @@ protected function setUp() $this->markTestSkipped('cUrl extension is not loaded'); } - $this->curl = new CurlRequest(); + $this->curl = new lib\CurlRequest(); } /** diff --git a/tests/tmdbTest.php b/tests/tmdbTest.php index 28c905e..10de624 100644 --- a/tests/tmdbTest.php +++ b/tests/tmdbTest.php @@ -100,7 +100,7 @@ public function testGetConfigurationNOK() public function testSendRequestHttpError() { $tmdb = new Tmdb('fake_api_key'); - $tmdb->sendRequest(new CurlRequest(), 'fake/'); + $tmdb->sendRequest(new lib\CurlRequest(), 'fake/'); } /** @@ -112,7 +112,7 @@ public function testSendRequestExecError() { $tmdb = new Tmdb('fake_api_key'); $tmdb->base_api_url = 'invalid_url'; - $tmdb->sendRequest(new CurlRequest(), 'action'); + $tmdb->sendRequest(new lib\CurlRequest(), 'action'); } /** @@ -124,7 +124,7 @@ public function testSendRequestExecError() public function testSendRequestHttpError429() { $tmdb = new Tmdb('fake_api_key'); - $http_request = $this->getMockBuilder(\vfalies\tmdb\CurlRequest::class) + $http_request = $this->getMockBuilder(\vfalies\tmdb\lib\CurlRequest::class) ->setMethods(['getInfo']) ->getMock(); $http_request->method('getInfo')->willReturn(429); @@ -141,7 +141,7 @@ public function testSendRequestHttpError429() public function testSendRequestHttpErrorNotJson() { $tmdb = new Tmdb('fake_api_key'); - $http_request = $this->getMockBuilder(\vfalies\tmdb\CurlRequest::class) + $http_request = $this->getMockBuilder(\vfalies\tmdb\lib\CurlRequest::class) ->setMethods(['getInfo','execute']) ->getMock(); $http_request->method('getInfo')->willReturn(200); @@ -158,7 +158,7 @@ public function testSendRequestHttpErrorNotJson() public function testSendRequestOk() { $tmdb = new Tmdb('fake_api_key'); - $http_request = $this->getMockBuilder(\vfalies\tmdb\CurlRequest::class) + $http_request = $this->getMockBuilder(\vfalies\tmdb\lib\CurlRequest::class) ->setMethods(['getInfo','execute']) ->getMock(); $http_request->method('getInfo')->willReturn(200); From 040bcd0e1f2cc6ddebd97887d5d6269382f10e99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vincent=20Fali=C3=A8s?= Date: Fri, 2 Jun 2017 21:52:16 +0200 Subject: [PATCH 3/7] Refactoring name utilisation --- src/Catalog.php | 6 ++++-- src/Catalogs/Genres.php | 10 +++++++--- src/Item.php | 16 ++++++++++------ src/Items/Collection.php | 10 +++++++--- src/Items/Item.php | 7 +++++-- src/Items/Movie.php | 7 +++++-- src/Items/TVShow.php | 7 +++++-- src/Results/Collection.php | 4 +++- src/Results/Movie.php | 4 +++- src/Results/Results.php | 3 ++- src/Results/TVShow.php | 4 +++- src/Search.php | 4 +++- src/Tmdb.php | 7 +++++-- src/lib/CurlRequest.php | 6 ++++-- 14 files changed, 66 insertions(+), 29 deletions(-) diff --git a/src/Catalog.php b/src/Catalog.php index 3b9250c..4daf095 100644 --- a/src/Catalog.php +++ b/src/Catalog.php @@ -2,6 +2,8 @@ namespace vfalies\tmdb; +use vfalies\tmdb\Catalogs\Genres; + class Catalog { @@ -23,7 +25,7 @@ public function __construct(Tmdb $tmdb) */ public function getMovieGenres(array $options = array()): \Generator { - $catalog = new Catalogs\Genres($this->tmdb); + $catalog = new Genres($this->tmdb); return $catalog->getMovieList($options); } @@ -34,7 +36,7 @@ public function getMovieGenres(array $options = array()): \Generator */ public function getTVShowGenres(array $options = array()): \Generator { - $catalog = new Catalogs\Genres($this->tmdb); + $catalog = new Genres($this->tmdb); return $catalog->getTVList($options); } } diff --git a/src/Catalogs/Genres.php b/src/Catalogs/Genres.php index 5f9a8b1..3f4b2fb 100644 --- a/src/Catalogs/Genres.php +++ b/src/Catalogs/Genres.php @@ -2,7 +2,11 @@ namespace vfalies\tmdb\Catalogs; -class Genres implements \vfalies\tmdb\Interfaces\GenresInterface +use vfalies\tmdb\Interfaces\GenresInterface; +use vfalies\tmdb\Tmdb; +use vfalies\tmdb\lib\CurlRequest; + +class Genres implements GenresInterface { protected $tmdb = null; @@ -12,7 +16,7 @@ class Genres implements \vfalies\tmdb\Interfaces\GenresInterface * @param \vfalies\tmdb\Tmdb $tmdb * @throws Exception */ - public function __construct(\vfalies\tmdb\Tmdb $tmdb) + public function __construct(Tmdb $tmdb) { $this->tmdb = $tmdb; } @@ -63,7 +67,7 @@ private function getList(string $type, array $options): \Generator try { $params = $this->tmdb->checkOptions($options); - $response = $this->tmdb->sendRequest(new \vfalies\tmdb\lib\CurlRequest(), $type, null, $params); + $response = $this->tmdb->sendRequest(new CurlRequest(), $type, null, $params); $genres = []; if (isset($response->genres)) diff --git a/src/Item.php b/src/Item.php index 6a8ba12..cca7978 100644 --- a/src/Item.php +++ b/src/Item.php @@ -2,6 +2,10 @@ namespace vfalies\tmdb; +use vfalies\tmdb\Items\Movie; +use vfalies\tmdb\Items\Collection; +use vfalies\tmdb\Items\TVShow; + class Item { private $tmdb = null; @@ -22,9 +26,9 @@ public function __construct(Tmdb $tmdb) * @param array $options * @return \vfalies\tmdb\Items\Movie */ - public function getMovie(int $movie_id, array $options = array()): Items\Movie + public function getMovie(int $movie_id, array $options = array()): Movie { - $movie = new Items\Movie($this->tmdb, $movie_id, $options); + $movie = new Movie($this->tmdb, $movie_id, $options); return $movie; } @@ -35,9 +39,9 @@ public function getMovie(int $movie_id, array $options = array()): Items\Movie * @param array $options * @return \vfalies\tmdb\Items\Collection */ - public function getCollection(int $collection_id, array $options = array()): Items\Collection + public function getCollection(int $collection_id, array $options = array()): Collection { - $collection = new Items\Collection($this->tmdb, $collection_id, $options); + $collection = new Collection($this->tmdb, $collection_id, $options); return $collection; } @@ -48,9 +52,9 @@ public function getCollection(int $collection_id, array $options = array()): Ite * @param array $options * @return \vfalies\tmdb\Items\TVShow */ - public function getTVShow(int $tv_id, array $options = array()): Items\TVShow + public function getTVShow(int $tv_id, array $options = array()): TVShow { - $tv = new Items\TVShow($this->tmdb, $tv_id, $options); + $tv = new TVShow($this->tmdb, $tv_id, $options); return $tv; } diff --git a/src/Items/Collection.php b/src/Items/Collection.php index efc11b5..dde88bd 100644 --- a/src/Items/Collection.php +++ b/src/Items/Collection.php @@ -2,7 +2,11 @@ namespace vfalies\tmdb\Items; -class Collection extends Item implements \vfalies\tmdb\Interfaces\CollectionInterface +use vfalies\tmdb\Interfaces\CollectionInterface; +use vfalies\tmdb\Tmdb; +use vfalies\tmdb\Results\Movie; + +class Collection extends Item implements CollectionInterface { // Private loaded data @@ -16,7 +20,7 @@ class Collection extends Item implements \vfalies\tmdb\Interfaces\CollectionInte * @param \vfalies\tmdb\Tmdb $tmdb * @throws \Exception */ - public function __construct(\vfalies\tmdb\Tmdb $tmdb, $collection_id, array $options = array()) + public function __construct(Tmdb $tmdb, $collection_id, array $options = array()) { parent::__construct($tmdb, $collection_id, $options, 'collection'); } @@ -55,7 +59,7 @@ public function getParts(): \Generator { foreach ($this->data->parts as $part) { - $movie = new \vfalies\tmdb\Results\Movie($this->tmdb, $part); + $movie = new Movie($this->tmdb, $part); yield $movie; } } diff --git a/src/Items/Item.php b/src/Items/Item.php index fa7a6d7..125e557 100644 --- a/src/Items/Item.php +++ b/src/Items/Item.php @@ -2,6 +2,9 @@ namespace vfalies\tmdb\Items; +use vfalies\tmdb\Tmdb; +use vfalies\tmdb\lib\CurlRequest; + abstract class Item { protected $data = null; @@ -17,7 +20,7 @@ abstract class Item * @param string $item_name * @throws \Exception */ - public function __construct(\vfalies\tmdb\Tmdb $tmdb, int $item_id, array $options, string $item_name) + public function __construct(Tmdb $tmdb, int $item_id, array $options, string $item_name) { try { @@ -25,7 +28,7 @@ public function __construct(\vfalies\tmdb\Tmdb $tmdb, int $item_id, array $optio $this->tmdb = $tmdb; $this->conf = $this->tmdb->getConfiguration(); $params = $this->tmdb->checkOptions($options); - $this->data = $this->tmdb->sendRequest(new \vfalies\tmdb\lib\CurlRequest(), $item_name . '/'.(int) $item_id, null, $params); + $this->data = $this->tmdb->sendRequest(new CurlRequest(), $item_name . '/'.(int) $item_id, null, $params); } catch (\Exception $ex) { diff --git a/src/Items/Movie.php b/src/Items/Movie.php index 7704d9b..9accbee 100644 --- a/src/Items/Movie.php +++ b/src/Items/Movie.php @@ -2,7 +2,10 @@ namespace vfalies\tmdb\Items; -class Movie extends Item implements \vfalies\tmdb\Interfaces\MovieInterface +use vfalies\tmdb\Interfaces\MovieInterface; +use vfalies\tmdb\Tmdb; + +class Movie extends Item implements MovieInterface { /** * Constructor @@ -11,7 +14,7 @@ class Movie extends Item implements \vfalies\tmdb\Interfaces\MovieInterface * @param array $options * @throws Exception */ - public function __construct(\vfalies\tmdb\Tmdb $tmdb, int $movie_id, array $options = array()) + public function __construct(Tmdb $tmdb, int $movie_id, array $options = array()) { parent::__construct($tmdb, $movie_id, $options, 'movie'); } diff --git a/src/Items/TVShow.php b/src/Items/TVShow.php index 1036f66..fec4f08 100644 --- a/src/Items/TVShow.php +++ b/src/Items/TVShow.php @@ -2,10 +2,13 @@ namespace vfalies\tmdb\Items; -class TVShow extends Item implements \vfalies\tmdb\Interfaces\TVShowInterface +use vfalies\tmdb\Interfaces\TVShowInterface; +use vfalies\tmdb\Tmdb; + +class TVShow extends Item implements TVShowInterface { - public function __construct(\vfalies\tmdb\Tmdb $tmdb, int $tv_id, array $options = array()) + public function __construct(Tmdb $tmdb, int $tv_id, array $options = array()) { parent::__construct($tmdb, $tv_id, $options, 'tv'); } diff --git a/src/Results/Collection.php b/src/Results/Collection.php index 3333c9f..683a76b 100644 --- a/src/Results/Collection.php +++ b/src/Results/Collection.php @@ -2,6 +2,8 @@ namespace vfalies\tmdb\Results; +use vfalies\tmdb\Tmdb; + class Collection extends Results { @@ -13,7 +15,7 @@ class Collection extends Results * @param \stdClass $result * @throws \Exception */ - public function __construct(\vfalies\tmdb\Tmdb $tmdb, \stdClass $result) + public function __construct(Tmdb $tmdb, \stdClass $result) { parent::__construct($tmdb, $result); diff --git a/src/Results/Movie.php b/src/Results/Movie.php index 93e5e45..4da4b81 100644 --- a/src/Results/Movie.php +++ b/src/Results/Movie.php @@ -2,6 +2,8 @@ namespace vfalies\tmdb\Results; +use vfalies\tmdb\Tmdb; + class Movie extends Results { protected $overview = null; @@ -15,7 +17,7 @@ class Movie extends Results * @param \stdClass $result * @throws \Exception */ - public function __construct(\vfalies\tmdb\Tmdb $tmdb, \stdClass $result) + public function __construct(Tmdb $tmdb, \stdClass $result) { parent::__construct($tmdb, $result); diff --git a/src/Results/Results.php b/src/Results/Results.php index 31bc101..3b099d6 100644 --- a/src/Results/Results.php +++ b/src/Results/Results.php @@ -1,6 +1,7 @@ tmdb->checkOptions($options); - $response = $this->tmdb->sendRequest(new lib\CurlRequest(), 'search/' . $item, $query, $params); + $response = $this->tmdb->sendRequest(new CurlRequest(), 'search/' . $item, $query, $params); $this->page = (int) $response->page; $this->total_pages = (int) $response->total_pages; diff --git a/src/Tmdb.php b/src/Tmdb.php index 2f2e28e..1a35878 100644 --- a/src/Tmdb.php +++ b/src/Tmdb.php @@ -2,10 +2,13 @@ namespace vfalies\tmdb; +use vfalies\tmdb\Interfaces\TmdbInterface; +use vfalies\tmdb\Interfaces\HttpRequestInterface; + /** * Tmdb wrapper core class */ -class Tmdb implements Interfaces\TmdbInterface +class Tmdb implements TmdbInterface { // Private variables @@ -36,7 +39,7 @@ public function __construct(string $api_key) * @param array $options Array of options of the request (optional) * @return \stdClass */ - public function sendRequest(Interfaces\HttpRequestInterface $http_request, string $action, string $query = null, array $options = array()): \stdClass + public function sendRequest(HttpRequestInterface $http_request, string $action, string $query = null, array $options = array()): \stdClass { // Url construction $url = $this->base_api_url . $action; diff --git a/src/lib/CurlRequest.php b/src/lib/CurlRequest.php index 9c4f599..821c72f 100644 --- a/src/lib/CurlRequest.php +++ b/src/lib/CurlRequest.php @@ -2,7 +2,9 @@ namespace vfalies\tmdb\lib; -class CurlRequest implements \vfalies\tmdb\Interfaces\HttpRequestInterface +use vfalies\tmdb\Interfaces\HttpRequestInterface; + +class CurlRequest implements HttpRequestInterface { private $handle = null; @@ -64,7 +66,7 @@ public function getInfo(string $name = '') * @param mixed $value * @throws \Exception */ - public function setOption(string $name, $value): \vfalies\tmdb\Interfaces\HttpRequestInterface + public function setOption(string $name, $value): HttpRequestInterface { curl_setopt($this->handle, $name, $value); return $this; From 49dc1b0694f9fc2e8d8a3ce0feab07c103b02cbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vincent=20Fali=C3=A8s?= Date: Fri, 2 Jun 2017 21:58:46 +0200 Subject: [PATCH 4/7] Update README --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ffb1c23..ce1468c 100644 --- a/README.md +++ b/README.md @@ -42,16 +42,17 @@ $tmdb = new Tmdb('your_api_key'); $search = new Search($tmdb); $responses = $search->movie('star wars'); -// Get title of the first result in API response -echo $search->getMovie($responses->current()->id)->getTitle(); - // Get all results foreach ($responses as $response) { echo $search->getMovie($response->id)->getTitle(); } +// Get movie information +$item = new Item($tmdb); +$infos = $item->getMovie(11, array('language' => 'fr-FR'); +echo $infos->getTitle(); ``` ## Documentation From 55e838148b24c5845016224fa92ed30f3a2ba04c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vincent=20Fali=C3=A8s?= Date: Fri, 2 Jun 2017 22:07:45 +0200 Subject: [PATCH 5/7] Resolve conflict namespace --- src/Items/Collection.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Items/Collection.php b/src/Items/Collection.php index dde88bd..f6c08b1 100644 --- a/src/Items/Collection.php +++ b/src/Items/Collection.php @@ -4,7 +4,6 @@ use vfalies\tmdb\Interfaces\CollectionInterface; use vfalies\tmdb\Tmdb; -use vfalies\tmdb\Results\Movie; class Collection extends Item implements CollectionInterface { @@ -59,7 +58,7 @@ public function getParts(): \Generator { foreach ($this->data->parts as $part) { - $movie = new Movie($this->tmdb, $part); + $movie = new vfalies\tmdb\Results\Movie($this->tmdb, $part); yield $movie; } } From cc366707ce53b9634456bb7ea040f0f10014f650 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vincent=20Fali=C3=A8s?= Date: Fri, 2 Jun 2017 22:09:37 +0200 Subject: [PATCH 6/7] Fix doc comment --- src/Items/Collection.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Items/Collection.php b/src/Items/Collection.php index f6c08b1..f062a30 100644 --- a/src/Items/Collection.php +++ b/src/Items/Collection.php @@ -16,10 +16,11 @@ class Collection extends Item implements CollectionInterface /** * Constructor - * @param \vfalies\tmdb\Tmdb $tmdb - * @throws \Exception + * @param Tmdb $tmdb + * @param int $collection_id + * @param array $options */ - public function __construct(Tmdb $tmdb, $collection_id, array $options = array()) + public function __construct(Tmdb $tmdb, int $collection_id, array $options = array()) { parent::__construct($tmdb, $collection_id, $options, 'collection'); } @@ -50,7 +51,7 @@ public function getName(): string /** * Get collection parts - * @return Generator|SearchMovieResult + * @return Generator */ public function getParts(): \Generator { From f11fcef3fb513577f9e28db35af81440e9b60fd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vincent=20Fali=C3=A8s?= Date: Fri, 2 Jun 2017 22:14:03 +0200 Subject: [PATCH 7/7] Fix namespace error --- src/Items/Collection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Items/Collection.php b/src/Items/Collection.php index f062a30..dce81a5 100644 --- a/src/Items/Collection.php +++ b/src/Items/Collection.php @@ -59,7 +59,7 @@ public function getParts(): \Generator { foreach ($this->data->parts as $part) { - $movie = new vfalies\tmdb\Results\Movie($this->tmdb, $part); + $movie = new \vfalies\tmdb\Results\Movie($this->tmdb, $part); yield $movie; } }