diff options
| author | 2024-12-27 12:12:49 +0100 | |
|---|---|---|
| committer | 2024-12-27 12:12:49 +0100 | |
| commit | b1d24fbdb7d1cc948c946295035dad6df550fb7e (patch) | |
| tree | 7b4365a04097a779659474fbb9281a9661512522 /app/Models/StatsDAO.php | |
| parent | 897e4a3f4a273d50c28157edb67612b2d7fa2e6f (diff) | |
PHPStan 2.0 (#7131)
* PHPStan 2.0
fix https://github.com/FreshRSS/FreshRSS/issues/6989
https://github.com/phpstan/phpstan/releases/tag/2.0.0
https://github.com/phpstan/phpstan/blob/2.0.x/UPGRADING.md
* More
* More
* Done
* fix i18n CLI
* Restore a PHPStan Next test
For work towards PHPStan Level 10
* 4 more on Level 10
* fix getTagsForEntry
* API at Level 10
* More Level 10
* Finish Minz at Level 10
* Finish CLI at Level 10
* Finish Controllers at Level 10
* More Level 10
* More
* Pass bleedingEdge
* Clean PHPStan options and add TODOs
* Level 10 for main config
* More
* Consitency array vs. list
* Sanitize themes get_infos
* Simplify TagDAO->getTagsForEntries()
* Finish reportAnyTypeWideningInVarTag
* Prepare checkBenevolentUnionTypes and checkImplicitMixed
* Fixes
* Refix
* Another fix
* Casing of __METHOD__ constant
Diffstat (limited to 'app/Models/StatsDAO.php')
| -rw-r--r-- | app/Models/StatsDAO.php | 42 |
1 files changed, 17 insertions, 25 deletions
diff --git a/app/Models/StatsDAO.php b/app/Models/StatsDAO.php index 6782bd7ee..d098b81a4 100644 --- a/app/Models/StatsDAO.php +++ b/app/Models/StatsDAO.php @@ -29,7 +29,7 @@ class FreshRSS_StatsDAO extends Minz_ModelPdo { * - unread entries * - favorite entries * - * @return array{'total':int,'count_unreads':int,'count_reads':int,'count_favorites':int}|false + * @return array{total:int,count_unreads:int,count_reads:int,count_favorites:int}|false */ public function calculateEntryRepartitionPerFeed(?int $feed = null, bool $only_main = false): array|false { $filter = ''; @@ -49,10 +49,9 @@ WHERE e.id_feed = f.id {$filter} SQL; $res = $this->fetchAssoc($sql); - if (!empty($res[0])) { + if (is_array($res) && !empty($res[0])) { $dao = $res[0]; - /** @var array<array{'total':int,'count_unreads':int,'count_reads':int,'count_favorites':int}> $res */ - FreshRSS_DatabaseDAO::pdoInt($dao, ['total', 'count_unreads', 'count_reads', 'count_favorites']); + /** @var array{total:int,count_unreads:int,count_reads:int,count_favorites:int} $dao */ return $dao; } return false; @@ -78,10 +77,10 @@ GROUP BY day ORDER BY day ASC SQL; $res = $this->fetchAssoc($sql); - if ($res == false) { + if (!is_array($res)) { return []; } - /** @var array<array{'day':int,'count':int}> $res */ + /** @var list<array{day:int,count:int}> $res */ foreach ($res as $value) { $count[(int)($value['day'])] = (int)($value['count']); } @@ -123,7 +122,6 @@ SQL; return $monthRepartition; } - /** * Calculates the number of article per period per feed * @param string $period format string to use for grouping @@ -228,7 +226,7 @@ SQL; /** * Calculates feed count per category. - * @return array<array{'label':string,'data':int}> + * @return list<array{'label':string,'data':int}> */ public function calculateFeedByCategory(): array { $sql = <<<SQL @@ -239,14 +237,14 @@ WHERE c.id = f.category GROUP BY label ORDER BY data DESC SQL; - /** @var array<array{'label':string,'data':int}>|null @res */ + /** @var list<array{'label':string,'data':int}>|null @res */ $res = $this->fetchAssoc($sql); return $res == null ? [] : $res; } /** * Calculates entry count per category. - * @return array<array{'label':string,'data':int}> + * @return list<array{'label':string,'data':int}> */ public function calculateEntryByCategory(): array { $sql = <<<SQL @@ -259,13 +257,13 @@ GROUP BY label ORDER BY data DESC SQL; $res = $this->fetchAssoc($sql); - /** @var array<array{'label':string,'data':int}>|null $res */ + /** @var list<array{'label':string,'data':int}>|null $res */ return $res == null ? [] : $res; } /** * Calculates the 10 top feeds based on their number of entries - * @return array<array{'id':int,'name':string,'category':string,'count':int}> + * @return list<array{'id':int,'name':string,'category':string,'count':int}> */ public function calculateTopFeed(): array { $sql = <<<SQL @@ -281,11 +279,8 @@ ORDER BY count DESC LIMIT 10 SQL; $res = $this->fetchAssoc($sql); - /** @var array<array{'id':int,'name':string,'category':string,'count':int}>|null $res */ + /** @var list<array{'id':int,'name':string,'category':string,'count':int}>|null $res */ if (is_array($res)) { - foreach ($res as &$dao) { - FreshRSS_DatabaseDAO::pdoInt($dao, ['id', 'count']); - } return $res; } return []; @@ -293,7 +288,7 @@ SQL; /** * Calculates the last publication date for each feed - * @return array<array{'id':int,'name':string,'last_date':int,'nb_articles':int}> + * @return list<array{'id':int,'name':string,'last_date':int,'nb_articles':int}> */ public function calculateFeedLastDate(): array { $sql = <<<SQL @@ -307,11 +302,8 @@ GROUP BY f.id ORDER BY name SQL; $res = $this->fetchAssoc($sql); - /** @var array<array{'id':int,'name':string,'last_date':int,'nb_articles':int}>|null $res */ + /** @var list<array{'id':int,'name':string,'last_date':int,'nb_articles':int}>|null $res */ if (is_array($res)) { - foreach ($res as &$dao) { - FreshRSS_DatabaseDAO::pdoInt($dao, ['id', 'last_date', 'nb_articles']); - } return $res; } return []; @@ -319,7 +311,7 @@ SQL; /** * Gets days ready for graphs - * @return array<string> + * @return list<string> */ public function getDays(): array { return $this->convertToTranslatedJson([ @@ -335,7 +327,7 @@ SQL; /** * Gets months ready for graphs - * @return array<string> + * @return list<string> */ public function getMonths(): array { return $this->convertToTranslatedJson([ @@ -356,8 +348,8 @@ SQL; /** * Translates array content - * @param array<string> $data - * @return array<string> + * @param list<string> $data + * @return list<string> */ private function convertToTranslatedJson(array $data = []): array { $translated = array_map(static fn(string $a) => _t('gen.date.' . $a), $data); |
