A free, self-hostable news aggregator…
Add some missing PHP native types (#7191)
Alexandre Alapetite50adb559823f
diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.phpindex 1436ffc68..6ecd9b501 100644--- a/app/Controllers/importExportController.php+++ b/app/Controllers/importExportController.php@@ -457,10 +457,13 @@ class FreshRSS_importExport_Controller extends FreshRSS_ActionController {$published = '0';}if (!ctype_digit($published)) {- $published = (string)strtotime($published);+ $published = (string)(strtotime($published) ?: 0);}if (strlen($published) > 10) { // Milliseconds, e.g. Feedly$published = substr($published, 0, -3);+ if (!is_numeric($published)) {+ $published = '0'; // For PHPStan+ }}$entry = new FreshRSS_Entry(diff --git a/app/Models/AttributesTrait.php b/app/Models/AttributesTrait.phpindex f30b11b5d..05fcb3c1b 100644--- a/app/Models/AttributesTrait.php+++ b/app/Models/AttributesTrait.php@@ -48,7 +48,7 @@ trait FreshRSS_AttributesTrait {}/** @param string|array<string,mixed> $values Values, not HTML-encoded */- public function _attributes($values): void {+ public function _attributes(string|array $values): void {if (is_string($values)) {$values = json_decode($values, true);}diff --git a/app/Models/BooleanSearch.php b/app/Models/BooleanSearch.phpindex f7273151e..1832bd419 100644--- a/app/Models/BooleanSearch.php+++ b/app/Models/BooleanSearch.php@@ -412,7 +412,7 @@ class FreshRSS_BooleanSearch implements \Stringable {}/** @param FreshRSS_BooleanSearch|FreshRSS_Search $search */- public function add($search): void {+ public function add(FreshRSS_BooleanSearch|FreshRSS_Search $search): void {$this->searches[] = $search;}diff --git a/app/Models/Category.php b/app/Models/Category.phpindex feaf7b79c..da902d6bd 100644--- a/app/Models/Category.php+++ b/app/Models/Category.php@@ -65,8 +65,7 @@ class FreshRSS_Category extends Minz_Model {return $this->error;}- /** @param bool|int $value */- public function _error($value): void {+ public function _error(bool|int $value): void {$this->error = (bool)$value;}public function isDefault(): bool {diff --git a/app/Models/Entry.php b/app/Models/Entry.phpindex c32506319..0919489fc 100644--- a/app/Models/Entry.php+++ b/app/Models/Entry.php@@ -37,6 +37,7 @@ class FreshRSS_Entry extends Minz_Model {/*** @param string|array<string> $tags+ * @param int|numeric-string $pubdate*/public function __construct(int $feedId = 0, string $guid = '', string $title = '', string $authors = '', string $content = '',string $link = '', int|string $pubdate = 0, bool|int|null $is_read = false, bool|int|null $is_favorite = false, $tags = '') {@@ -59,6 +60,10 @@ class FreshRSS_Entry extends Minz_Model {$dao['content'] = '';}+ if (!is_numeric($dao['date'] ?? null)) {+ $dao['date'] = 0;+ }+$dao['attributes'] = empty($dao['attributes']) ? [] : json_decode($dao['attributes'], true);if (!is_array($dao['attributes'])) {$dao['attributes'] = [];@@ -487,7 +492,7 @@ HTML;}/** @param int|numeric-string $value String is for compatibility with 32-bit platforms */- public function _id($value): void {+ public function _id(int|string $value): void {if (is_int($value)) {$value = (string)$value;}@@ -510,7 +515,7 @@ HTML;$this->_authors($value);}/** @param array<string>|string $value */- public function _authors($value): void {+ public function _authors(array|string $value): void {$this->hash = '';if (!is_array($value)) {if (str_contains($value, ';')) {@@ -531,8 +536,8 @@ HTML;$this->hash = '';$this->link = trim($value);}- /** @param int|string $value */- public function _date($value): void {+ /** @param int|numeric-string $value */+ public function _date(int|string $value): void {$value = (int)$value;$this->date = $value > 1 ? $value : time();}@@ -541,20 +546,20 @@ HTML;$this->lastSeen = $value > 0 ? $value : 0;}- /** @param int|string $value */- public function _dateAdded($value, bool $microsecond = false): void {+ /** @param int|numeric-string $value */+ public function _dateAdded(int|string $value, bool $microsecond = false): void {if ($microsecond) {$this->date_added = (string)($value);} else {$this->date_added = $value . '000000';}}- /** @param bool|int|null $value */- public function _isRead($value): void {++ public function _isRead(bool|int|null $value): void {$this->is_read = $value === null ? null : (bool)$value;}- /** @param bool|int|null $value */- public function _isFavorite($value): void {++ public function _isFavorite(bool|int|null $value): void {$this->is_favorite = $value === null ? null : (bool)$value;}@@ -563,14 +568,13 @@ HTML;$this->feedId = $this->feed == null ? 0 : $this->feed->id();}- /** @param int|string $id */- private function _feedId($id): void {+ private function _feedId(int $id): void {$this->feed = null;- $this->feedId = (int)$id;+ $this->feedId = $id;}/** @param array<string>|string $value */- public function _tags($value): void {+ public function _tags(array|string $value): void {$this->hash = '';if (!is_array($value)) {$value = preg_split('/\s*[#,]\s*/', $value, -1, PREG_SPLIT_NO_EMPTY) ?: [];@@ -1052,7 +1056,7 @@ HTML;* @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 {+ private static function dec2hex(string|int $dec): string {return PHP_INT_SIZE < 8 ? // 32-bit ?str_pad(gmp_strval(gmp_init($dec, 10), 16), 16, '0', STR_PAD_LEFT) :str_pad(dechex((int)($dec)), 16, '0', STR_PAD_LEFT);diff --git a/app/Models/EntryDAO.php b/app/Models/EntryDAO.phpindex 6075b0759..c169e0e24 100644--- a/app/Models/EntryDAO.php+++ b/app/Models/EntryDAO.php@@ -344,7 +344,7 @@ SQL;** @param numeric-string|list<numeric-string> $ids*/- public function markFavorite($ids, bool $is_favorite = true): int|false {+ public function markFavorite(string|array $ids, bool $is_favorite = true): int|false {if (!is_array($ids)) {$ids = [$ids];}diff --git a/app/Models/EntryDAOSQLite.php b/app/Models/EntryDAOSQLite.phpindex 6951afb27..e4cb9727e 100644--- a/app/Models/EntryDAOSQLite.php+++ b/app/Models/EntryDAOSQLite.php@@ -153,7 +153,7 @@ SQL;* @return int|false affected rows*/#[\Override]- public function markReadTag($id = 0, string $idMax = '0', ?FreshRSS_BooleanSearch $filters = null, int $state = 0, bool $is_read = true): int|false {+ public function markReadTag(int $id = 0, string $idMax = '0', ?FreshRSS_BooleanSearch $filters = null, int $state = 0, bool $is_read = true): int|false {FreshRSS_UserDAO::touch();if ($idMax == 0) {$idMax = time() . '000000';diff --git a/app/Models/Feed.php b/app/Models/Feed.phpindex 645dbcf3c..dd508299d 100644--- a/app/Models/Feed.php+++ b/app/Models/Feed.php@@ -287,8 +287,8 @@ class FreshRSS_Feed extends Minz_Model {$this->categoryId = $this->category == null ? 0 : $this->category->id();}- /** @param int|string $id */- public function _categoryId($id): void {+ /** @param int|numeric-string $id */+ public function _categoryId(int|string $id): void {$this->category = null;$this->categoryId = (int)$id;}@@ -321,8 +321,8 @@ class FreshRSS_Feed extends Minz_Model {public function _httpAuth(string $value): void {$this->httpAuth = $value;}- /** @param bool|int $value */- public function _error($value): void {++ public function _error(bool|int $value): void {$this->error = (bool)$value;}public function _mute(bool $value): void {@@ -350,7 +350,7 @@ class FreshRSS_Feed extends Minz_Model {/*** @throws Minz_FileNotExistException*/- if (CACHE_PATH == '') {+ if (trim(CACHE_PATH) === '') {throw new Minz_FileNotExistException('CACHE_PATH',Minz_Exception::ERROR@@ -549,6 +549,9 @@ class FreshRSS_Feed extends Minz_Model {$authors = $item->get_authors();$link = $item->get_permalink();$date = $item->get_date('U');+ if (!is_numeric($date)) {+ $date = 0;+ }//Tag processing (tag == category)$categories = $item->get_categories();diff --git a/app/Models/Tag.php b/app/Models/Tag.phpindex 9a3baffcd..dc74dcabd 100644--- a/app/Models/Tag.php+++ b/app/Models/Tag.php@@ -17,8 +17,8 @@ class FreshRSS_Tag extends Minz_Model {return $this->id;}- public function _id(int|string $value): void {- $this->id = (int)$value;+ public function _id(int $value): void {+ $this->id = $value;}public function name(): string {@@ -37,8 +37,8 @@ class FreshRSS_Tag extends Minz_Model {return $this->nbEntries;}- public function _nbEntries(int|string $value): void {- $this->nbEntries = (int)$value;+ public function _nbEntries(int $value): void {+ $this->nbEntries = $value;}public function nbUnread(): int {@@ -49,7 +49,7 @@ class FreshRSS_Tag extends Minz_Model {return $this->nbUnread;}- public function _nbUnread(int|string $value): void {- $this->nbUnread = (int)$value;+ public function _nbUnread(int $value): void {+ $this->nbUnread = $value;}}diff --git a/app/Models/TagDAO.php b/app/Models/TagDAO.phpindex 16b068a51..2f12c96d4 100644--- a/app/Models/TagDAO.php+++ b/app/Models/TagDAO.php@@ -407,7 +407,7 @@ SQL;}/**- * @param iterable<array{id:int,name:string,attributes?:string}> $listDAO+ * @param iterable<array{id:int,name:string,attributes?:string,unreads?:int}> $listDAO* @return array<int,FreshRSS_Tag> where the key is the label ID*/private static function daoToTags(iterable $listDAO): array {diff --git a/cli/i18n/I18nValue.php b/cli/i18n/I18nValue.phpindex ba6465062..d7f5107cc 100644--- a/cli/i18n/I18nValue.php+++ b/cli/i18n/I18nValue.php@@ -15,7 +15,7 @@ class I18nValue implements \Stringable {private ?string $state = null;/** @param I18nValue|string $data */- public function __construct($data) {+ public function __construct(I18nValue|string $data) {if ($data instanceof I18nValue) {$data = $data->__toString();}diff --git a/lib/Minz/Error.php b/lib/Minz/Error.phpindex e95fd346c..e44ec8579 100644--- a/lib/Minz/Error.php+++ b/lib/Minz/Error.php@@ -52,7 +52,7 @@ class Minz_Error {* @param string|array<'error'|'warning'|'notice',list<string>> $logs logs sorted by category (error, warning, notice)* @return list<string> list of matching logs, without the category, according to environment preferences (production / development)*/- private static function processLogs($logs): array {+ private static function processLogs(string|array $logs): array {if (is_string($logs)) {return [$logs];}diff --git a/lib/Minz/Paginator.php b/lib/Minz/Paginator.phpindex 7d6892c67..265b0c2cb 100644--- a/lib/Minz/Paginator.php+++ b/lib/Minz/Paginator.php@@ -64,11 +64,11 @@ class Minz_Paginator {* @param Minz_Model $item l'élément à retrouver* @return int|false la page à laquelle se trouve l’élément, false si non trouvé*/- public function pageByItem($item): int|false {+ public function pageByItem(Minz_Model $item): int|false {$i = 0;do {- if ($item == $this->items[$i]) {+ if ($item === $this->items[$i]) {return (int)(ceil(($i + 1) / $this->nbItemsPerPage));}$i++;@@ -82,11 +82,11 @@ class Minz_Paginator {* @param Minz_Model $item the element to search* @return int|false the position of the element, or false if not found*/- public function positionByItem($item): int|false {+ public function positionByItem(Minz_Model $item): int|false {$i = 0;do {- if ($item == $this->items[$i]) {+ if ($item === $this->items[$i]) {return $i;}$i++;diff --git a/lib/Minz/Request.php b/lib/Minz/Request.phpindex f441bcabf..3304ad480 100644--- a/lib/Minz/Request.php+++ b/lib/Minz/Request.php@@ -432,7 +432,7 @@ class Minz_Request {* @param bool $redirect If true, uses an HTTP redirection, and if false (default), performs an internal dispatcher redirection.* @throws Minz_ConfigurationException*/- public static function forward($url = [], bool $redirect = false): void {+ public static function forward(array $url = [], bool $redirect = false): void {if (empty(Minz_Request::originalRequest())) {self::$originalRequest = $url;}diff --git a/lib/Minz/View.php b/lib/Minz/View.phpindex 01e8501b0..65573c7bd 100644--- a/lib/Minz/View.php+++ b/lib/Minz/View.php@@ -247,7 +247,7 @@ class Minz_View {/*** @param string|array{dark?:string,light?:string,default?:string} $themeColors*/- public static function appendThemeColors($themeColors): void {+ public static function appendThemeColors(string|array $themeColors): void {self::$themeColors = $themeColors;}diff --git a/lib/lib_rss.php b/lib/lib_rss.phpindex c93243eff..2a5bdd02f 100644--- a/lib/lib_rss.php+++ b/lib/lib_rss.php@@ -217,8 +217,7 @@ function escapeToUnicodeAlternative(string $text, bool $extended = true): stringreturn trim(str_replace($problem, $replace, $text));}-/** @param int|float $n */-function format_number($n, int $precision = 0): string {+function format_number(int|float $n, int $precision = 0): string {// number_format does not seem to be Unicode-compatiblereturn str_replace(' ', ' ', // Thin non-breaking spacenumber_format((float)$n, $precision, '.', ' ')@@ -274,7 +273,7 @@ function html_only_entity_decode(?string $text): string {* @param array<string,mixed>|string $log* @return array<string,mixed>|string*/-function sensitive_log($log): array|string {+function sensitive_log(array|string $log): array|string {if (is_array($log)) {foreach ($log as $k => $v) {if (in_array($k, ['api_key', 'Passwd', 'T'], true)) {