Skip to content

Commit

Permalink
fix: make getSoleValue return null instead of throwing
Browse files Browse the repository at this point in the history
  • Loading branch information
phanan committed May 24, 2024
1 parent 618963b commit 8c14629
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions src/Poddle.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,24 +76,28 @@ public function getEpisodes(): EpisodeCollection
*/
private function getSoleValue(string ...$queries): ?string
{
foreach ($queries as $query) {
if (!Str::startsWith('/rss/channel/', $query)) {
$query = '/rss/channel/'.ltrim($query, '/');
try {
foreach ($queries as $query) {
if (!Str::startsWith('/rss/channel/', $query)) {
$query = '/rss/channel/' . ltrim($query, '/');
}

if (Str::contains($query, '@')) {
[$query, $attribute] = explode('@', $query, 2);
$value = $this->xmlReader->xpathElement($query)->first()?->getAttribute($attribute); // @phpstan-ignore-line
} else {
$value = $this->xmlReader->xpathValue($query)->first();
}

if ($value) {
return $value;
}
}

if (Str::contains($query, '@')) {
[$query, $attribute] = explode('@', $query, 2);
$value = $this->xmlReader->xpathElement($query)->first()?->getAttribute($attribute); // @phpstan-ignore-line
} else {
$value = $this->xmlReader->xpathValue($query)->first();
}

if ($value) {
return $value;
}
return null;
} catch (Throwable) {
return null;
}

return null;
}

/**
Expand Down

0 comments on commit 8c14629

Please sign in to comment.