From d488c1907a8047d9eeaa802a24f5573feba76991 Mon Sep 17 00:00:00 2001 From: Art4 Date: Tue, 25 Feb 2025 15:24:00 +0000 Subject: [PATCH 01/15] Fix PHPStan error in webdav_storage addon --- webdav_storage/src/WebDavConfig.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webdav_storage/src/WebDavConfig.php b/webdav_storage/src/WebDavConfig.php index 2236e97a..320b06a2 100644 --- a/webdav_storage/src/WebDavConfig.php +++ b/webdav_storage/src/WebDavConfig.php @@ -52,7 +52,7 @@ class WebDavConfig implements ICanConfigureStorage $this->config = $config; $this->client = $client; - $this->authOptions = null; + $this->authOptions = []; if (!empty($this->config->get('webdav', 'username'))) { $this->authOptions = [ From cfe27582eeba1442f8414a4edc731b53057bc092 Mon Sep 17 00:00:00 2001 From: Art4 Date: Wed, 26 Feb 2025 08:47:06 +0000 Subject: [PATCH 02/15] Fix PHPStan error in tumblr addon --- tumblr/tumblr.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tumblr/tumblr.php b/tumblr/tumblr.php index 4415e2de..9e691bf2 100644 --- a/tumblr/tumblr.php +++ b/tumblr/tumblr.php @@ -791,7 +791,7 @@ function tumblr_fetch_dashboard(int $uid, int $last_poll) $dashboard = tumblr_get($uid, 'user/dashboard', $parameters); if ($dashboard->meta->status > 399) { DI::logger()->notice('Error fetching dashboard', ['meta' => $dashboard->meta, 'response' => $dashboard->response, 'errors' => $dashboard->errors]); - return []; + return; } if (empty($dashboard->response->posts)) { From 512ad63dbff6a9c4c85ff414e0768eda09b71b52 Mon Sep 17 00:00:00 2001 From: Art4 Date: Wed, 26 Feb 2025 14:35:00 +0000 Subject: [PATCH 03/15] Fix PHPStan errors in statusnet addon --- statusnet/library/codebirdsn.php | 2 +- statusnet/library/statusnetoauth.php | 16 ++++++------- statusnet/library/twitteroauth.php | 36 ++++++++++++++-------------- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/statusnet/library/codebirdsn.php b/statusnet/library/codebirdsn.php index 9807d97f..bffca163 100644 --- a/statusnet/library/codebirdsn.php +++ b/statusnet/library/codebirdsn.php @@ -976,7 +976,7 @@ class CodebirdSN * @param string $method The method that has been called * @param string $reply The actual reply, JSON-encoded or URL-encoded * - * @return array|object The parsed reply + * @return string|array|object The parsed reply */ protected function _parseApiReply($method, $reply) { diff --git a/statusnet/library/statusnetoauth.php b/statusnet/library/statusnetoauth.php index c32b2b4f..da21be58 100644 --- a/statusnet/library/statusnetoauth.php +++ b/statusnet/library/statusnetoauth.php @@ -12,7 +12,7 @@ require_once __DIR__ . DIRECTORY_SEPARATOR . 'twitteroauth.php'; */ class StatusNetOAuth extends TwitterOAuth { - function get_maxlength() + public function get_maxlength() { $config = $this->get($this->host . 'statusnet/config.json'); if (empty($config)) { @@ -21,27 +21,27 @@ class StatusNetOAuth extends TwitterOAuth return $config->site->textlimit; } - function accessTokenURL() + public function accessTokenURL() { return $this->host . 'oauth/access_token'; } - function authenticateURL() + public function authenticateURL() { return $this->host . 'oauth/authenticate'; } - function authorizeURL() + public function authorizeURL() { return $this->host . 'oauth/authorize'; } - function requestTokenURL() + public function requestTokenURL() { return $this->host . 'oauth/request_token'; } - function __construct($apipath, $consumer_key, $consumer_secret, $oauth_token = NULL, $oauth_token_secret = NULL) + public function __construct($apipath, $consumer_key, $consumer_secret, $oauth_token = NULL, $oauth_token_secret = NULL) { parent::__construct($consumer_key, $consumer_secret, $oauth_token, $oauth_token_secret); $this->host = $apipath; @@ -52,9 +52,9 @@ class StatusNetOAuth extends TwitterOAuth * * Copied here from the TwitterOAuth library and complemented by applying the proxy settings of Friendica * - * @return array|object API results + * @return array|object|mixed API results */ - function http($url, $method, $postfields = NULL) + public function http($url, $method, $postfields = NULL) { $this->http_info = []; $ci = curl_init(); diff --git a/statusnet/library/twitteroauth.php b/statusnet/library/twitteroauth.php index bf413d23..bab66195 100644 --- a/statusnet/library/twitteroauth.php +++ b/statusnet/library/twitteroauth.php @@ -45,11 +45,11 @@ class TwitterOAuth public $http_header; /** * Contains the last HTTP request info - * @var string + * @var array */ public $http_info; - /** @var OAuthToken */ + /** @var OAuthToken|null */ private $token; /** @var OAuthConsumer */ private $consumer; @@ -59,27 +59,27 @@ class TwitterOAuth /** * Set API URLS */ - function accessTokenURL() + public function accessTokenURL() { return 'https://api.twitter.com/oauth/access_token'; } - function authenticateURL() + public function authenticateURL() { return 'https://twitter.com/oauth/authenticate'; } - function authorizeURL() + public function authorizeURL() { return 'https://twitter.com/oauth/authorize'; } - function requestTokenURL() + public function requestTokenURL() { return 'https://api.twitter.com/oauth/request_token'; } - function __construct($consumer_key, $consumer_secret, $oauth_token = null, $oauth_token_secret = null) + public function __construct($consumer_key, $consumer_secret, $oauth_token = null, $oauth_token_secret = null) { $this->sha1_method = new OAuthSignatureMethod_HMAC_SHA1(); $this->consumer = new OAuthConsumer($consumer_key, $consumer_secret); @@ -96,7 +96,7 @@ class TwitterOAuth * @param callable $oauth_callback * @return array */ - function getRequestToken($oauth_callback = null) + public function getRequestToken($oauth_callback = null) { $parameters = []; if (!empty($oauth_callback)) { @@ -114,7 +114,7 @@ class TwitterOAuth * * @return string */ - function getAuthorizeURL($token, $sign_in_with_twitter = TRUE) + public function getAuthorizeURL($token, $sign_in_with_twitter = TRUE) { if (is_array($token)) { $token = $token['oauth_token']; @@ -137,7 +137,7 @@ class TwitterOAuth * "user_id" => "9436992", * "screen_name" => "abraham") */ - function getAccessToken($oauth_verifier = FALSE) + public function getAccessToken($oauth_verifier = FALSE) { $parameters = []; if (!empty($oauth_verifier)) { @@ -162,7 +162,7 @@ class TwitterOAuth * "screen_name" => "abraham", * "x_auth_expires" => "0") */ - function getXAuthToken($username, $password) + public function getXAuthToken($username, $password) { $parameters = []; $parameters['x_auth_username'] = $username; @@ -182,7 +182,7 @@ class TwitterOAuth * @param array $parameters * @return mixed|string */ - function get($url, $parameters = []) + public function get($url, $parameters = []) { $response = $this->oAuthRequest($url, 'GET', $parameters); if ($this->format === 'json' && $this->decode_json) { @@ -199,7 +199,7 @@ class TwitterOAuth * @param array $parameters * @return mixed|string */ - function post($url, $parameters = []) + public function post($url, $parameters = []) { $response = $this->oAuthRequest($url, 'POST', $parameters); if ($this->format === 'json' && $this->decode_json) { @@ -216,7 +216,7 @@ class TwitterOAuth * @param array $parameters * @return mixed|string */ - function delete($url, $parameters = []) + public function delete($url, $parameters = []) { $response = $this->oAuthRequest($url, 'DELETE', $parameters); if ($this->format === 'json' && $this->decode_json) { @@ -234,7 +234,7 @@ class TwitterOAuth * @param array $parameters * @return mixed|string */ - function oAuthRequest($url, $method, $parameters) + public function oAuthRequest($url, $method, $parameters) { if (strrpos($url, 'https://') !== 0 && strrpos($url, 'http://') !== 0) { $url = "{$this->host}{$url}.{$this->format}"; @@ -258,9 +258,9 @@ class TwitterOAuth * @param string $url * @param string $method * @param mixed $postfields - * @return string API results + * @return string|bool|mixed API results */ - function http($url, $method, $postfields = null) + public function http($url, $method, $postfields = null) { $this->http_info = []; $ci = curl_init(); @@ -305,7 +305,7 @@ class TwitterOAuth * @param string $header * @return int */ - function getHeader($ch, $header) + public function getHeader($ch, $header) { $i = strpos($header, ':'); if (!empty($i)) { From bbce8c345f6e25f979f81b4939f0a647ce3245fb Mon Sep 17 00:00:00 2001 From: Art4 Date: Wed, 26 Feb 2025 15:12:25 +0000 Subject: [PATCH 04/15] Fix PHPStan errors in phpnut addon --- pnut/lib/phpnut.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pnut/lib/phpnut.php b/pnut/lib/phpnut.php index ff765243..716945ed 100644 --- a/pnut/lib/phpnut.php +++ b/pnut/lib/phpnut.php @@ -1025,7 +1025,7 @@ class phpnut * see: https://docs.pnut.io/resources/posts/search * @param string $query The search query. Supports * normal search terms. Searches post text. - * @return array An array of associative arrays, each representing one post. + * @return string|array|false An array of associative arrays, each representing one post. * or false on error */ public function searchPosts(array $params=[], string $query='', string $order='default') @@ -1769,7 +1769,7 @@ class phpnut * see: https://docs.pnut.io/resources/messages/search * @param string $query The search query. Supports * normal search terms. Searches common channel raw. - * @return array An array of associative arrays, each representing one channel. + * @return string|array|false An array of associative arrays, each representing one channel. * or false on error */ public function searchMessages(array $params=[], string $query='', string $order='default') From 21a7529a0ef570c68bb15d97adcbc82ba57d0b7b Mon Sep 17 00:00:00 2001 From: Art4 Date: Wed, 26 Feb 2025 15:21:19 +0000 Subject: [PATCH 05/15] fix PHPStan error in phpmailer addon --- phpmailer/phpmailer.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/phpmailer/phpmailer.php b/phpmailer/phpmailer.php index f4bb7753..10287a04 100644 --- a/phpmailer/phpmailer.php +++ b/phpmailer/phpmailer.php @@ -28,10 +28,14 @@ function phpmailer_load_config(ConfigFileManager $loader) } /** - * @param IEmail $email + * @param null|IEmail $email */ -function phpmailer_emailer_send_prepare(IEmail &$email) +function phpmailer_emailer_send_prepare(?IEmail &$email) { + if ($email === null) { + return; + } + // Passing `true` enables exceptions $mailer = new PHPMailer(true); try { From dda6710b1064559621ac3f4f720fe8b7ef6533f9 Mon Sep 17 00:00:00 2001 From: Art4 Date: Thu, 13 Mar 2025 09:36:34 +0000 Subject: [PATCH 06/15] Fix error in notifyall addon --- notifyall/notifyall.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notifyall/notifyall.php b/notifyall/notifyall.php index d37bac56..387fa1ab 100644 --- a/notifyall/notifyall.php +++ b/notifyall/notifyall.php @@ -50,7 +50,7 @@ function notifyall_post() $recipients = DBA::p("SELECT DISTINCT `email` FROM `user`" . DBA::buildCondition($condition), $condition); - if (! $recipients) { + if (! $recipients || !is_iterable($recipients)) { DI::sysmsg()->addNotice(DI::l10n()->t('No recipients found.')); return; } From 417a3a81989fb07ea89209e4a7c4caf47afcd192 Mon Sep 17 00:00:00 2001 From: Art4 Date: Thu, 13 Mar 2025 09:49:18 +0000 Subject: [PATCH 07/15] Fix error in membersince addon --- membersince/membersince.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/membersince/membersince.php b/membersince/membersince.php index 448b8cf2..df6388c6 100644 --- a/membersince/membersince.php +++ b/membersince/membersince.php @@ -17,7 +17,11 @@ function membersince_install() Hook::register('profile_advanced', 'addon/membersince/membersince.php', 'membersince_display'); } -function membersince_display(array &$b) +/** + * @param array|string|null $b + * @return void + */ +function membersince_display(&$b) { $uid = DI::userSession()->getLocalUserId(); @@ -59,7 +63,7 @@ function membersince_display(array &$b) $div->appendChild($entry); $elm->parentNode->insertBefore($div, $elm->nextSibling); - $b = $doc->saveHTML(); + $b = (string) $doc->saveHTML(); } else { // Works in Vier. $b = preg_replace('/<\/dl>/', "\n\n\n
\n
" . DI::l10n()->t('Member since:') . "
\n
" . DateTimeFormat::local($user['register_date']) . "
\n
", $b, 1); From c56ec7c7c4c2545fcb463719d92630ea653bde61 Mon Sep 17 00:00:00 2001 From: Art4 Date: Thu, 13 Mar 2025 10:29:47 +0000 Subject: [PATCH 08/15] Fix error in mailstream addon --- mailstream/mailstream.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mailstream/mailstream.php b/mailstream/mailstream.php index 5228b168..98654831 100644 --- a/mailstream/mailstream.php +++ b/mailstream/mailstream.php @@ -179,7 +179,7 @@ function mailstream_post_hook(array &$item) function mailstream_do_images(array &$item, array &$attachments) { if (!DI::pConfig()->get($item['uid'], 'mailstream', 'attachimg')) { - return; + return $attachments; } $attachments = []; From 2667b4d78ede7dbcc4068acc43ad80209fbb2440 Mon Sep 17 00:00:00 2001 From: Art4 Date: Thu, 13 Mar 2025 11:38:18 +0000 Subject: [PATCH 09/15] Fix error in libravatar addon --- libravatar/Services/Libravatar.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libravatar/Services/Libravatar.php b/libravatar/Services/Libravatar.php index e51ef070..a5bd0793 100644 --- a/libravatar/Services/Libravatar.php +++ b/libravatar/Services/Libravatar.php @@ -361,19 +361,19 @@ class Services_Libravatar protected function domainGet($identifier) { if ($identifier === null) { - return null; + return ''; } // What are we, email or openid? Split ourself up and get the // important bit out. if (filter_var($identifier, FILTER_VALIDATE_EMAIL)) { $email = explode('@', $identifier); - return $email[1]; + return (string) $email[1]; } //OpenID $url = parse_url($identifier); - $domain = $url['host']; + $domain = (string) $url['host']; if (isset($url['port']) && $url['scheme'] === 'http' && $url['port'] != 80 || isset($url['port']) && $url['scheme'] === 'https' From ad316852376f82c6d5998b4f6dc8edbd86495e2a Mon Sep 17 00:00:00 2001 From: Art4 Date: Thu, 13 Mar 2025 11:51:53 +0000 Subject: [PATCH 10/15] Fix error in js_upload addon --- js_upload/js_upload.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js_upload/js_upload.php b/js_upload/js_upload.php index c0a2467d..4bf91de1 100644 --- a/js_upload/js_upload.php +++ b/js_upload/js_upload.php @@ -188,7 +188,7 @@ class js_upload_qqFileUploader private $sizeLimit; /** - * @var js_upload_qqUploadedFileXhr|js_upload_qqUploadedFileForm + * @var js_upload_qqUploadedFileXhr|js_upload_qqUploadedFileForm|false */ private $file; From cdeaa433a133d88569987a9e0c7cd57863198bcd Mon Sep 17 00:00:00 2001 From: Art4 Date: Thu, 13 Mar 2025 11:55:34 +0000 Subject: [PATCH 11/15] Fix error in diaspora addon --- diaspora/Diaspora_Connection.php | 1 - 1 file changed, 1 deletion(-) diff --git a/diaspora/Diaspora_Connection.php b/diaspora/Diaspora_Connection.php index d8390d70..05c21eb0 100644 --- a/diaspora/Diaspora_Connection.php +++ b/diaspora/Diaspora_Connection.php @@ -33,7 +33,6 @@ class Diaspora_Connection { } $this->cookiejar = tempnam(System::getTempPath(), 'cookies'); - return $this; } public function __destruct() { From dd58b000d9728dc16976011c8bd8a044449a573e Mon Sep 17 00:00:00 2001 From: Art4 Date: Thu, 13 Mar 2025 11:57:28 +0000 Subject: [PATCH 12/15] Fix error in bluesky addon --- bluesky/bluesky.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bluesky/bluesky.php b/bluesky/bluesky.php index ba80660c..500f1846 100644 --- a/bluesky/bluesky.php +++ b/bluesky/bluesky.php @@ -961,13 +961,13 @@ function bluesky_complete_post(stdClass $post, int $uid, int $post_reason, int $ if (!empty($existing_uri)) { $comments = Post::countPosts(['thr-parent' => $existing_uri, 'gravity' => Item::GRAVITY_COMMENT]); if (($post->replyCount <= $comments) || !$complete) { - return DI::atpProcessor()->fetchUriId($existing_uri, $uid); + return (int) DI::atpProcessor()->fetchUriId($existing_uri, $uid); } } if ($complete) { $uri = DI::atpProcessor()->fetchMissingPost(DI::atpProcessor()->getUri($post), $uid, $post_reason, $causer, 0, '', true, $protocol); - $uri_id = DI::atpProcessor()->fetchUriId($uri, $uid); + $uri_id = (int) DI::atpProcessor()->fetchUriId($uri, $uid); } else { $uri_id = DI::atpProcessor()->processPost($post, $uid, $post_reason, $causer, 0, $protocol); } From db875bc755449ec71571a35cb62942b282cae0b9 Mon Sep 17 00:00:00 2001 From: Art4 Date: Fri, 14 Mar 2025 07:49:20 +0000 Subject: [PATCH 13/15] Remove type casting to int --- bluesky/bluesky.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bluesky/bluesky.php b/bluesky/bluesky.php index 500f1846..ba80660c 100644 --- a/bluesky/bluesky.php +++ b/bluesky/bluesky.php @@ -961,13 +961,13 @@ function bluesky_complete_post(stdClass $post, int $uid, int $post_reason, int $ if (!empty($existing_uri)) { $comments = Post::countPosts(['thr-parent' => $existing_uri, 'gravity' => Item::GRAVITY_COMMENT]); if (($post->replyCount <= $comments) || !$complete) { - return (int) DI::atpProcessor()->fetchUriId($existing_uri, $uid); + return DI::atpProcessor()->fetchUriId($existing_uri, $uid); } } if ($complete) { $uri = DI::atpProcessor()->fetchMissingPost(DI::atpProcessor()->getUri($post), $uid, $post_reason, $causer, 0, '', true, $protocol); - $uri_id = (int) DI::atpProcessor()->fetchUriId($uri, $uid); + $uri_id = DI::atpProcessor()->fetchUriId($uri, $uid); } else { $uri_id = DI::atpProcessor()->processPost($post, $uid, $post_reason, $causer, 0, $protocol); } From 38a8e9a16950584b14c0c5b4e1945c31cbd2e0df Mon Sep 17 00:00:00 2001 From: Art4 Date: Fri, 14 Mar 2025 08:15:02 +0000 Subject: [PATCH 14/15] remove obvious type cast --- libravatar/Services/Libravatar.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libravatar/Services/Libravatar.php b/libravatar/Services/Libravatar.php index a5bd0793..8b3dd493 100644 --- a/libravatar/Services/Libravatar.php +++ b/libravatar/Services/Libravatar.php @@ -368,12 +368,12 @@ class Services_Libravatar // important bit out. if (filter_var($identifier, FILTER_VALIDATE_EMAIL)) { $email = explode('@', $identifier); - return (string) $email[1]; + return $email[1]; } //OpenID $url = parse_url($identifier); - $domain = (string) $url['host']; + $domain = $url['host']; if (isset($url['port']) && $url['scheme'] === 'http' && $url['port'] != 80 || isset($url['port']) && $url['scheme'] === 'https' From 06b4f164f5bb26162fa948797b4cc79e09e27fe1 Mon Sep 17 00:00:00 2001 From: Art4 Date: Fri, 14 Mar 2025 08:21:08 +0000 Subject: [PATCH 15/15] cast db stmt object to array --- notifyall/notifyall.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/notifyall/notifyall.php b/notifyall/notifyall.php index 387fa1ab..f814c4f5 100644 --- a/notifyall/notifyall.php +++ b/notifyall/notifyall.php @@ -50,14 +50,14 @@ function notifyall_post() $recipients = DBA::p("SELECT DISTINCT `email` FROM `user`" . DBA::buildCondition($condition), $condition); - if (! $recipients || !is_iterable($recipients)) { + if (! $recipients) { DI::sysmsg()->addNotice(DI::l10n()->t('No recipients found.')); return; } $notifyEmail = new NotifyAllEmail(DI::l10n(), DI::config(), DI::baseUrl(), $text); - foreach ($recipients as $recipient) { + foreach (DBA::toArray($recipients) as $recipient) { DI::emailer()->send($notifyEmail->withRecipient($recipient['email'])); }