Merge pull request 'PHPStan level 3' (#1603) from Art4/friendica-addons:phpstan-level-3 into develop

Reviewed-on: https://git.friendi.ca/friendica/friendica-addons/pulls/1603
pull/1607/head
Philipp Holzer 2025-04-27 02:17:41 +02:00
commit 95a9f7038a
13 changed files with 47 additions and 40 deletions

View File

@ -33,7 +33,6 @@ class Diaspora_Connection {
} }
$this->cookiejar = tempnam(System::getTempPath(), 'cookies'); $this->cookiejar = tempnam(System::getTempPath(), 'cookies');
return $this;
} }
public function __destruct() { public function __destruct() {

View File

@ -188,7 +188,7 @@ class js_upload_qqFileUploader
private $sizeLimit; private $sizeLimit;
/** /**
* @var js_upload_qqUploadedFileXhr|js_upload_qqUploadedFileForm * @var js_upload_qqUploadedFileXhr|js_upload_qqUploadedFileForm|false
*/ */
private $file; private $file;

View File

@ -361,7 +361,7 @@ class Services_Libravatar
protected function domainGet($identifier) protected function domainGet($identifier)
{ {
if ($identifier === null) { if ($identifier === null) {
return null; return '';
} }
// What are we, email or openid? Split ourself up and get the // What are we, email or openid? Split ourself up and get the

View File

@ -179,7 +179,7 @@ function mailstream_post_hook(array &$item)
function mailstream_do_images(array &$item, array &$attachments) function mailstream_do_images(array &$item, array &$attachments)
{ {
if (!DI::pConfig()->get($item['uid'], 'mailstream', 'attachimg')) { if (!DI::pConfig()->get($item['uid'], 'mailstream', 'attachimg')) {
return; return $attachments;
} }
$attachments = []; $attachments = [];

View File

@ -17,7 +17,11 @@ function membersince_install()
Hook::register('profile_advanced', 'addon/membersince/membersince.php', 'membersince_display'); 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(); $uid = DI::userSession()->getLocalUserId();
@ -59,7 +63,7 @@ function membersince_display(array &$b)
$div->appendChild($entry); $div->appendChild($entry);
$elm->parentNode->insertBefore($div, $elm->nextSibling); $elm->parentNode->insertBefore($div, $elm->nextSibling);
$b = $doc->saveHTML(); $b = (string) $doc->saveHTML();
} else { } else {
// Works in Vier. // Works in Vier.
$b = preg_replace('/<\/dl>/', "</dl>\n\n\n<dl id=\"aprofile-membersince\" class=\"aprofile\">\n<dt>" . DI::l10n()->t('Member since:') . "</dt>\n<dd>" . DateTimeFormat::local($user['register_date']) . "</dd>\n</dl>", $b, 1); $b = preg_replace('/<\/dl>/', "</dl>\n\n\n<dl id=\"aprofile-membersince\" class=\"aprofile\">\n<dt>" . DI::l10n()->t('Member since:') . "</dt>\n<dd>" . DateTimeFormat::local($user['register_date']) . "</dd>\n</dl>", $b, 1);

View File

@ -57,7 +57,7 @@ function notifyall_post()
$notifyEmail = new NotifyAllEmail(DI::l10n(), DI::config(), DI::baseUrl(), $text); $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'])); DI::emailer()->send($notifyEmail->withRecipient($recipient['email']));
} }

View File

@ -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 // Passing `true` enables exceptions
$mailer = new PHPMailer(true); $mailer = new PHPMailer(true);
try { try {

View File

@ -1025,7 +1025,7 @@ class phpnut
* see: https://docs.pnut.io/resources/posts/search * see: https://docs.pnut.io/resources/posts/search
* @param string $query The search query. Supports * @param string $query The search query. Supports
* normal search terms. Searches post text. * 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 * or false on error
*/ */
public function searchPosts(array $params=[], string $query='', string $order='default') public function searchPosts(array $params=[], string $query='', string $order='default')
@ -1769,7 +1769,7 @@ class phpnut
* see: https://docs.pnut.io/resources/messages/search * see: https://docs.pnut.io/resources/messages/search
* @param string $query The search query. Supports * @param string $query The search query. Supports
* normal search terms. Searches common channel raw. * 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 * or false on error
*/ */
public function searchMessages(array $params=[], string $query='', string $order='default') public function searchMessages(array $params=[], string $query='', string $order='default')

View File

@ -976,7 +976,7 @@ class CodebirdSN
* @param string $method The method that has been called * @param string $method The method that has been called
* @param string $reply The actual reply, JSON-encoded or URL-encoded * @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) protected function _parseApiReply($method, $reply)
{ {

View File

@ -12,7 +12,7 @@ require_once __DIR__ . DIRECTORY_SEPARATOR . 'twitteroauth.php';
*/ */
class StatusNetOAuth extends TwitterOAuth class StatusNetOAuth extends TwitterOAuth
{ {
function get_maxlength() public function get_maxlength()
{ {
$config = $this->get($this->host . 'statusnet/config.json'); $config = $this->get($this->host . 'statusnet/config.json');
if (empty($config)) { if (empty($config)) {
@ -21,27 +21,27 @@ class StatusNetOAuth extends TwitterOAuth
return $config->site->textlimit; return $config->site->textlimit;
} }
function accessTokenURL() public function accessTokenURL()
{ {
return $this->host . 'oauth/access_token'; return $this->host . 'oauth/access_token';
} }
function authenticateURL() public function authenticateURL()
{ {
return $this->host . 'oauth/authenticate'; return $this->host . 'oauth/authenticate';
} }
function authorizeURL() public function authorizeURL()
{ {
return $this->host . 'oauth/authorize'; return $this->host . 'oauth/authorize';
} }
function requestTokenURL() public function requestTokenURL()
{ {
return $this->host . 'oauth/request_token'; 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); parent::__construct($consumer_key, $consumer_secret, $oauth_token, $oauth_token_secret);
$this->host = $apipath; $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 * 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 = []; $this->http_info = [];
$ci = curl_init(); $ci = curl_init();

View File

@ -45,11 +45,11 @@ class TwitterOAuth
public $http_header; public $http_header;
/** /**
* Contains the last HTTP request info * Contains the last HTTP request info
* @var string * @var array
*/ */
public $http_info; public $http_info;
/** @var OAuthToken */ /** @var OAuthToken|null */
private $token; private $token;
/** @var OAuthConsumer */ /** @var OAuthConsumer */
private $consumer; private $consumer;
@ -59,27 +59,27 @@ class TwitterOAuth
/** /**
* Set API URLS * Set API URLS
*/ */
function accessTokenURL() public function accessTokenURL()
{ {
return 'https://api.twitter.com/oauth/access_token'; return 'https://api.twitter.com/oauth/access_token';
} }
function authenticateURL() public function authenticateURL()
{ {
return 'https://twitter.com/oauth/authenticate'; return 'https://twitter.com/oauth/authenticate';
} }
function authorizeURL() public function authorizeURL()
{ {
return 'https://twitter.com/oauth/authorize'; return 'https://twitter.com/oauth/authorize';
} }
function requestTokenURL() public function requestTokenURL()
{ {
return 'https://api.twitter.com/oauth/request_token'; 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->sha1_method = new OAuthSignatureMethod_HMAC_SHA1();
$this->consumer = new OAuthConsumer($consumer_key, $consumer_secret); $this->consumer = new OAuthConsumer($consumer_key, $consumer_secret);
@ -96,7 +96,7 @@ class TwitterOAuth
* @param callable $oauth_callback * @param callable $oauth_callback
* @return array * @return array
*/ */
function getRequestToken($oauth_callback = null) public function getRequestToken($oauth_callback = null)
{ {
$parameters = []; $parameters = [];
if (!empty($oauth_callback)) { if (!empty($oauth_callback)) {
@ -114,7 +114,7 @@ class TwitterOAuth
* *
* @return string * @return string
*/ */
function getAuthorizeURL($token, $sign_in_with_twitter = TRUE) public function getAuthorizeURL($token, $sign_in_with_twitter = TRUE)
{ {
if (is_array($token)) { if (is_array($token)) {
$token = $token['oauth_token']; $token = $token['oauth_token'];
@ -137,7 +137,7 @@ class TwitterOAuth
* "user_id" => "9436992", * "user_id" => "9436992",
* "screen_name" => "abraham") * "screen_name" => "abraham")
*/ */
function getAccessToken($oauth_verifier = FALSE) public function getAccessToken($oauth_verifier = FALSE)
{ {
$parameters = []; $parameters = [];
if (!empty($oauth_verifier)) { if (!empty($oauth_verifier)) {
@ -162,7 +162,7 @@ class TwitterOAuth
* "screen_name" => "abraham", * "screen_name" => "abraham",
* "x_auth_expires" => "0") * "x_auth_expires" => "0")
*/ */
function getXAuthToken($username, $password) public function getXAuthToken($username, $password)
{ {
$parameters = []; $parameters = [];
$parameters['x_auth_username'] = $username; $parameters['x_auth_username'] = $username;
@ -182,7 +182,7 @@ class TwitterOAuth
* @param array $parameters * @param array $parameters
* @return mixed|string * @return mixed|string
*/ */
function get($url, $parameters = []) public function get($url, $parameters = [])
{ {
$response = $this->oAuthRequest($url, 'GET', $parameters); $response = $this->oAuthRequest($url, 'GET', $parameters);
if ($this->format === 'json' && $this->decode_json) { if ($this->format === 'json' && $this->decode_json) {
@ -199,7 +199,7 @@ class TwitterOAuth
* @param array $parameters * @param array $parameters
* @return mixed|string * @return mixed|string
*/ */
function post($url, $parameters = []) public function post($url, $parameters = [])
{ {
$response = $this->oAuthRequest($url, 'POST', $parameters); $response = $this->oAuthRequest($url, 'POST', $parameters);
if ($this->format === 'json' && $this->decode_json) { if ($this->format === 'json' && $this->decode_json) {
@ -216,7 +216,7 @@ class TwitterOAuth
* @param array $parameters * @param array $parameters
* @return mixed|string * @return mixed|string
*/ */
function delete($url, $parameters = []) public function delete($url, $parameters = [])
{ {
$response = $this->oAuthRequest($url, 'DELETE', $parameters); $response = $this->oAuthRequest($url, 'DELETE', $parameters);
if ($this->format === 'json' && $this->decode_json) { if ($this->format === 'json' && $this->decode_json) {
@ -234,7 +234,7 @@ class TwitterOAuth
* @param array $parameters * @param array $parameters
* @return mixed|string * @return mixed|string
*/ */
function oAuthRequest($url, $method, $parameters) public function oAuthRequest($url, $method, $parameters)
{ {
if (strrpos($url, 'https://') !== 0 && strrpos($url, 'http://') !== 0) { if (strrpos($url, 'https://') !== 0 && strrpos($url, 'http://') !== 0) {
$url = "{$this->host}{$url}.{$this->format}"; $url = "{$this->host}{$url}.{$this->format}";
@ -258,9 +258,9 @@ class TwitterOAuth
* @param string $url * @param string $url
* @param string $method * @param string $method
* @param mixed $postfields * @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 = []; $this->http_info = [];
$ci = curl_init(); $ci = curl_init();
@ -305,7 +305,7 @@ class TwitterOAuth
* @param string $header * @param string $header
* @return int * @return int
*/ */
function getHeader($ch, $header) public function getHeader($ch, $header)
{ {
$i = strpos($header, ':'); $i = strpos($header, ':');
if (!empty($i)) { if (!empty($i)) {

View File

@ -791,7 +791,7 @@ function tumblr_fetch_dashboard(int $uid, int $last_poll)
$dashboard = tumblr_get($uid, 'user/dashboard', $parameters); $dashboard = tumblr_get($uid, 'user/dashboard', $parameters);
if ($dashboard->meta->status > 399) { if ($dashboard->meta->status > 399) {
DI::logger()->notice('Error fetching dashboard', ['meta' => $dashboard->meta, 'response' => $dashboard->response, 'errors' => $dashboard->errors]); DI::logger()->notice('Error fetching dashboard', ['meta' => $dashboard->meta, 'response' => $dashboard->response, 'errors' => $dashboard->errors]);
return []; return;
} }
if (empty($dashboard->response->posts)) { if (empty($dashboard->response->posts)) {

View File

@ -52,7 +52,7 @@ class WebDavConfig implements ICanConfigureStorage
$this->config = $config; $this->config = $config;
$this->client = $client; $this->client = $client;
$this->authOptions = null; $this->authOptions = [];
if (!empty($this->config->get('webdav', 'username'))) { if (!empty($this->config->get('webdav', 'username'))) {
$this->authOptions = [ $this->authOptions = [