aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2023-05-13 22:47:51 +0200
committerGravatar GitHub <noreply@github.com> 2023-05-13 22:47:51 +0200
commitd8c535c25c2330f9c2b7ee19d74b6d2b4a3bf4b6 (patch)
tree45b3ad4f13f051f0061ade5f1d4d3dc90ae7e045
parent68766a98574d98be358199924222f26d8ac36561 (diff)
PHPStan Level 7 for Share userController logs_pagination (#5393)
-rw-r--r--app/Controllers/configureController.php2
-rw-r--r--app/Controllers/userController.php13
-rw-r--r--app/Models/FeedDAO.php7
-rw-r--r--app/Models/Share.php60
-rw-r--r--app/Models/View.php4
-rwxr-xr-xapp/views/helpers/logs_pagination.phtml4
-rw-r--r--lib/Minz/Paginator.php4
-rw-r--r--tests/phpstan-next.txt3
8 files changed, 54 insertions, 43 deletions
diff --git a/app/Controllers/configureController.php b/app/Controllers/configureController.php
index 7611d93b2..2e0b14f4e 100644
--- a/app/Controllers/configureController.php
+++ b/app/Controllers/configureController.php
@@ -264,7 +264,7 @@ class FreshRSS_configure_Controller extends FreshRSS_ActionController {
FreshRSS_Context::$user_conf->volatile = $volatile;
$entryDAO = FreshRSS_Factory::createEntryDao();
- $this->view->nb_total = $entryDAO->count() ?: 0;
+ $this->view->nb_total = $entryDAO->count();
$databaseDAO = FreshRSS_Factory::createDatabaseDAO();
$this->view->size_user = $databaseDAO->size();
diff --git a/app/Controllers/userController.php b/app/Controllers/userController.php
index 650f96fb2..f929fc779 100644
--- a/app/Controllers/userController.php
+++ b/app/Controllers/userController.php
@@ -392,7 +392,10 @@ class FreshRSS_user_Controller extends FreshRSS_ActionController {
$oldUserDAO = FreshRSS_Factory::createUserDao($username);
$ok &= $oldUserDAO->deleteUser();
$ok &= recursive_unlink($user_data);
- array_map('unlink', glob(PSHB_PATH . '/feeds/*/' . $username . '.txt'));
+ $filenames = glob(PSHB_PATH . '/feeds/*/' . $username . '.txt');
+ if (!empty($filenames)) {
+ array_map('unlink', $filenames);
+ }
}
return (bool)$ok;
}
@@ -628,7 +631,7 @@ class FreshRSS_user_Controller extends FreshRSS_ActionController {
$this->view->details = $this->retrieveUserDetails($username);
}
- /** @return array{'feed_count':int|false,'article_count':int|false,'database_size':int,'language':string,'mail_login':string,'enabled':bool,'is_admin':bool,'last_user_activity':string,'is_default':bool} */
+ /** @return array{'feed_count':int,'article_count':int,'database_size':int,'language':string,'mail_login':string,'enabled':bool,'is_admin':bool,'last_user_activity':string,'is_default':bool} */
private function retrieveUserDetails(string $username): array {
$feedDAO = FreshRSS_Factory::createFeedDao($username);
$entryDAO = FreshRSS_Factory::createEntryDao($username);
@@ -636,7 +639,7 @@ class FreshRSS_user_Controller extends FreshRSS_ActionController {
$userConfiguration = get_user_configuration($username);
- return array(
+ return [
'feed_count' => $feedDAO->count(),
'article_count' => $entryDAO->count(),
'database_size' => $databaseDAO->size(),
@@ -644,8 +647,8 @@ class FreshRSS_user_Controller extends FreshRSS_ActionController {
'mail_login' => $userConfiguration->mail_login,
'enabled' => $userConfiguration->enabled,
'is_admin' => $userConfiguration->is_admin,
- 'last_user_activity' => date('c', FreshRSS_UserDAO::mtime($username)),
+ 'last_user_activity' => date('c', FreshRSS_UserDAO::mtime($username)) ?: '',
'is_default' => FreshRSS_Context::$system_conf->default_user === $username,
- );
+ ];
}
}
diff --git a/app/Models/FeedDAO.php b/app/Models/FeedDAO.php
index 67543b597..ec51486a6 100644
--- a/app/Models/FeedDAO.php
+++ b/app/Models/FeedDAO.php
@@ -640,14 +640,11 @@ SQL;
}
}
- /**
- * @return int|false
- */
- public function count() {
+ public function count(): int {
$sql = 'SELECT COUNT(e.id) AS count FROM `_feed` e';
$stm = $this->pdo->query($sql);
if ($stm == false) {
- return false;
+ return -1;
}
$res = $stm->fetchAll(PDO::FETCH_COLUMN, 0);
return isset($res[0]) ? $res[0] : 0;
diff --git a/app/Models/Share.php b/app/Models/Share.php
index a0bae22b3..8d8aed97b 100644
--- a/app/Models/Share.php
+++ b/app/Models/Share.php
@@ -12,7 +12,7 @@ class FreshRSS_Share {
/**
* Register a new sharing option.
- * @param array{'type':string,'url':string,'transform'?:array<string>|array<string,string>,'field'?:string,'help'?:string,'form'?:'simple'|'advanced',
+ * @param array{'type':string,'url':string,'transform'?:array<callable>|array<string,array<callable>>,'field'?:string,'help'?:string,'form'?:'simple'|'advanced',
* 'method'?:'GET'|'POST','HTMLtag'?:'button','deprecated'?:bool} $share_options is an array defining the share option.
*/
private static function register(array $share_options): void {
@@ -81,7 +81,7 @@ class FreshRSS_Share {
private $name = '';
/** @var string */
private $url_transform = '';
- /** @var array<string>|array<string,array<string>> */
+ /** @var array<callable>|array<string,array<callable>> */
private $transforms = [];
/**
* @phpstan-var 'simple'|'advanced'
@@ -119,7 +119,7 @@ class FreshRSS_Share {
* Create a FreshRSS_Share object.
* @param string $type is a unique string defining the kind of share option.
* @param string $url_transform defines the url format to use in order to share.
- * @param array<string>|array<string,array<string>> $transforms is an array of transformations to apply on link and title.
+ * @param array<callable>|array<string,array<callable>> $transforms is an array of transformations to apply on link and title.
* @param 'simple'|'advanced' $form_type defines which form we have to use to complete. "simple"
* is typically for a centralized service while "advanced" is for
* decentralized ones.
@@ -154,19 +154,29 @@ class FreshRSS_Share {
* in this list: name, url, id, title, link.
*/
public function update(array $options): void {
- $available_options = array(
- 'name' => 'custom_name',
- 'url' => 'base_url',
- 'id' => 'id',
- 'title' => 'title',
- 'link' => 'link',
- 'method' => 'method',
- 'field' => 'field',
- );
-
foreach ($options as $key => $value) {
- if (isset($available_options[$key])) {
- $this->{$available_options[$key]} = $value;
+ switch ($key) {
+ case 'name':
+ $this->custom_name = $value;
+ break;
+ case 'url':
+ $this->base_url = $value;
+ break;
+ case 'id':
+ $this->id = $value;
+ break;
+ case 'title':
+ $this->title = $value;
+ break;
+ case 'link':
+ $this->link = $value;
+ break;
+ case 'method':
+ $this->method = strcasecmp($value, 'POST') === 0 ? 'POST' : 'GET';
+ break;
+ case 'field';
+ $this->field = $value;
+ break;
}
}
}
@@ -300,7 +310,7 @@ class FreshRSS_Share {
/**
* Transform a data with the given functions.
* @param string $data the data to transform.
- * @param array<string> $transform an array containing a list of functions to apply.
+ * @param array<callable> $transform an array containing a list of functions to apply.
* @return string the transformed data.
*/
private static function transform(string $data, array $transform): string {
@@ -309,9 +319,7 @@ class FreshRSS_Share {
}
foreach ($transform as $action) {
- if (is_string($action) && $action != '') {
- $data = call_user_func($action, $data);
- }
+ $data = call_user_func($action, $data);
}
return $data;
@@ -320,13 +328,21 @@ class FreshRSS_Share {
/**
* Get the list of transformations for the given attribute.
* @param string $attr the attribute of which we want the transformations.
- * @return array<string> containing a list of transformations to apply.
+ * @return array<callable> containing a list of transformations to apply.
*/
private function getTransform(string $attr): array {
if (array_key_exists($attr, $this->transforms)) {
- return $this->transforms[$attr];
+ $candidates = is_array($this->transforms[$attr]) ? $this->transforms[$attr] : [];
+ } else {
+ $candidates = $this->transforms;
}
- return $this->transforms;
+ $transforms = [];
+ foreach ($candidates as $transform) {
+ if (is_callable($transform)) {
+ $transforms[] = $transform;
+ }
+ }
+ return $transforms;
}
}
diff --git a/app/Models/View.php b/app/Models/View.php
index cfa06da62..ca237971f 100644
--- a/app/Models/View.php
+++ b/app/Models/View.php
@@ -49,7 +49,7 @@ class FreshRSS_View extends Minz_View {
public $signalError;
// Manage users
- /** @var array{'feed_count':int|false,'article_count':int|false,'database_size':int,'language':string,'mail_login':string,'enabled':bool,'is_admin':bool,'last_user_activity':string,'is_default':bool} */
+ /** @var array{'feed_count':int,'article_count':int,'database_size':int,'language':string,'mail_login':string,'enabled':bool,'is_admin':bool,'last_user_activity':string,'is_default':bool} */
public $details;
/** @var bool */
public $disable_aside;
@@ -57,7 +57,7 @@ class FreshRSS_View extends Minz_View {
public $show_email_field;
/** @var string */
public $username;
- /** @var array<array{'last_user_activity':int,'language':string,'enabled':bool,'is_admin':bool,'enabled':bool,'article_count':int,'database_size':int,'last_user_activity','mail_login':string,'feed_count':int,'is_default':bool}> */
+ /** @var array<array{'language':string,'enabled':bool,'is_admin':bool,'enabled':bool,'article_count':int,'database_size':int,'last_user_activity':string,'mail_login':string,'feed_count':int,'is_default':bool}> */
public $users;
// Updates
diff --git a/app/views/helpers/logs_pagination.phtml b/app/views/helpers/logs_pagination.phtml
index c9f18dc07..349be0760 100755
--- a/app/views/helpers/logs_pagination.phtml
+++ b/app/views/helpers/logs_pagination.phtml
@@ -9,7 +9,7 @@
<nav class="nav-pagination nav-list">
<ul class="pagination">
<?php
- /** @var int $getteur */
+ /** @var string $getteur from Minz_Paginator::render() */
$params[$getteur] = 1;
?>
<li class="item pager-first">
@@ -18,14 +18,12 @@
<?php $params[$getteur] = $this->currentPage - 1; ?>
-
<li class="item pager-previous">
<?php if ($this->currentPage > 1) { ?>
<a href="<?= Minz_Url::display(array('c' => $c, 'a' => $a, 'params' => $params)) ?>">‹ <?= _t('conf.logs.pagination.previous') ?></a>
<?php } ?>
</li>
-
<?php if ($this->currentPage - 2 > 1) { ?>
<li class="item">…</a></li>
<?php } ?>
diff --git a/lib/Minz/Paginator.php b/lib/Minz/Paginator.php
index 77bc3e5e0..a3e2e58f7 100644
--- a/lib/Minz/Paginator.php
+++ b/lib/Minz/Paginator.php
@@ -47,9 +47,9 @@ class Minz_Paginator {
/**
* Permet d'afficher la pagination
* @param string $view nom du fichier de vue situé dans /app/views/helpers/
- * @param int $getteur variable de type $_GET[] permettant de retrouver la page
+ * @param string $getteur variable de type $_GET[] permettant de retrouver la page
*/
- public function render(string $view, int $getteur = 0): void {
+ public function render(string $view, string $getteur = '0'): void {
$view = APP_PATH . '/views/helpers/' . $view;
if (file_exists($view)) {
diff --git a/tests/phpstan-next.txt b/tests/phpstan-next.txt
index e873dd727..694212613 100644
--- a/tests/phpstan-next.txt
+++ b/tests/phpstan-next.txt
@@ -3,10 +3,7 @@
# Can be regenerated with something like:
# find . -type d -name 'vendor' -prune -o -name '*.php' -exec sh -c 'vendor/bin/phpstan analyse --level 7 --memory-limit 512M {} >/dev/null 2>/dev/null || echo {}' \;
-./app/Controllers/userController.php
./app/Models/Feed.php
-./app/Models/Share.php
-./app/views/helpers/logs_pagination.phtml
./lib/Minz/Error.php
./lib/Minz/Mailer.php
./lib/Minz/Migrator.php