diff --git a/.gitattributes b/.gitattributes index efc16726d..a9f0731e0 100644 --- a/.gitattributes +++ b/.gitattributes @@ -4,9 +4,12 @@ /compatibility_test export-ignore /demo export-ignore /tests export-ignore +/utils/PHPStan export-ignore .gitattributes export-ignore .editorconfig export-ignore .gitignore export-ignore ROADMAP.md export-ignore phpunit.xml.dist export-ignore .php-cs-fixer.dist.php export-ignore +db.sql export-ignore +phpstan.dist.neon export-ignore diff --git a/src/File.php b/src/File.php index a5396e576..873509d54 100644 --- a/src/File.php +++ b/src/File.php @@ -123,7 +123,7 @@ public function __construct(string $url, int $timeout = 10, int $redirects = 5, } if (version_compare(\SimplePie\Misc::get_curl_version(), '7.21.6', '>=')) { curl_setopt($fp, CURLOPT_ACCEPT_ENCODING, ''); - } elseif (version_compare(\SimplePie\Misc::get_curl_version(), '7.10.5', '>=')) { + } else { curl_setopt($fp, CURLOPT_ENCODING, ''); } curl_setopt($fp, CURLOPT_URL, $url); diff --git a/src/Item.php b/src/Item.php index 978cf518c..d638250cc 100644 --- a/src/Item.php +++ b/src/Item.php @@ -677,7 +677,7 @@ public function get_date(string $date_format = 'j F Y, g:i a') return $this->data['date']['parsed']; default: - return date($date_format, $this->data['date']['parsed']); + return $this->data['date']['parsed'] !== null ? date($date_format, $this->data['date']['parsed']) : null; } } diff --git a/tests/Unit/ItemTest.php b/tests/Unit/ItemTest.php index 44fe873b5..b1ace1190 100644 --- a/tests/Unit/ItemTest.php +++ b/tests/Unit/ItemTest.php @@ -663,7 +663,7 @@ public function test_get_content(string $data, string $expected): void } /** - * @return array + * @return array */ public static function getDateDataProvider(): array { @@ -1318,13 +1318,56 @@ public static function getDateDataProvider(): array , 1168531200, ], + 'Test RFC 2822 formatted date' => [ +<< + + + Thu, 11 Jan 2007 16:00:00 +0000 + + + +XML + , + 1168531200 + ], + 'Test date is properly formatted' => [ +<< + + + Thu, 11 Jan 2007 16:00:00 +0000 + + + +XML + , + '2007-01-11', + 'Y-m-d' + ], + 'Invalid format: localized RFC 2822 formatted date' => [ +<< + + + Ost, 11 Urt 2007 16:00:00 +0000 + + + +XML + , + null, + 'Y-m-d' + ], ]; } /** + * @param int|string|null $expected + * * @dataProvider getDateDataProvider */ - public function test_get_date(string $data, ?int $expected): void + public function test_get_date(string $data, $expected, string $format = 'U'): void { $feed = new SimplePie(); $feed->set_raw_data($data); @@ -1334,7 +1377,7 @@ public function test_get_date(string $data, ?int $expected): void $item = $feed->get_item(0); self::assertInstanceOf(Item::class, $item); - self::assertSame($expected, $item->get_date('U')); + self::assertSame($expected, $item->get_date($format)); } /**