aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Luc SANCHEZ <4697568+ColonelMoutarde@users.noreply.github.com> 2023-06-08 16:00:30 +0200
committerGravatar GitHub <noreply@github.com> 2023-06-08 16:00:30 +0200
commitbab353ce6156c4d9344c641611aa712a99f20a94 (patch)
treebb26c46494907f7a9a8c14bdd4a5282a48e2fafc
parent0308c33d97c218aa4324cd1079cf957565b347ae (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>
-rw-r--r--app/Models/Category.php13
-rw-r--r--tests/phpstan-next.txt1
2 files changed, 10 insertions, 4 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());
});
diff --git a/tests/phpstan-next.txt b/tests/phpstan-next.txt
index ba06802de..b241caa2f 100644
--- a/tests/phpstan-next.txt
+++ b/tests/phpstan-next.txt
@@ -24,7 +24,6 @@
./app/Mailers/UserMailer.php
./app/Models/Auth.php
./app/Models/BooleanSearch.php
-./app/Models/Category.php
./app/Models/Context.php
./app/Models/DatabaseDAO.php
./app/Models/DatabaseDAOPGSQL.php