Apply suggestions from code review
Co-authored-by: Jonathan Flueren <11487762+JonOfUs@users.noreply.github.com>
This commit is contained in:
parent
5a52efea07
commit
3a84b2506b
@ -56,7 +56,7 @@ class PersonalSettingsController extends Controller {
|
|||||||
return new JSONResponse([
|
return new JSONResponse([
|
||||||
'message' => "Missing query parameter 'url'.",
|
'message' => "Missing query parameter 'url'.",
|
||||||
'data' => null,
|
'data' => null,
|
||||||
], statusCode: Http::STATUS_BAD_REQUEST);
|
], Http::STATUS_BAD_REQUEST);
|
||||||
}
|
}
|
||||||
return new JsonResponse([
|
return new JsonResponse([
|
||||||
'data' => $this->dataReader->getCachedOrFetchPodcastData($url, $this->userId),
|
'data' => $this->dataReader->getCachedOrFetchPodcastData($url, $this->userId),
|
||||||
|
@ -42,18 +42,17 @@ class PodcastData implements JsonSerializable {
|
|||||||
$xml = new SimpleXMLElement($xmlString);
|
$xml = new SimpleXMLElement($xmlString);
|
||||||
$channel = $xml->channel;
|
$channel = $xml->channel;
|
||||||
return new PodcastData(
|
return new PodcastData(
|
||||||
title: self::stringOrNull($channel->title),
|
self::stringOrNull($channel->title),
|
||||||
author: self::getXPathContent($xml, '/rss/channel/itunes:author'),
|
self::getXPathContent($xml, '/rss/channel/itunes:author'),
|
||||||
link: self::stringOrNull($channel->link),
|
self::stringOrNull($channel->link),
|
||||||
description: self::stringOrNull($channel->description),
|
self::stringOrNull($channel->description),
|
||||||
imageUrl:
|
self::getXPathContent($xml, '/rss/channel/image/url')
|
||||||
self::getXPathContent($xml, '/rss/channel/image/url')
|
|
||||||
?? self::getXPathAttribute($xml, '/rss/channel/itunes:image/@href'),
|
?? self::getXPathAttribute($xml, '/rss/channel/itunes:image/@href'),
|
||||||
fetchedAtUnix: $fetchedAtUnix ?? (new DateTime())->getTimestamp(),
|
$fetchedAtUnix ?? (new DateTime())->getTimestamp()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function stringOrNull(mixed $value): ?string {
|
private static function stringOrNull($value): ?string {
|
||||||
if ($value) {
|
if ($value) {
|
||||||
return (string)$value;
|
return (string)$value;
|
||||||
}
|
}
|
||||||
@ -159,7 +158,7 @@ class PodcastData implements JsonSerializable {
|
|||||||
/**
|
/**
|
||||||
* @return array<string,mixed>
|
* @return array<string,mixed>
|
||||||
*/
|
*/
|
||||||
public function jsonSerialize(): mixed {
|
public function jsonSerialize(): array {
|
||||||
return $this->toArray();
|
return $this->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,13 +167,13 @@ class PodcastData implements JsonSerializable {
|
|||||||
*/
|
*/
|
||||||
public static function fromArray(array $data): PodcastData {
|
public static function fromArray(array $data): PodcastData {
|
||||||
return new PodcastData(
|
return new PodcastData(
|
||||||
title: $data['title'],
|
$data['title'],
|
||||||
author: $data['author'],
|
$data['author'],
|
||||||
link: $data['link'],
|
$data['link'],
|
||||||
description: $data['description'],
|
$data['description'],
|
||||||
imageUrl: $data['imageUrl'],
|
$data['imageUrl'],
|
||||||
fetchedAtUnix: $data['fetchedAtUnix'],
|
$data['fetchedAtUnix'],
|
||||||
imageBlob: $data['imageBlob'],
|
$data['imageBlob']
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,7 @@ class PodcastDataReader {
|
|||||||
$body = $resp->getBody();
|
$body = $resp->getBody();
|
||||||
$bodyBase64 = base64_encode($body);
|
$bodyBase64 = base64_encode($body);
|
||||||
return "data:$contentType;base64,$bodyBase64";
|
return "data:$contentType;base64,$bodyBase64";
|
||||||
} catch (Exception) {
|
} catch (Exception $e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ class PodcastMetrics implements JsonSerializable {
|
|||||||
/**
|
/**
|
||||||
* @return array<string,mixed>
|
* @return array<string,mixed>
|
||||||
*/
|
*/
|
||||||
public function jsonSerialize(): mixed {
|
public function jsonSerialize(): array {
|
||||||
return $this->toArray();
|
return $this->toArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,9 +65,9 @@ class PodcastMetricsReader {
|
|||||||
|
|
||||||
private function createMetricsForUrl(string $url): PodcastMetrics {
|
private function createMetricsForUrl(string $url): PodcastMetrics {
|
||||||
return new PodcastMetrics(
|
return new PodcastMetrics(
|
||||||
url: $url,
|
$url,
|
||||||
listenedSeconds: 0,
|
0,
|
||||||
actionCounts: new PodcastActionCounts(),
|
new PodcastActionCounts()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user