From 5b28a35003a015e29770094932157f13a3f7f5c0 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sun, 9 Jun 2024 20:32:12 +0200 Subject: Pass PHPStan level 9 (#6544) * More PHPStan * More, passing * 4 more files * Update to PHPStan 1.11.4 Needed for fixed bug: Consider numeric-string types after string concat https://github.com/phpstan/phpstan/releases/tag/1.11.4 * Pass PHPStan level 9 Start tracking booleansInConditions * Fix mark as read * Fix doctype * ctype_digit --- app/Models/Entry.php | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'app/Models/Entry.php') diff --git a/app/Models/Entry.php b/app/Models/Entry.php index 2325252f7..e102c5c21 100644 --- a/app/Models/Entry.php +++ b/app/Models/Entry.php @@ -10,6 +10,7 @@ class FreshRSS_Entry extends Minz_Model { public const STATE_FAVORITE = 4; public const STATE_NOT_FAVORITE = 8; + /** @var numeric-string */ private string $id = '0'; private string $guid; private string $title; @@ -110,6 +111,7 @@ class FreshRSS_Entry extends Minz_Model { } } + /** @return numeric-string */ public function id(): string { return $this->id; } @@ -195,8 +197,8 @@ class FreshRSS_Entry extends Minz_Model { $thumbnailAttribute = $this->attributeArray('thumbnail') ?? []; if (!empty($thumbnailAttribute['url'])) { $elink = $thumbnailAttribute['url']; - if ($allowDuplicateEnclosures || !self::containsLink($content, $elink)) { - $content .= <<

@@ -216,7 +218,7 @@ HTML; continue; } $elink = $enclosure['url'] ?? ''; - if ($elink == '') { + if ($elink == '' || !is_string($elink)) { continue; } if (!$allowDuplicateEnclosures && self::containsLink($content, $elink)) { @@ -281,6 +283,7 @@ HTML; $attributeEnclosures = $this->attributeArray('enclosures'); if (is_iterable($attributeEnclosures)) { // FreshRSS 1.20.1+: The enclosures are saved as attributes + /** @var iterable,'height'?:int,'width'?:int,'thumbnails'?:array}> $attributeEnclosures */ yield from $attributeEnclosures; } try { @@ -296,8 +299,10 @@ HTML; // Legacy code for database entries < FreshRSS 1.20.1 $enclosures = $xpath->query('//div[@class="enclosure"]/p[@class="enclosure-content"]/*[@src]'); if (!empty($enclosures)) { - /** @var DOMElement $enclosure */ foreach ($enclosures as $enclosure) { + if (!($enclosure instanceof DOMElement)) { + continue; + } $result = [ 'url' => $enclosure->getAttribute('src'), 'type' => $enclosure->getAttribute('data-type'), @@ -318,8 +323,10 @@ HTML; if ($searchBodyImages && $xpath !== null) { $images = $xpath->query('//img'); if (!empty($images)) { - /** @var DOMElement $img */ foreach ($images as $img) { + if (!($img instanceof DOMElement)) { + continue; + } $src = $img->getAttribute('src'); if ($src == null) { $src = $img->getAttribute('data-src'); @@ -346,6 +353,7 @@ HTML; $thumbnail = $this->attributeArray('thumbnail') ?? []; // First, use the provided thumbnail, if any if (!empty($thumbnail['url'])) { + /** @var array{'url':string,'height'?:int,'width'?:int,'time'?:string} $thumbnail */ return $thumbnail; } if ($searchEnclosures) { @@ -467,7 +475,7 @@ HTML; return $this->hash; } - /** @param int|string $value String is for compatibility with 32-bit platforms */ + /** @param int|numeric-string $value String is for compatibility with 32-bit platforms */ public function _id($value): void { if (is_int($value)) { $value = (string)$value; @@ -882,7 +890,7 @@ HTML; /** * Integer format conversion for Google Reader API format - * @param string|int $dec Decimal number + * @param numeric-string|int $dec Decimal number * @return string 64-bit hexa http://code.google.com/p/google-reader-api/wiki/ItemId */ private static function dec2hex($dec): string { -- cgit v1.2.3