diff --git a/composer.json b/composer.json index d6e286c9..ebf966c5 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "require": { "php": ">=5.4.0", "ext-curl": "*", - "symfony/event-dispatcher": "~2.1", + "symfony/event-dispatcher": "~2.4", "symfony/options-resolver": "~2.1", "guzzlehttp/guzzle": "~5.0", "guzzlehttp/cache-subscriber": "~0.1@dev", diff --git a/examples/find/api/get.php b/examples/find/api/get.php index 01d556ad..4d68a6c8 100644 --- a/examples/find/api/get.php +++ b/examples/find/api/get.php @@ -16,7 +16,7 @@ $token = new \Tmdb\ApiToken(TMDB_API_KEY); $client = new \Tmdb\Client($token); -$find = $client->getFindApi()->find('tt0120737', [ +$find = $client->getFindApi()->findBy('tt0120737', [ 'external_source' => 'imdb_id' ]); diff --git a/examples/find/model/get.php b/examples/find/model/get.php index bc24e2de..c91ff339 100644 --- a/examples/find/model/get.php +++ b/examples/find/model/get.php @@ -17,6 +17,6 @@ $client = new \Tmdb\Client($token); $repository = new \Tmdb\Repository\FindRepository($client); -$find = $repository->find('tt0120737', ['external_source' => 'imdb_id']); +$find = $repository->findBy('tt0120737', ['external_source' => 'imdb_id']); var_dump($find); diff --git a/lib/Tmdb/Api/Find.php b/lib/Tmdb/Api/Find.php index 175af815..7df4afb3 100644 --- a/lib/Tmdb/Api/Find.php +++ b/lib/Tmdb/Api/Find.php @@ -37,7 +37,7 @@ class Find extends AbstractApi * @param array $headers * @return mixed */ - public function find($id, array $parameters = [], array $headers = []) + public function findBy($id, array $parameters = [], array $headers = []) { return $this->get( sprintf('find/%s', $id), diff --git a/lib/Tmdb/ConfigurationInterface.php b/lib/Tmdb/ConfigurationInterface.php index 644a46f6..c2378b4a 100644 --- a/lib/Tmdb/ConfigurationInterface.php +++ b/lib/Tmdb/ConfigurationInterface.php @@ -4,7 +4,7 @@ * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. - * + * * @package Shop2Market * @author Michael Roterman * @copyright (c) 2014, B-Found Internet Marketing & Services @@ -13,6 +13,7 @@ namespace Tmdb; -interface ConfigurationInterface { - function all(); -} \ No newline at end of file +interface ConfigurationInterface +{ + public function all(); +} diff --git a/lib/Tmdb/Event/HydrationSubscriber.php b/lib/Tmdb/Event/HydrationSubscriber.php index b9108ba1..fc39c8d5 100644 --- a/lib/Tmdb/Event/HydrationSubscriber.php +++ b/lib/Tmdb/Event/HydrationSubscriber.php @@ -12,6 +12,7 @@ */ namespace Tmdb\Event; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Tmdb\Common\ObjectHydrator; use Tmdb\HttpClient\HttpClientEventSubscriber; @@ -36,13 +37,16 @@ public static function getSubscribedEvents() /** * Hydrate the subject with data * - * @param HydrationEvent $event + * @param HydrationEvent $event + * @param string $eventName + * @param EventDispatcherInterface $eventDispatcher + * * @return \Tmdb\Model\AbstractModel */ - public function hydrate(HydrationEvent $event) + public function hydrate(HydrationEvent $event, $eventName, $eventDispatcher) { // Possibility to load serialized cache - $event->getDispatcher()->dispatch(TmdbEvents::BEFORE_HYDRATION, $event); + $eventDispatcher->dispatch(TmdbEvents::BEFORE_HYDRATION, $event); if ($event->isPropagationStopped()) { return $event->getSubject(); @@ -52,7 +56,7 @@ public function hydrate(HydrationEvent $event) $event->setSubject($subject); // Possibility to cache the data - $event->getDispatcher()->dispatch(TmdbEvents::AFTER_HYDRATION, $event); + $eventDispatcher->dispatch(TmdbEvents::AFTER_HYDRATION, $event); return $event->getSubject(); } diff --git a/lib/Tmdb/Event/RequestSubscriber.php b/lib/Tmdb/Event/RequestSubscriber.php index b215dbee..28ca4bea 100644 --- a/lib/Tmdb/Event/RequestSubscriber.php +++ b/lib/Tmdb/Event/RequestSubscriber.php @@ -12,6 +12,7 @@ */ namespace Tmdb\Event; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Tmdb\Exception\RuntimeException; use Tmdb\HttpClient\HttpClientEventSubscriber; use Tmdb\HttpClient\Response; @@ -29,10 +30,17 @@ public static function getSubscribedEvents() ]; } - public function send(RequestEvent $event) + /** + * @param RequestEvent $event + * @param string $eventName + * @param EventDispatcherInterface $eventDispatcher + * + * @return string|Response + */ + public function send(RequestEvent $event, $eventName, EventDispatcherInterface $eventDispatcher) { // Preparation of request parameters / Possibility to use for logging and caching etc. - $event->getDispatcher()->dispatch(TmdbEvents::BEFORE_REQUEST, $event); + $eventDispatcher->dispatch(TmdbEvents::BEFORE_REQUEST, $event); if ($event->isPropagationStopped() && $event->hasResponse()) { return $event->getResponse(); @@ -42,7 +50,7 @@ public function send(RequestEvent $event) $event->setResponse($response); // Possibility to cache the request - $event->getDispatcher()->dispatch(TmdbEvents::AFTER_REQUEST, $event); + $eventDispatcher->dispatch(TmdbEvents::AFTER_REQUEST, $event); return $response; } @@ -56,8 +64,6 @@ public function send(RequestEvent $event) */ public function sendRequest(RequestEvent $event) { - $response = null; - switch ($event->getMethod()) { case 'GET': $response = $this->getHttpClient()->getAdapter()->get($event->getRequest()); diff --git a/lib/Tmdb/Exception/TmdbApiException.php b/lib/Tmdb/Exception/TmdbApiException.php index bca7bf4d..34075677 100644 --- a/lib/Tmdb/Exception/TmdbApiException.php +++ b/lib/Tmdb/Exception/TmdbApiException.php @@ -43,10 +43,10 @@ class TmdbApiException extends \Exception /** * Create the exception * - * @param string $message - * @param int $code - * @param null $request - * @param null $response + * @param string $message + * @param int $code + * @param Request|null $request + * @param Response|null $response */ public function __construct($code, $message, $request = null, $response = null) { diff --git a/lib/Tmdb/Factory/Common/VideoFactory.php b/lib/Tmdb/Factory/Common/VideoFactory.php index 21e931a3..63e4866d 100644 --- a/lib/Tmdb/Factory/Common/VideoFactory.php +++ b/lib/Tmdb/Factory/Common/VideoFactory.php @@ -62,10 +62,8 @@ private function resolveVideoType($data) switch ($site) { case 'youtube': return new Video\Youtube(); - break; default: return new Video(); - break; } } } diff --git a/lib/Tmdb/Factory/FindFactory.php b/lib/Tmdb/Factory/FindFactory.php index 25268fc8..d0ea3fdb 100644 --- a/lib/Tmdb/Factory/FindFactory.php +++ b/lib/Tmdb/Factory/FindFactory.php @@ -36,6 +36,16 @@ class FindFactory extends AbstractFactory */ private $tvFactory; + /** + * @var TvSeasonFactory + */ + private $tvSeasonFactory; + + /** + * @var TvEpisodeFactory + */ + private $tvEpisodeFactory; + /** * Constructor * @@ -46,7 +56,7 @@ public function __construct(HttpClient $httpClient) $this->movieFactory = new MovieFactory($httpClient); $this->peopleFactory = new PeopleFactory($httpClient); $this->tvFactory = new TvFactory($httpClient); - $this->tvSeasonFactory = new TvFactory($httpClient); + $this->tvSeasonFactory = new TvSeasonFactory($httpClient); $this->tvEpisodeFactory = new TvEpisodeFactory($httpClient); parent::__construct($httpClient); @@ -171,7 +181,7 @@ public function setTvEpisodeFactory($tvEpisodeFactory) } /** - * @return TvFactory + * @return TvSeasonFactory */ public function getTvSeasonFactory() { @@ -179,7 +189,7 @@ public function getTvSeasonFactory() } /** - * @param TvFactory $tvSeasonFactory + * @param TvSeasonFactory $tvSeasonFactory * @return $this */ public function setTvSeasonFactory($tvSeasonFactory) diff --git a/lib/Tmdb/Factory/People/CastFactory.php b/lib/Tmdb/Factory/People/CastFactory.php index 5efcadbf..8a559fe2 100644 --- a/lib/Tmdb/Factory/People/CastFactory.php +++ b/lib/Tmdb/Factory/People/CastFactory.php @@ -13,7 +13,6 @@ namespace Tmdb\Factory\People; use Tmdb\Factory\PeopleFactory; -use Tmdb\HttpClient\HttpClient; use Tmdb\Model\Collection\People\Cast; /** @@ -22,24 +21,6 @@ */ class CastFactory extends PeopleFactory { - /** - * Constructor - * - * @param HttpClient $httpClient - */ - public function __construct(HttpClient $httpClient) - { - parent::__construct($httpClient); - } - - /** - * {@inheritdoc} - */ - public function create(array $data = [], $person = null) - { - return parent::create($data, $person); - } - /** * {@inheritdoc} * @param \Tmdb\Model\Person\CastMember $person diff --git a/lib/Tmdb/Factory/People/CrewFactory.php b/lib/Tmdb/Factory/People/CrewFactory.php index b959e061..7613ff18 100644 --- a/lib/Tmdb/Factory/People/CrewFactory.php +++ b/lib/Tmdb/Factory/People/CrewFactory.php @@ -13,7 +13,6 @@ namespace Tmdb\Factory\People; use Tmdb\Factory\PeopleFactory; -use Tmdb\HttpClient\HttpClient; use Tmdb\Model\Collection\People\Crew; /** @@ -22,24 +21,6 @@ */ class CrewFactory extends PeopleFactory { - /** - * Constructor - * - * @param HttpClient $httpClient - */ - public function __construct(HttpClient $httpClient) - { - parent::__construct($httpClient); - } - - /** - * {@inheritdoc} - */ - public function create(array $data = [], $person = null) - { - return parent::create($data, $person); - } - /** * {@inheritdoc} * @param \Tmdb\Model\Person\CrewMember $person diff --git a/lib/Tmdb/HttpClient/Adapter/GuzzleAdapter.php b/lib/Tmdb/HttpClient/Adapter/GuzzleAdapter.php index a61827f4..ebb4b691 100644 --- a/lib/Tmdb/HttpClient/Adapter/GuzzleAdapter.php +++ b/lib/Tmdb/HttpClient/Adapter/GuzzleAdapter.php @@ -26,7 +26,7 @@ class GuzzleAdapter extends AbstractAdapter { /** - * @var Client + * @var ClientInterface */ private $client; @@ -88,9 +88,11 @@ private function createResponse(ResponseInterface $adapterResponse = null) { $response = new Response(); - $response->setCode($adapterResponse->getStatusCode()); - $response->setHeaders(new ParameterBag($adapterResponse->getHeaders())); - $response->setBody((string) $adapterResponse->getBody()); + if ($adapterResponse !== null) { + $response->setCode($adapterResponse->getStatusCode()); + $response->setHeaders(new ParameterBag($adapterResponse->getHeaders())); + $response->setBody((string) $adapterResponse->getBody()); + } return $response; } @@ -102,9 +104,9 @@ private function createResponse(ResponseInterface $adapterResponse = null) * @param RequestException|null $previousException * @throws \Tmdb\Exception\TmdbApiException */ - protected function handleRequestException(Request $request, RequestException $previousException = null) + protected function handleRequestException(Request $request, RequestException $previousException) { - if (null !== $previousException && null == $response = $previousException->getResponse()) { + if (null !== $previousException && null == $previousException->getResponse()) { throw new NullResponseException($this->request, $previousException); } diff --git a/lib/Tmdb/HttpClient/HttpClient.php b/lib/Tmdb/HttpClient/HttpClient.php index 3318898c..bfef04d4 100644 --- a/lib/Tmdb/HttpClient/HttpClient.php +++ b/lib/Tmdb/HttpClient/HttpClient.php @@ -56,7 +56,7 @@ class HttpClient private $eventDispatcher; /** - * @var ParameterBag + * @var array */ protected $options; @@ -148,7 +148,7 @@ public function delete($path, $body = null, array $parameters = [], array $heade } /** - * @return ParameterBag + * @return array */ public function getOptions() { @@ -156,7 +156,7 @@ public function getOptions() } /** - * @param ParameterBag $options + * @param array $options * @return $this */ public function setOptions($options) diff --git a/lib/Tmdb/Model/Account/ListItem.php b/lib/Tmdb/Model/Account/ListItem.php index b5fc67ca..bd81eefa 100644 --- a/lib/Tmdb/Model/Account/ListItem.php +++ b/lib/Tmdb/Model/Account/ListItem.php @@ -13,6 +13,7 @@ namespace Tmdb\Model\Account; use Tmdb\Model\AbstractModel; +use Tmdb\Model\Image; use Tmdb\Model\Image\PosterImage; /** @@ -214,7 +215,7 @@ public function getName() } /** - * @param \Tmdb\Model\Image\PosterImage $posterImage + * @param PosterImage|Image $posterImage * @return $this */ public function setPosterImage($posterImage) @@ -225,7 +226,7 @@ public function setPosterImage($posterImage) } /** - * @return \Tmdb\Model\Image\PosterImage + * @return PosterImage|Image */ public function getPosterImage() { diff --git a/lib/Tmdb/Model/Collection.php b/lib/Tmdb/Model/Collection.php index 7059eef0..f087b5fb 100644 --- a/lib/Tmdb/Model/Collection.php +++ b/lib/Tmdb/Model/Collection.php @@ -83,7 +83,7 @@ public function __construct() } /** - * @param \Tmdb\Model\Image\BackdropImage $backdrop + * @param BackdropImage $backdrop * @return $this */ public function setBackdropImage(BackdropImage $backdrop) @@ -94,7 +94,7 @@ public function setBackdropImage(BackdropImage $backdrop) } /** - * @return \Tmdb\Model\Image\BackdropImage + * @return BackdropImage */ public function getBackdropImage() { @@ -216,7 +216,7 @@ public function getParts() } /** - * @param \Tmdb\Model\Image\PosterImage $poster + * @param PosterImage $poster * @return $this */ public function setPosterImage(PosterImage $poster) diff --git a/lib/Tmdb/Model/Common/AccountStates.php b/lib/Tmdb/Model/Common/AccountStates.php index 71e6f2ef..12fdbb8b 100644 --- a/lib/Tmdb/Model/Common/AccountStates.php +++ b/lib/Tmdb/Model/Common/AccountStates.php @@ -31,7 +31,7 @@ class AccountStates extends AbstractModel private $favorite; /** - * @var Rating + * @var Rating|boolean */ private $rated; @@ -93,7 +93,7 @@ public function getId() } /** - * @param \Tmdb\Model\Movie\Rating $rated + * @param Rating|bool $rated * @return $this */ public function setRated($rated) @@ -104,7 +104,7 @@ public function setRated($rated) } /** - * @return \Tmdb\Model\Movie\Rating + * @return Rating|bool */ public function getRated() { diff --git a/lib/Tmdb/Model/Query/Discover/DiscoverMoviesQuery.php b/lib/Tmdb/Model/Query/Discover/DiscoverMoviesQuery.php index 4abcc17c..1f4d35e6 100644 --- a/lib/Tmdb/Model/Query/Discover/DiscoverMoviesQuery.php +++ b/lib/Tmdb/Model/Query/Discover/DiscoverMoviesQuery.php @@ -421,9 +421,9 @@ public function year($year) /** * Format the with compatible parameters. * - * @param null $with - * @param int $mode - * @return null|DiscoverMoviesQuery + * @param array|string $with + * @param int $mode + * @return string */ protected function with($with = null, $mode = self::MODE_OR) { @@ -441,9 +441,9 @@ protected function with($with = null, $mode = self::MODE_OR) /** * Creates an and query to combine an AND or an OR expression. * - * @param array $with - * @param int $mode - * @return $this + * @param array $with + * @param int $mode + * @return string */ protected function andWith(array $with, $mode) { @@ -471,12 +471,12 @@ protected function normalize($mixed) } /** - * @param \DateTime|string $year - * @param string $format + * @param \DateTime|string|integer $year + * @param string $format * @return int */ protected function getDate($year, $format = 'Y-m-d') { - return ($year instanceof \DateTime) ? $year->format($format) : $year; + return ($year instanceof \DateTime) ? $year->format($format) : (string) $year; } } diff --git a/lib/Tmdb/Model/Tv.php b/lib/Tmdb/Model/Tv.php index c3a4820d..116f60fc 100644 --- a/lib/Tmdb/Model/Tv.php +++ b/lib/Tmdb/Model/Tv.php @@ -239,19 +239,19 @@ class Tv extends AbstractModel */ public function __construct() { - $this->genres = new Genres(); - $this->networks = new GenericCollection(); - $this->originCountry = new GenericCollection(); - $this->seasons = new GenericCollection(); + $this->genres = new Genres(); + $this->networks = new GenericCollection(); + $this->originCountry = new GenericCollection(); + $this->seasons = new GenericCollection(); - $this->credits = new CreditsCollection(); - $this->externalIds = new ExternalIds(); - $this->images = new Images(); - $this->translations = new GenericCollection(); - $this->videos = new Videos(); - $this->changes = new GenericCollection(); - $this->keywords = new GenericCollection(); - $this->similar = new GenericCollection(); + $this->credits = new CreditsCollection(); + $this->externalIds = new ExternalIds(); + $this->images = new Images(); + $this->translations = new GenericCollection(); + $this->videos = new Videos(); + $this->changes = new GenericCollection(); + $this->keywords = new GenericCollection(); + $this->similar = new GenericCollection(); } /** @@ -274,7 +274,7 @@ public function getBackdropPath() } /** - * @param \Tmdb\Model\Common\Collection $createdBy + * @param GenericCollection $createdBy * @return $this */ public function setCreatedBy($createdBy) @@ -411,7 +411,7 @@ public function getInProduction() } /** - * @param array $languages + * @param GenericCollection $languages * @return $this */ public function setLanguages($languages) @@ -422,7 +422,7 @@ public function setLanguages($languages) } /** - * @return array + * @return GenericCollection */ public function getLanguages() { @@ -529,7 +529,7 @@ public function getNumberOfSeasons() } /** - * @param \Tmdb\Model\Common\Collection $originCountry + * @param GenericCollection $originCountry * @return $this */ public function setOriginCountry($originCountry) @@ -833,7 +833,7 @@ public function getVideos() } /** - * @param \Tmdb\Model\GenericCollection $changes + * @param GenericCollection $changes * @return $this */ public function setChanges($changes) @@ -844,7 +844,7 @@ public function setChanges($changes) } /** - * @return \Tmdb\Model\GenericCollection + * @return GenericCollection */ public function getChanges() { @@ -852,7 +852,7 @@ public function getChanges() } /** - * @param \Tmdb\Model\GenericCollection $keywords + * @param GenericCollection $keywords * @return $this */ public function setKeywords($keywords) @@ -863,7 +863,7 @@ public function setKeywords($keywords) } /** - * @return \Tmdb\Model\GenericCollection + * @return GenericCollection */ public function getKeywords() { @@ -871,7 +871,7 @@ public function getKeywords() } /** - * @param \Tmdb\Model\GenericCollection $similar + * @param GenericCollection $similar * @return $this */ public function setSimilar($similar) @@ -882,7 +882,7 @@ public function setSimilar($similar) } /** - * @return \Tmdb\Model\GenericCollection + * @return GenericCollection */ public function getSimilar() { diff --git a/lib/Tmdb/Model/Tv/Episode.php b/lib/Tmdb/Model/Tv/Episode.php index 2e81f45a..fa98336c 100644 --- a/lib/Tmdb/Model/Tv/Episode.php +++ b/lib/Tmdb/Model/Tv/Episode.php @@ -16,6 +16,7 @@ use Tmdb\Model\Collection\Changes; use Tmdb\Model\Collection\CreditsCollection; use Tmdb\Model\Collection\Images; +use Tmdb\Model\Collection\ResultCollection; use Tmdb\Model\Collection\Videos; use Tmdb\Model\Common\ExternalIds; use Tmdb\Model\Image\StillImage; @@ -412,7 +413,7 @@ public function getStillImage() } /** - * @param \Tmdb\Model\Collection\Videos $videos + * @param \Tmdb\Model\Collection\Videos|ResultCollection $videos * @return $this */ public function setVideos($videos) diff --git a/lib/Tmdb/Repository/FindRepository.php b/lib/Tmdb/Repository/FindRepository.php index 9e771cc3..bf84ee46 100644 --- a/lib/Tmdb/Repository/FindRepository.php +++ b/lib/Tmdb/Repository/FindRepository.php @@ -30,10 +30,10 @@ class FindRepository extends AbstractRepository * @param array $headers * @return Find */ - public function find($id, array $parameters = [], array $headers = []) + public function findBy($id, array $parameters = [], array $headers = []) { return $this->getFactory()->create( - $this->getApi()->find($id, $parameters, $headers) + $this->getApi()->findBy($id, $parameters, $headers) ); } diff --git a/lib/Tmdb/Repository/MovieRepository.php b/lib/Tmdb/Repository/MovieRepository.php index cbff50a2..1cf84d94 100644 --- a/lib/Tmdb/Repository/MovieRepository.php +++ b/lib/Tmdb/Repository/MovieRepository.php @@ -397,17 +397,6 @@ public function getFactory() return new MovieFactory($this->getClient()->getHttpClient()); } - /** - * Create an collection of an array - * - * @param $data - * @return Movie[] - */ - private function createCollection($data) - { - return $this->getFactory()->createCollection($data); - } - /** * @param AlternativeTitleFactory $alternativeTitleFactory * @return $this diff --git a/lib/Tmdb/Repository/SearchRepository.php b/lib/Tmdb/Repository/SearchRepository.php index 0451947c..80f9c55e 100644 --- a/lib/Tmdb/Repository/SearchRepository.php +++ b/lib/Tmdb/Repository/SearchRepository.php @@ -259,7 +259,7 @@ private function processSearchMultiItem(array $item) /** * Convert parameters back to an array * - * @param array $parameters + * @param SearchQuery|array $parameters * @return array */ private function getParameters($parameters = []) diff --git a/lib/Tmdb/Repository/TimezoneRepository.php b/lib/Tmdb/Repository/TimezoneRepository.php index dce53b4a..5286ba62 100644 --- a/lib/Tmdb/Repository/TimezoneRepository.php +++ b/lib/Tmdb/Repository/TimezoneRepository.php @@ -25,13 +25,11 @@ class TimezoneRepository extends AbstractRepository /** * Get the list of supported timezones for the API methods that support them. * - * @param $parameters - * @param $headers * @return Timezones */ - public function getTimezones(array $parameters = [], array $headers = []) + public function getTimezones() { - $data = $this->getApi()->getTimezones($this->parseQueryParameters($parameters), $headers); + $data = $this->getApi()->getTimezones(); return $this->getFactory()->createCollection($data); } diff --git a/test/Tmdb/Tests/Repository/FindRepositoryTest.php b/test/Tmdb/Tests/Repository/FindRepositoryTest.php index 05e9691b..e7b33f83 100644 --- a/test/Tmdb/Tests/Repository/FindRepositoryTest.php +++ b/test/Tmdb/Tests/Repository/FindRepositoryTest.php @@ -28,7 +28,7 @@ public function shouldGetMovieChanges() ->with($this->getRequest('find/' . self::FIND_QUERY, [])) ; - $repository->find(self::FIND_QUERY); + $repository->findBy(self::FIND_QUERY); } protected function getApiClass()