aboutsummaryrefslogtreecommitdiff
path: root/app/Models
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 /app/Models
parent68766a98574d98be358199924222f26d8ac36561 (diff)
PHPStan Level 7 for Share userController logs_pagination (#5393)
Diffstat (limited to 'app/Models')
-rw-r--r--app/Models/FeedDAO.php7
-rw-r--r--app/Models/Share.php60
-rw-r--r--app/Models/View.php4
3 files changed, 42 insertions, 29 deletions
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