From 5c5251c61fa6a80111fb118e672142bcbd332b0a Mon Sep 17 00:00:00 2001 From: Michael Roterman Date: Sun, 19 Jan 2014 01:14:12 +0100 Subject: [PATCH] Making sure depdendencies are met for the request --- lib/Tmdb/Repository/DiscoverRepository.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/Tmdb/Repository/DiscoverRepository.php b/lib/Tmdb/Repository/DiscoverRepository.php index facb43b9..693591da 100644 --- a/lib/Tmdb/Repository/DiscoverRepository.php +++ b/lib/Tmdb/Repository/DiscoverRepository.php @@ -12,6 +12,7 @@ */ namespace Tmdb\Repository; +use Tmdb\Exception\RuntimeException; use Tmdb\Factory\MovieFactory; use Tmdb\Factory\TvFactory; use Tmdb\Model\Common\GenericCollection; @@ -24,10 +25,17 @@ class DiscoverRepository extends AbstractRepository { * * @param DiscoverMoviesQuery $query * @param array $headers + * @throws RuntimeException when certification_country is set but certification.lte is not given * @return GenericCollection */ public function discoverMovies(DiscoverMoviesQuery $query, array $headers = array()) { - $data = $this->getApi()->discoverMovies($query->toArray(), $this->parseHeaders($headers)); + $query = $query->toArray(); + + if (array_key_exists('certification_country', $query) && !array_key_exists('certification.lte', $query)) { + throw new RuntimeException('When the certification_country option is given the certification.lte option is required.'); + } + + $data = $this->getApi()->discoverMovies($query, $this->parseHeaders($headers)); return MovieFactory::createCollection($data); }