From 95277fd099987f8173287c9565494633157a0ac8 Mon Sep 17 00:00:00 2001 From: wn_ Date: Thu, 11 Nov 2021 22:28:13 +0000 Subject: Address PHPStan warnings in 'classes/labels.php'. --- classes/labels.php | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) (limited to 'classes/labels.php') diff --git a/classes/labels.php b/classes/labels.php index 570f24f4f..b9c480f82 100644 --- a/classes/labels.php +++ b/classes/labels.php @@ -1,15 +1,15 @@ prepare("SELECT id FROM ttrss_labels2 WHERE LOWER(caption) = LOWER(?) @@ -23,7 +23,7 @@ class Labels } } - static function find_caption($label, $owner_uid) { + static function find_caption(int $label, int $owner_uid): string { $pdo = Db::pdo(); $sth = $pdo->prepare("SELECT caption FROM ttrss_labels2 WHERE id = ? @@ -37,18 +37,24 @@ class Labels } } - static function get_as_hash($owner_uid) { + /** + * @return array> + */ + static function get_as_hash(int $owner_uid): array { $rv = []; $labels = Labels::get_all($owner_uid); foreach ($labels as $i => $label) { - $rv[$label["id"]] = $labels[$i]; + $rv[(int)$label["id"]] = $labels[$i]; } return $rv; } - static function get_all($owner_uid) { + /** + * @return array> An array of label detail arrays + */ + static function get_all(int $owner_uid) { $rv = array(); $pdo = Db::pdo(); @@ -64,7 +70,12 @@ class Labels return $rv; } - static function update_cache($owner_uid, $id, $labels = false, $force = false) { + /** + * @param array>|null $labels + * + * @see Article::_get_labels() + */ + static function update_cache(int $owner_uid, int $id, ?array $labels = null, bool $force = false): void { $pdo = Db::pdo(); if ($force) @@ -81,7 +92,7 @@ class Labels } - static function clear_cache($id) { + static function clear_cache(int $id): void { $pdo = Db::pdo(); @@ -91,7 +102,7 @@ class Labels } - static function remove_article($id, $label, $owner_uid) { + static function remove_article(int $id, string $label, int $owner_uid): void { $label_id = self::find_id($label, $owner_uid); @@ -109,7 +120,7 @@ class Labels self::clear_cache($id); } - static function add_article($id, $label, $owner_uid) { + static function add_article(int $id, string $label, int $owner_uid): void { $label_id = self::find_id($label, $owner_uid); @@ -138,7 +149,7 @@ class Labels } - static function remove($id, $owner_uid) { + static function remove(int $id, int $owner_uid): void { if (!$owner_uid) $owner_uid = $_SESSION["uid"]; $pdo = Db::pdo(); @@ -182,7 +193,10 @@ class Labels if (!$tr_in_progress) $pdo->commit(); } - static function create($caption, $fg_color = '', $bg_color = '', $owner_uid = false) { + /** + * @return false|int false if the check for an existing label failed, otherwise the number of rows inserted (1 on success) + */ + static function create(string $caption, ?string $fg_color = '', ?string $bg_color = '', ?int $owner_uid = null) { if (!$owner_uid) $owner_uid = $_SESSION['uid']; -- cgit v1.2.3 From 57bf56f7945b639d0e39f4c7ad9da161a4a18888 Mon Sep 17 00:00:00 2001 From: wn_ Date: Fri, 12 Nov 2021 01:50:40 +0000 Subject: Address PHPStan warnings in 'classes/article.php'. Also related changes in some other classes. --- classes/labels.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'classes/labels.php') diff --git a/classes/labels.php b/classes/labels.php index b9c480f82..d78f92139 100644 --- a/classes/labels.php +++ b/classes/labels.php @@ -71,11 +71,11 @@ class Labels } /** - * @param array>|null $labels + * @param array> $labels * * @see Article::_get_labels() */ - static function update_cache(int $owner_uid, int $id, ?array $labels = null, bool $force = false): void { + static function update_cache(int $owner_uid, int $id, array $labels, bool $force = false): void { $pdo = Db::pdo(); if ($force) -- cgit v1.2.3 From 9db5e402a0283deaae7d06496f410e9ab8deb1b4 Mon Sep 17 00:00:00 2001 From: wn_ Date: Fri, 12 Nov 2021 05:42:55 +0000 Subject: Address PHPStan warnings in 'classes/rpc.php'. Also a couple minor fixes in 'classes/article.php' and 'classes/labels.php'. --- classes/labels.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'classes/labels.php') diff --git a/classes/labels.php b/classes/labels.php index d78f92139..5a17d665e 100644 --- a/classes/labels.php +++ b/classes/labels.php @@ -71,7 +71,7 @@ class Labels } /** - * @param array> $labels + * @param array>> $labels * * @see Article::_get_labels() */ -- cgit v1.2.3 From b37a03fb31cf1c394e36ccf082bb5d3359f3a1fb Mon Sep 17 00:00:00 2001 From: wn_ Date: Sat, 13 Nov 2021 14:41:22 +0000 Subject: Fix the type of Labels::update_cache() --- classes/labels.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'classes/labels.php') diff --git a/classes/labels.php b/classes/labels.php index 5a17d665e..026e6621f 100644 --- a/classes/labels.php +++ b/classes/labels.php @@ -71,7 +71,8 @@ class Labels } /** - * @param array>> $labels + * @param array{'no-labels': 1}|array> $labels + * [label_id, caption, fg_color, bg_color] * * @see Article::_get_labels() */ -- cgit v1.2.3