Skip to content

Commit

Permalink
Refactor code to use null instead of an empty array in getImage() method
Browse files Browse the repository at this point in the history
  • Loading branch information
ewilan-riviere committed Sep 13, 2024
1 parent 8f3710b commit 1b16d37
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ $movie = Tmdb::client('API_KEY')
->movies()
->details(movie_id: 120); // ?\Kiwilan\Tmdb\Models\Movie

$poster_url = $movie->getPosterUrl(size: PosterSize::W500); // string|null (url to poster)
$poster_url = $movie->getPosterUrl(size: PosterSize::W500); // string|null (URL to poster)
```

These methods are available for `Poster`, `Backdrop`, `Logo`, `Profile` and `Still`.
Expand Down
8 changes: 6 additions & 2 deletions src/Utils/TmdbImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ public function getUrl(): string
/**
* Get the image content, as binary.
*/
public function getImage(): string
public function getImage(): ?string
{
$url = $this->getUrl();
$contents = file_get_contents($url);

return file_get_contents($url);
return $contents !== false ? $contents : null;
}

/**
Expand All @@ -45,6 +46,9 @@ public function getImage(): string
public function saveImage(string $path): bool
{
$contents = $this->getImage();
if ($contents === null) {
return false;
}

return file_put_contents($path, $contents) !== false;
}
Expand Down

0 comments on commit 1b16d37

Please sign in to comment.