fedi-feed-router/app/Services/Parsers/BelgaHomepageParser.php
myrmidex ac1b461e41
Some checks failed
CI / ci (push) Failing after 31m11s
CI / ci (pull_request) Failing after 28m46s
115 - Satisfy PHPStan on Belga parser and fixture helpers
2026-08-02 00:08:14 +02:00

28 lines
765 B
PHP

<?php
namespace App\Services\Parsers;
class BelgaHomepageParser
{
private const ARTICLE_URL_TEMPLATE = 'https://www.belganewsagency.eu/press-releases/%s/';
/**
* @return array<int, string>
*/
public static function extractArticleUrls(string $json): array
{
$decoded = json_decode($json, true);
if (! is_array($decoded) || ! isset($decoded['data']) || ! is_array($decoded['data'])) {
return [];
}
return collect($decoded['data'])
->pluck('id')
->filter(fn($id) => is_int($id) || (is_string($id) && ctype_digit($id)))
->map(fn($id) => sprintf(self::ARTICLE_URL_TEMPLATE, $id))
->unique()
->values()
->toArray();
}
}