diff options
| author | 2023-06-08 16:00:30 +0200 | |
|---|---|---|
| committer | 2023-06-08 16:00:30 +0200 | |
| commit | bab353ce6156c4d9344c641611aa712a99f20a94 (patch) | |
| tree | bb26c46494907f7a9a8c14bdd4a5282a48e2fafc /app/Models/Category.php | |
| parent | 0308c33d97c218aa4324cd1079cf957565b347ae (diff) | |
phpstan-8 for category class (#5434)
* phpstan-8 for category class
* Another approach to nullable
https://github.com/FreshRSS/FreshRSS/pull/5434#discussion_r1210776699
---------
Co-authored-by: Luc <sanchezluc+freshrss@gmail.com>
Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>
Diffstat (limited to 'app/Models/Category.php')
| -rw-r--r-- | app/Models/Category.php | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/app/Models/Category.php b/app/Models/Category.php index 4e28b1741..c9c919e4a 100644 --- a/app/Models/Category.php +++ b/app/Models/Category.php @@ -36,7 +36,7 @@ class FreshRSS_Category extends Minz_Model { /** * @param array<FreshRSS_Feed>|null $feeds */ - public function __construct(string $name = '', array $feeds = null) { + public function __construct(string $name = '', ?array $feeds = null) { $this->_name($name); if ($feeds !== null) { $this->_feeds($feeds); @@ -99,7 +99,11 @@ class FreshRSS_Category extends Minz_Model { return $this->nbNotRead; } - /** @return array<FreshRSS_Feed> */ + /** + * @return array<FreshRSS_Feed> + * @throws Minz_ConfigurationNamespaceException + * @throws Minz_PDOConnectionException + */ public function feeds(): array { if ($this->feeds === null) { $feedDAO = FreshRSS_Factory::createFeedDao(); @@ -115,7 +119,7 @@ class FreshRSS_Category extends Minz_Model { $this->sortFeeds(); } - return $this->feeds; + return $this->feeds ?? []; } public function hasFeedsWithError(): bool { @@ -266,6 +270,9 @@ class FreshRSS_Category extends Minz_Model { } private function sortFeeds(): void { + if ($this->feeds === null) { + return; + } usort($this->feeds, static function (FreshRSS_Feed $a, FreshRSS_Feed $b) { return strnatcasecmp($a->name(), $b->name()); }); |
