chore: cleanup
This commit is contained in:
@@ -22,7 +22,7 @@ class TmdbMovieResultDenormalizer extends TmdbResultDenormalizer implements Deno
|
||||
public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): TmdbResult|array|null
|
||||
{
|
||||
/** @var TmdbResult $result */
|
||||
$result = $this->normalizer->denormalize($data, TmdbResult::class, $format, $context);
|
||||
$result = parent::denormalize($data, TmdbResult::class, $format, $context);
|
||||
|
||||
if (array_key_exists('release_date', $data) && !in_array($data['release_date'], ['', null,])) {
|
||||
$airDate = (new \DateTime($data['release_date']));
|
||||
@@ -34,9 +34,7 @@ class TmdbMovieResultDenormalizer extends TmdbResultDenormalizer implements Deno
|
||||
$result->premiereDate = $airDate;
|
||||
$result->poster = (null !== $data['poster_path']) ? self::POSTER_IMG_PATH . $data['poster_path'] : null;
|
||||
$result->year = (null !== $airDate) ? $airDate->format('Y') : null;
|
||||
$result->mediaType = "movies";
|
||||
$result->stars = $this->getStars($data);
|
||||
$result->directors = $this->getDirectors($data);
|
||||
$result->mediaType = MediaType::Movie->value;
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,12 @@ class TmdbResultDenormalizer implements DenormalizerInterface
|
||||
|
||||
public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): TmdbResult|array|null
|
||||
{
|
||||
return $this->normalizer->denormalize($data, TmdbResult::class, $format, $context);
|
||||
$result = $this->normalizer->denormalize($data, TmdbResult::class, $format, $context);
|
||||
$result->stars = $this->getStars($data);
|
||||
$result->directors = $this->getDirectors($data);
|
||||
$result->producers = $this->getProducers($data);
|
||||
$result->creators = $this->getCreators($data);
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function getStars(array $data): ?array
|
||||
@@ -49,6 +54,28 @@ class TmdbResultDenormalizer implements DenormalizerInterface
|
||||
->toArray();
|
||||
}
|
||||
|
||||
public function getCreators(array $data): ?array
|
||||
{
|
||||
if (!array_key_exists('credits', $data)) {
|
||||
return null;
|
||||
}
|
||||
return Map::from($data['credits']['crew'])
|
||||
->filter(fn($item) => $item['job'] === 'Creator')
|
||||
->map(fn($item) => $this->normalizer->denormalize($item, CrewMemberDto::class))
|
||||
->toArray();
|
||||
}
|
||||
|
||||
public function getProducers(array $data): ?array
|
||||
{
|
||||
if (!array_key_exists('credits', $data)) {
|
||||
return null;
|
||||
}
|
||||
return Map::from($data['credits']['crew'])
|
||||
->filter(fn($item) => $item['job'] === 'Producer')
|
||||
->map(fn($item) => $this->normalizer->denormalize($item, CrewMemberDto::class))
|
||||
->toArray();
|
||||
}
|
||||
|
||||
public function getGenres(array $data, MediaType $mediaType): ?array
|
||||
{
|
||||
if (array_key_exists('genres', $data)) {
|
||||
|
||||
@@ -20,7 +20,7 @@ class TmdbTvShowResultDenormalizer extends TmdbResultDenormalizer implements Den
|
||||
public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): TmdbResult|array|null
|
||||
{
|
||||
/** @var TmdbResult $result */
|
||||
$result = $this->normalizer->denormalize($data, TmdbResult::class, $format, $context);
|
||||
$result = parent::denormalize($data, TmdbResult::class, $format, $context);
|
||||
|
||||
if (!in_array($data['first_air_date'], ['', null,])) {
|
||||
$airDate = (new \DateTime($data['first_air_date']));
|
||||
@@ -28,11 +28,16 @@ class TmdbTvShowResultDenormalizer extends TmdbResultDenormalizer implements Den
|
||||
$airDate = null;
|
||||
}
|
||||
|
||||
if (array_key_exists('seasons', $data)) {
|
||||
$result->numberSeasons = count($data['seasons']);
|
||||
}
|
||||
|
||||
$result->title = $data['original_name'];
|
||||
$result->premiereDate = $airDate;
|
||||
$result->poster = (null !== $data['poster_path']) ? self::POSTER_IMG_PATH . $data['poster_path'] : null;
|
||||
$result->year = (null !== $airDate) ? $airDate->format('Y') : null;
|
||||
$result->mediaType = MediaType::TvShow->value;
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user