diff options
| author | 2024-06-09 20:32:12 +0200 | |
|---|---|---|
| committer | 2024-06-09 20:32:12 +0200 | |
| commit | 5b28a35003a015e29770094932157f13a3f7f5c0 (patch) | |
| tree | 4cbe4100379ca0d148115ad31f5a1c0c95ff7c80 /app/Models/Entry.php | |
| parent | e98c57841b843ed881f06ce6ed1c9c89942c27b8 (diff) | |
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
Diffstat (limited to 'app/Models/Entry.php')
| -rw-r--r-- | app/Models/Entry.php | 22 |
1 files changed, 15 insertions, 7 deletions
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 .= <<<HTML + if (is_string($elink) && ($allowDuplicateEnclosures || !self::containsLink($content, $elink))) { + $content .= <<<HTML <figure class="enclosure"> <p class="enclosure-content"> <img class="enclosure-thumbnail" src="{$elink}" alt="" /> @@ -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<array{'url':string,'type'?:string,'medium'?:string,'length'?:int,'title'?:string,'description'?:string,'credit'?:string|array<string>,'height'?:int,'width'?:int,'thumbnails'?:array<string>}> $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 { |
