Skip to content

Commit

Permalink
Don't use native union types yet
Browse files Browse the repository at this point in the history
  • Loading branch information
neildaniels committed Feb 12, 2023
1 parent 05f8098 commit f4ca761
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/Tmdb/Factory/AbstractFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public function createResult(array $data = [])
*
* @return GenericCollection<S>
*/
protected function createGenericCollection(array $data = [], AbstractModel|string $class = null): GenericCollection
protected function createGenericCollection(array $data = [], $class = null): GenericCollection
{
if (!$class) {
throw new \Tmdb\Exception\RuntimeException('Expected a class to be present.');
Expand Down Expand Up @@ -244,7 +244,7 @@ protected function createGenericCollection(array $data = [], AbstractModel|strin
*/
protected function createCustomCollection(
array $data,
AbstractModel|string $class,
$class,
GenericCollection $collection
) {
if (!$class) {
Expand Down
6 changes: 5 additions & 1 deletion lib/Tmdb/Repository/TvEpisodeRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class TvEpisodeRepository extends AbstractRepository
* @return null|AbstractModel
* @throws RuntimeException
*/
public function load(Tv|int $tvShow, Season|int $season, Episode|int $episode, array $parameters = [], array $headers = [])
public function load($tvShow, $season, $episode, array $parameters = [], array $headers = [])
{
if ($tvShow instanceof Tv) {
$tvShow = $tvShow->getId();
Expand All @@ -65,6 +65,10 @@ public function load(Tv|int $tvShow, Season|int $season, Episode|int $episode, a
$episode = $episode->getEpisodeNumber();
}

if (is_null($tvShow) || is_null($season) || is_null($episode)) {
throw new RuntimeException('Not all required parameters to load an tv episode are present.');
}

if (!isset($parameters['append_to_response'])) {
$parameters = array_merge($parameters, [
new AppendToResponse([
Expand Down
6 changes: 5 additions & 1 deletion lib/Tmdb/Repository/TvSeasonRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ public function load(int|Tv $tvShow, int|Season $season, array $parameters = [],
$season = $season->getSeasonNumber();
}

if (null === $tvShow || null === $season) {
throw new RuntimeException('Not all required parameters to load an tv season are present.');
}

if (!isset($parameters['append_to_response'])) {
$parameters = array_merge($parameters, [
new AppendToResponse([
Expand Down Expand Up @@ -101,7 +105,7 @@ public function getFactory()
* @param array $headers
* @return CreditsCollection
*/
public function getCredits(Tv|int $tvShow, Season|int $season, array $parameters = [], array $headers = [])
public function getCredits($tvShow, $season, array $parameters = [], array $headers = [])
{
if ($tvShow instanceof Tv) {
$tvShow = $tvShow->getId();
Expand Down
4 changes: 2 additions & 2 deletions test/Tmdb/Tests/Repository/TvEpisodeRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public function shouldRateModel()
*/
public function shouldThrowExceptionWhenConditionsNotMet()
{
$this->expectException(TypeError::class);
$this->expectException(RuntimeException::class);
$repository = $this->getRepositoryWithMockedHttpClient();

$tv = new Tv();
Expand All @@ -264,7 +264,7 @@ public function shouldThrowExceptionWhenConditionsNotMet()
*/
public function shouldThrowExceptionWhenConditionsNotMetAll()
{
$this->expectException(TypeError::class);
$this->expectException(RuntimeException::class);
$repository = $this->getRepositoryWithMockedHttpClient();

$repository->load(null, null, null);
Expand Down

0 comments on commit f4ca761

Please sign in to comment.