Ver Fonte

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>
Luc SANCHEZ há 2 anos atrás
pai
commit
bab353ce61
2 ficheiros alterados com 10 adições e 4 exclusões
  1. 10 3
      app/Models/Category.php
  2. 0 1
      tests/phpstan-next.txt

+ 10 - 3
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());
 		});

+ 0 - 1
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