diff options
| author | 2023-04-28 14:01:11 +0200 | |
|---|---|---|
| committer | 2023-04-28 14:01:11 +0200 | |
| commit | c72914bba2363e436574204b3d6093a6f3cfce89 (patch) | |
| tree | 377008a7393e4d80e4c8659f27dd42c0ccbab382 /app/Controllers | |
| parent | 26e2a703125ffe1d0d2746b0e5ea3491b627832c (diff) | |
PHPStan Level 7 for more DAO PDO (#5328)
* PHPStan Level 7 for more DAO PDO
With new function to address common type and check problems
* A bit more
* PHPStan Level 7 for FreshRSS_Entry
Diffstat (limited to 'app/Controllers')
| -rw-r--r-- | app/Controllers/categoryController.php | 12 | ||||
| -rw-r--r-- | app/Controllers/statsController.php | 33 | ||||
| -rw-r--r-- | app/Controllers/tagController.php | 2 |
3 files changed, 30 insertions, 17 deletions
diff --git a/app/Controllers/categoryController.php b/app/Controllers/categoryController.php index 0ca1bbbcd..60685c566 100644 --- a/app/Controllers/categoryController.php +++ b/app/Controllers/categoryController.php @@ -79,6 +79,8 @@ class FreshRSS_category_Controller extends FreshRSS_ActionController { /** * This action updates the given category. + * @todo Check whether this function is used at all + * @see FreshRSS_subscription_Controller::categoryAction() (consider merging) * * Request parameters are: * - id @@ -97,14 +99,16 @@ class FreshRSS_category_Controller extends FreshRSS_ActionController { Minz_Request::bad(_t('feedback.sub.category.no_name'), $url_redirect); } - if ($catDAO->searchById($id) == null) { + $cat = $catDAO->searchById($id); + if ($cat === null) { Minz_Request::bad(_t('feedback.sub.category.not_exist'), $url_redirect); } - $cat = new FreshRSS_Category($name); - $values = array( + $values = [ 'name' => $cat->name(), - ); + 'kind' => $cat->kind(), + 'attributes' => $cat->attributes(), + ]; if ($catDAO->updateCategory($id, $values)) { Minz_Request::good(_t('feedback.sub.category.updated'), $url_redirect); diff --git a/app/Controllers/statsController.php b/app/Controllers/statsController.php index 0fc6490f8..afbaccfc5 100644 --- a/app/Controllers/statsController.php +++ b/app/Controllers/statsController.php @@ -47,25 +47,34 @@ class FreshRSS_stats_Controller extends FreshRSS_ActionController { $statsDAO = FreshRSS_Factory::createStatsDAO(); FreshRSS_View::appendScript(Minz_Url::display('/scripts/vendor/chart.min.js?' . @filemtime(PUBLIC_PATH . '/scripts/vendor/chart.min.js'))); - $this->view->repartition = $statsDAO->calculateEntryRepartition(); + $this->view->repartitions = $statsDAO->calculateEntryRepartition(); $entryCount = $statsDAO->calculateEntryCount(); - $this->view->entryCount = $entryCount; - $this->view->average = round(array_sum(array_values($entryCount)) / count($entryCount), 2); + if (is_array($entryCount) && count($entryCount) > 0) { + $this->view->entryCount = $entryCount; + $this->view->average = round(array_sum(array_values($entryCount)) / count($entryCount), 2); + } else { + $this->view->entryCount = []; + $this->view->average = -1.0; + } - $feedByCategory_calculated = $statsDAO->calculateFeedByCategory(); $feedByCategory = []; - for ($i = 0; $i < count($feedByCategory_calculated); $i++) { - $feedByCategory['label'][$i] = $feedByCategory_calculated[$i]['label']; - $feedByCategory['data'][$i] = $feedByCategory_calculated[$i]['data']; + $feedByCategory_calculated = $statsDAO->calculateFeedByCategory(); + if (is_array($feedByCategory_calculated)) { + for ($i = 0; $i < count($feedByCategory_calculated); $i++) { + $feedByCategory['label'][$i] = $feedByCategory_calculated[$i]['label']; + $feedByCategory['data'][$i] = $feedByCategory_calculated[$i]['data']; + } } $this->view->feedByCategory = $feedByCategory; - $entryByCategory_calculated = $statsDAO->calculateEntryByCategory(); $entryByCategory = []; - for ($i = 0; $i < count($entryByCategory_calculated); $i++) { - $entryByCategory['label'][$i] = $entryByCategory_calculated[$i]['label']; - $entryByCategory['data'][$i] = $entryByCategory_calculated[$i]['data']; + $entryByCategory_calculated = $statsDAO->calculateEntryByCategory(); + if (is_array($entryByCategory_calculated)) { + for ($i = 0; $i < count($entryByCategory_calculated); $i++) { + $entryByCategory['label'][$i] = $entryByCategory_calculated[$i]['label']; + $entryByCategory['data'][$i] = $entryByCategory_calculated[$i]['data']; + } } $this->view->entryByCategory = $entryByCategory; @@ -114,7 +123,7 @@ class FreshRSS_stats_Controller extends FreshRSS_ActionController { FreshRSS_View::appendScript(Minz_Url::display('/scripts/feed.js?' . @filemtime(PUBLIC_PATH . '/scripts/feed.js'))); $feed_dao = FreshRSS_Factory::createFeedDao(); $statsDAO = FreshRSS_Factory::createStatsDAO(); - $feeds = $statsDAO->calculateFeedLastDate(); + $feeds = $statsDAO->calculateFeedLastDate() ?: []; $idleFeeds = array( 'last_5_year' => array(), 'last_3_year' => array(), diff --git a/app/Controllers/tagController.php b/app/Controllers/tagController.php index 7a89b2b84..c9dc7ce3e 100644 --- a/app/Controllers/tagController.php +++ b/app/Controllers/tagController.php @@ -132,7 +132,7 @@ class FreshRSS_tag_Controller extends FreshRSS_ActionController { $targetTag = $tagDAO->searchByName($targetName); if ($targetTag === null) { // There is no existing tag with the same target name - $tagDAO->updateTag($sourceId, ['name' => $targetName]); + $tagDAO->updateTagName($sourceId, $targetName); } else { // There is an existing tag with the same target name $tagDAO->updateEntryTag($sourceId, $targetTag->id()); |
