2022-07-08 14:53:04 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Values;
|
|
|
|
|
|
|
|
use Illuminate\Contracts\Support\Arrayable;
|
|
|
|
|
|
|
|
final class ArtistInformation implements Arrayable
|
|
|
|
{
|
|
|
|
use FormatsLastFmText;
|
|
|
|
|
2022-07-14 05:18:44 +00:00
|
|
|
private function __construct(public ?string $url, public ?string $image, public array $bio)
|
2022-07-08 14:53:04 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function fromLastFmData(object $data): self
|
|
|
|
{
|
|
|
|
return new self(
|
|
|
|
url: $data->url,
|
|
|
|
image: count($data->image) > 3 ? $data->image[3]->{'#text'} : $data->image[0]->{'#text'},
|
|
|
|
bio: [
|
|
|
|
'summary' => isset($data->bio) ? self::formatLastFmText($data->bio->summary) : '',
|
|
|
|
'full' => isset($data->bio) ? self::formatLastFmText($data->bio->content) : '',
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @return array<mixed> */
|
|
|
|
public function toArray(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'url' => $this->url,
|
|
|
|
'image' => $this->image,
|
|
|
|
'bio' => $this->bio,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|