115 - Satisfy PHPStan on Belga parser and fixture helpers
Some checks failed
CI / ci (push) Failing after 31m11s
CI / ci (pull_request) Failing after 28m46s

This commit is contained in:
myrmidex 2026-08-02 00:08:14 +02:00
parent 3bded659d2
commit ac1b461e41
3 changed files with 27 additions and 8 deletions

View file

@ -6,6 +6,9 @@ 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);
@ -16,8 +19,8 @@ public static function extractArticleUrls(string $json): array
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))
->filter(fn($id) => is_int($id) || (is_string($id) && ctype_digit($id)))
->map(fn($id) => sprintf(self::ARTICLE_URL_TEMPLATE, $id))
->unique()
->values()
->toArray();

View file

@ -22,7 +22,11 @@ class ArticleFetcherBelgaTest extends TestCase
private function apiResponse(): string
{
return file_get_contents(__DIR__.'/../../Fixtures/belga-pressreleases.json');
$contents = file_get_contents(__DIR__.'/../../Fixtures/belga-pressreleases.json');
$this->assertNotFalse($contents, 'Belga fixture could not be read.');
return $contents;
}
private function belgaFeed(): Feed

View file

@ -10,7 +10,19 @@ class BelgaHomepageParserTest extends TestCase
{
private function fixture(): string
{
return file_get_contents(__DIR__.'/../../../Fixtures/belga-pressreleases.json');
$contents = file_get_contents(__DIR__.'/../../../Fixtures/belga-pressreleases.json');
$this->assertNotFalse($contents, 'Belga fixture could not be read.');
return $contents;
}
/**
* @param array<int, array<string, mixed>> $data
*/
private function jsonWith(array $data): string
{
return (string) json_encode(['data' => $data]);
}
public function test_extracts_article_urls_from_api_json(): void
@ -24,12 +36,12 @@ public function test_extracts_article_urls_from_api_json(): void
public function test_deduplicates_urls(): void
{
$json = json_encode(['data' => [
$json = $this->jsonWith([
['id' => 100],
['id' => 100],
['id' => '100'],
['id' => 101],
]]);
]);
$urls = BelgaHomepageParser::extractArticleUrls($json);
@ -55,13 +67,13 @@ public function test_returns_empty_array_when_data_key_missing_or_empty(): void
public function test_skips_entries_without_usable_id(): void
{
$json = json_encode(['data' => [
$json = $this->jsonWith([
['id' => 200],
['id' => null],
['publishDate' => '2026-08-01T06:24:19'],
['id' => 'not-numeric'],
['id' => 201],
]]);
]);
$urls = BelgaHomepageParser::extractArticleUrls($json);