Merge pull request 'fix-phpstan-error-level-1' (#1579) from MrPetovan/friendica-addons:fix-phpstan-error-level-1 into develop

Reviewed-on: friendica/friendica-addons#1579
This commit is contained in:
Hypolite Petovan 2024-12-12 22:37:42 +01:00
commit 81a84fb895
19 changed files with 62 additions and 45 deletions

View file

@ -683,6 +683,8 @@ function bluesky_create_activity(array $item, stdClass $parent = null)
return; return;
} }
$post = [];
if ($item['verb'] == Activity::LIKE) { if ($item['verb'] == Activity::LIKE) {
$record = [ $record = [
'subject' => $parent, 'subject' => $parent,
@ -1563,7 +1565,7 @@ function bluesky_get_uri_class(string $uri): ?stdClass
} }
$elements = explode(':', $uri); $elements = explode(':', $uri);
if (empty($elements) || ($elements[0] != 'at')) { if ($elements[0] !== 'at') {
$post = Post::selectFirstPost(['extid'], ['uri' => $uri]); $post = Post::selectFirstPost(['extid'], ['uri' => $uri]);
return bluesky_get_uri_class($post['extid'] ?? ''); return bluesky_get_uri_class($post['extid'] ?? '');
} }

View file

@ -181,7 +181,7 @@ function convert_content() {
} }
} }
$o .= '<h3>Unit Conversions</h3>'; $o = '<h3>Unit Conversions</h3>';
if (isset($_POST['from_unit']) && isset($_POST['value'])) { if (isset($_POST['from_unit']) && isset($_POST['value'])) {
$o .= ($conv->getTable(intval($_POST['value']), $_POST['from_unit'], $_POST['to_unit'], 5)) . '</p>'; $o .= ($conv->getTable(intval($_POST['value']), $_POST['from_unit'], $_POST['to_unit'], 5)) . '</p>';

View file

@ -2,12 +2,12 @@
usleep(100000); usleep(100000);
$fileName; $fileName = '';
$fileSize; $fileSize = 0;;
if (isset($_GET['qqfile'])){ if (isset($_GET['qqfile'])){
$fileName = $_GET['qqfile']; $fileName = $_GET['qqfile'];
// xhr request // xhr request
$headers = apache_request_headers(); $headers = apache_request_headers();
$fileSize = (int)$headers['Content-Length']; $fileSize = (int)$headers['Content-Length'];
@ -34,13 +34,13 @@ if ($fileSize > 9 * 1024){
die ('{error: "server-error file size is bigger than 9kB"}'); die ('{error: "server-error file size is bigger than 9kB"}');
} }
if (count($_GET)){ if (count($_GET)){
array_merge($_GET, array('fileName'=>$fileName)); array_merge($_GET, array('fileName'=>$fileName));
$response = array_merge($_GET, array('success'=>true, 'fileName'=>$fileName)); $response = array_merge($_GET, array('success'=>true, 'fileName'=>$fileName));
// to pass data through iframe you will need to encode all html tags // to pass data through iframe you will need to encode all html tags
echo htmlspecialchars(json_encode($response), ENT_NOQUOTES); echo htmlspecialchars(json_encode($response), ENT_NOQUOTES);
} else { } else {
die ('{error: "server-error query params not passed"}'); die ('{error: "server-error query params not passed"}');
} }

View file

@ -2,11 +2,11 @@
sleep(4); sleep(4);
$fileName; $fileName = '';
if (isset($_GET['qqfile'])){ if (isset($_GET['qqfile'])){
$fileName = $_GET['qqfile']; $fileName = $_GET['qqfile'];
// xhr request // xhr request
$headers = apache_request_headers(); $headers = apache_request_headers();
if ((int)$headers['Content-Length'] == 0){ if ((int)$headers['Content-Length'] == 0){
@ -14,7 +14,7 @@ if (isset($_GET['qqfile'])){
} }
} elseif (isset($_FILES['qqfile'])){ } elseif (isset($_FILES['qqfile'])){
$fileName = basename($_FILES['qqfile']['name']); $fileName = basename($_FILES['qqfile']['name']);
// form request // form request
if ($_FILES['qqfile']['size'] == 0){ if ($_FILES['qqfile']['size'] == 0){
die ('{error: "file size is zero"}'); die ('{error: "file size is zero"}');
@ -25,7 +25,7 @@ if (isset($_GET['qqfile'])){
if (count($_GET)){ if (count($_GET)){
$_GET['success'] = true; $_GET['success'] = true;
echo json_encode(array_merge($_GET)); echo json_encode(array_merge($_GET));
} else { } else {
die ('{error: "query params not passed"}'); die ('{error: "query params not passed"}');
} }

View file

@ -2,11 +2,11 @@
usleep(300); usleep(300);
$fileName; $fileName = '';
if (isset($_GET['qqfile'])){ if (isset($_GET['qqfile'])){
$fileName = $_GET['qqfile']; $fileName = $_GET['qqfile'];
// xhr request // xhr request
$headers = apache_request_headers(); $headers = apache_request_headers();
if ((int)$headers['Content-Length'] == 0){ if ((int)$headers['Content-Length'] == 0){
@ -14,7 +14,7 @@ if (isset($_GET['qqfile'])){
} }
} elseif (isset($_FILES['qqfile'])){ } elseif (isset($_FILES['qqfile'])){
$fileName = basename($_FILES['qqfile']['name']); $fileName = basename($_FILES['qqfile']['name']);
// form request // form request
if ($_FILES['qqfile']['size'] == 0){ if ($_FILES['qqfile']['size'] == 0){
die ('{error: "file size is zero"}'); die ('{error: "file size is zero"}');
@ -25,7 +25,7 @@ if (isset($_GET['qqfile'])){
if (count($_GET)){ if (count($_GET)){
//return query params //return query params
echo json_encode(array_merge($_GET, array('fileName'=>$fileName))); echo json_encode(array_merge($_GET, array('fileName'=>$fileName)));
} else { } else {
die ('{error: "query params not passed"}'); die ('{error: "query params not passed"}');
} }

View file

@ -6,7 +6,6 @@
* Author: Ryan <https://verya.pe/profile/ryan> * Author: Ryan <https://verya.pe/profile/ryan>
*/ */
use Friendica\App;
use Friendica\Core\Hook; use Friendica\Core\Hook;
use Friendica\Core\Logger; use Friendica\Core\Logger;
use Friendica\Core\Renderer; use Friendica\Core\Renderer;
@ -92,7 +91,7 @@ function keycloakpassword_authenticate(array &$b)
$client_id, $client_id,
$secret, $secret,
$endpoint . '/logout', $endpoint . '/logout',
[ 'refresh_token' => res['refresh_token'] ] [ 'refresh_token' => $res['refresh_token'] ]
); );
} }
} }

View file

@ -7,7 +7,6 @@
* License: MIT * License: MIT
*/ */
use Friendica\App;
use Friendica\Content\Text\BBCode; use Friendica\Content\Text\BBCode;
use Friendica\Core\Hook; use Friendica\Core\Hook;
use Friendica\Core\Renderer; use Friendica\Core\Renderer;
@ -148,6 +147,8 @@ function langfilter_prepare_body_content_filter(&$hook_data)
$iso639 = new Matriphe\ISO639\ISO639; $iso639 = new Matriphe\ISO639\ISO639;
$confidence = null;
// Extract the language of the post // Extract the language of the post
if (!empty($hook_data['item']['language'])) { if (!empty($hook_data['item']['language'])) {
$languages = json_decode($hook_data['item']['language'], true); $languages = json_decode($hook_data['item']['language'], true);

View file

@ -6,7 +6,6 @@
* Author: Michael Vogel <https://pirati.ca/profile/heluecht> * Author: Michael Vogel <https://pirati.ca/profile/heluecht>
*/ */
use Friendica\App;
use Friendica\Core\Hook; use Friendica\Core\Hook;
use Friendica\Core\Logger; use Friendica\Core\Logger;
use Friendica\DI; use Friendica\DI;
@ -149,7 +148,7 @@ function leistungsschutzrecht_is_member_site(string $url): bool
$cleanedurlpart = explode('%', $urldata['host']); $cleanedurlpart = explode('%', $urldata['host']);
$hostname = explode('.', $cleanedurlpart[0]); $hostname = explode('.', $cleanedurlpart[0]);
if (empty($hostname)) { if ($hostname === false || $hostname === '') {
return false; return false;
} }

View file

@ -401,9 +401,8 @@ class Services_Libravatar
*/ */
protected function srvGet($domain, $https = false) protected function srvGet($domain, $https = false)
{ {
// Are we going secure? Set up a fallback too. // Are we going secure? Set up a fallback too.
if (isset($https) && $https === true) { if ($https === true) {
$subdomain = '_avatars-sec._tcp.'; $subdomain = '_avatars-sec._tcp.';
$fallback = 'seccdn.'; $fallback = 'seccdn.';
} else { } else {
@ -426,6 +425,7 @@ class Services_Libravatar
$top = $srv[0]; $top = $srv[0];
$sum = 0; $sum = 0;
$pri = [];
// Try to adhere to RFC2782's weighting algorithm, page 3 // Try to adhere to RFC2782's weighting algorithm, page 3
// "arrange all SRV RRs (that have not been ordered yet) in any order, // "arrange all SRV RRs (that have not been ordered yet) in any order,

View file

@ -8,7 +8,6 @@
* Author: Cat Gray <https://free-haven.org/profile/catness> * Author: Cat Gray <https://free-haven.org/profile/catness>
*/ */
use Friendica\App;
use Friendica\Content\Text\BBCode; use Friendica\Content\Text\BBCode;
use Friendica\Core\Hook; use Friendica\Core\Hook;
use Friendica\Core\Logger; use Friendica\Core\Logger;
@ -203,10 +202,12 @@ EOT;
Logger::debug('ljpost: data: ' . $xml); Logger::debug('ljpost: data: ' . $xml);
$x = '';
if ($lj_blog !== 'test') { if ($lj_blog !== 'test') {
$x = DI::httpClient()->post($lj_blog, $xml, ['Content-Type' => 'text/xml'])->getBodyString(); $x = DI::httpClient()->post($lj_blog, $xml, ['Content-Type' => 'text/xml'])->getBodyString();
} }
Logger::info('posted to livejournal: ' . ($x) ? $x : ''); Logger::info('posted to livejournal: ' . $x);
} }
} }

View file

@ -3287,7 +3287,7 @@ class PHPMailer
$result = 'localhost.localdomain'; $result = 'localhost.localdomain';
if (!empty($this->Hostname)) { if (!empty($this->Hostname)) {
$result = $this->Hostname; $result = $this->Hostname;
} elseif (isset($_SERVER) and array_key_exists('SERVER_NAME', $_SERVER) and !empty($_SERVER['SERVER_NAME'])) { } elseif (!empty($_SERVER['SERVER_NAME'])) {
$result = $_SERVER['SERVER_NAME']; $result = $_SERVER['SERVER_NAME'];
} elseif (function_exists('gethostname') && gethostname() !== false) { } elseif (function_exists('gethostname') && gethostname() !== false) {
$result = gethostname(); $result = gethostname();

View file

@ -8,7 +8,6 @@
* *
*/ */
use Friendica\App;
use Friendica\Core\Hook; use Friendica\Core\Hook;
use Friendica\Core\Renderer; use Friendica\Core\Renderer;
use Friendica\DI; use Friendica\DI;
@ -119,7 +118,9 @@ function nsfw_prepare_body_content_filter(&$hook_data)
$word_list = ['nsfw']; $word_list = ['nsfw'];
} }
$found = false; $found = false;
$tag_search = false;
if (count($word_list)) { if (count($word_list)) {
$body = $hook_data['item']['title'] . "\n" . nsfw_extract_photos($hook_data['item']['body']); $body = $hook_data['item']['title'] . "\n" . nsfw_extract_photos($hook_data['item']['body']);
@ -129,7 +130,6 @@ function nsfw_prepare_body_content_filter(&$hook_data)
continue; continue;
} }
$tag_search = false;
switch ($word[0]) { switch ($word[0]) {
case '/'; // Regular expression case '/'; // Regular expression
$found = @preg_match($word, $body); $found = @preg_match($word, $body);

View file

@ -1339,6 +1339,8 @@ class phpnut
*/ */
protected function updateUserImage(string $image, string $which='avatar') protected function updateUserImage(string $image, string $which='avatar')
{ {
$mimeType = '';
$test = @getimagesize($image); $test = @getimagesize($image);
if ($test && array_key_exists('mime', $test)) { if ($test && array_key_exists('mime', $test)) {
$mimeType = $test['mime']; $mimeType = $test['mime'];

View file

@ -6,7 +6,6 @@
* Author: Michael Vogel <http://pirati.ca/profile/heluecht> * Author: Michael Vogel <http://pirati.ca/profile/heluecht>
*/ */
use Friendica\App;
use Friendica\Content\Text\BBCode; use Friendica\Content\Text\BBCode;
use Friendica\Content\Text\HTML; use Friendica\Content\Text\HTML;
use Friendica\Core\Addon; use Friendica\Core\Addon;
@ -582,6 +581,8 @@ function pumpio_action(int $uid, string $uri, string $action, string $content =
$uri = $orig_post['uri']; $uri = $orig_post['uri'];
} }
$objectType = '';
if (($orig_post['object-type'] != '') && (strstr($orig_post['object-type'], ActivityNamespace::ACTIVITY_SCHEMA))) { if (($orig_post['object-type'] != '') && (strstr($orig_post['object-type'], ActivityNamespace::ACTIVITY_SCHEMA))) {
$objectType = str_replace(ActivityNamespace::ACTIVITY_SCHEMA, '', $orig_post['object-type']); $objectType = str_replace(ActivityNamespace::ACTIVITY_SCHEMA, '', $orig_post['object-type']);
} elseif (strstr($uri, '/api/comment/')) { } elseif (strstr($uri, '/api/comment/')) {
@ -827,6 +828,7 @@ function pumpio_dounlike(int $uid, array $self, $post, string $own_id)
} }
$contactid = 0; $contactid = 0;
$contact = [];
if (Strings::compareLink($post->actor->url, $own_id)) { if (Strings::compareLink($post->actor->url, $own_id)) {
$contactid = $self['id']; $contactid = $self['id'];
@ -1430,6 +1432,8 @@ function pumpio_fetchallcomments($uid, $id)
Logger::notice('pumpio_fetchallcomments: fetching comment for user ' . $uid . ', URL ' . $url); Logger::notice('pumpio_fetchallcomments: fetching comment for user ' . $uid . ', URL ' . $url);
$item = new \stdClass();
if (pumpio_reachable($url)) { if (pumpio_reachable($url)) {
$success = $client->CallAPI($url, 'GET', [], ['FailOnAccessError' => true], $item); $success = $client->CallAPI($url, 'GET', [], ['FailOnAccessError' => true], $item);
} else { } else {

View file

@ -26,6 +26,7 @@ class RatioedPanel extends Active
$action = $this->parameters['action'] ?? ''; $action = $this->parameters['action'] ?? '';
$uid = $this->parameters['uid'] ?? 0; $uid = $this->parameters['uid'] ?? 0;
$user = [];
if ($uid) { if ($uid) {
$user = User::getById($uid, ['username', 'blocked']); $user = User::getById($uid, ['username', 'blocked']);

View file

@ -31,11 +31,10 @@ use Friendica\Core\System;
/** /**
* Define constants * Define constants
*/ */
$constants = explode(' ', 'OBJECT ARRAY JSON'); defined('CODEBIRD_RETURNFORMAT_ARRAY') or define('CODEBIRD_RETURNFORMAT_ARRAY', 0);
foreach ($constants as $i => $id) { defined('CODEBIRD_RETURNFORMAT_JSON') or define('CODEBIRD_RETURNFORMAT_JSON', 1);
$id = 'CODEBIRD_RETURNFORMAT_' . $id; defined('CODEBIRD_RETURNFORMAT_OBJECT') or define('CODEBIRD_RETURNFORMAT_OBJECT', 2);
defined($id) or define($id, $i);
}
$constants = array( $constants = array(
'CURLE_SSL_CERTPROBLEM' => 58, 'CURLE_SSL_CERTPROBLEM' => 58,
'CURLE_SSL_CACERT' => 60, 'CURLE_SSL_CACERT' => 60,
@ -788,6 +787,8 @@ class CodebirdSN
$possible_files = explode(' ', $possible_files[$method]); $possible_files = explode(' ', $possible_files[$method]);
$data = '';
$multipart_border = '--------------------' . $this->_nonce(); $multipart_border = '--------------------' . $this->_nonce();
$multipart_request = ''; $multipart_request = '';
foreach ($params as $key => $value) { foreach ($params as $key => $value) {
@ -917,7 +918,7 @@ class CodebirdSN
$authorization = 'Authorization: Bearer ' . self::$_oauth_bearer_token; $authorization = 'Authorization: Bearer ' . self::$_oauth_bearer_token;
} }
$request_headers = array(); $request_headers = array();
if (isset($authorization)) { if ($authorization !== '') {
$request_headers[] = $authorization; $request_headers[] = $authorization;
$request_headers[] = 'Expect:'; $request_headers[] = 'Expect:';
} }

View file

@ -366,6 +366,8 @@ function statusnet_post_hook(array &$b)
$otoken = DI::pConfig()->get($b['uid'], 'statusnet', 'oauthtoken'); $otoken = DI::pConfig()->get($b['uid'], 'statusnet', 'oauthtoken');
$osecret = DI::pConfig()->get($b['uid'], 'statusnet', 'oauthsecret'); $osecret = DI::pConfig()->get($b['uid'], 'statusnet', 'oauthsecret');
$iscomment = null;
if ($ckey && $csecret && $otoken && $osecret) { if ($ckey && $csecret && $otoken && $osecret) {
$dent = new StatusNetOAuth($api, $ckey, $csecret, $otoken, $osecret); $dent = new StatusNetOAuth($api, $ckey, $csecret, $otoken, $osecret);
$max_char = $dent->get_maxlength(); // max. length for a dent $max_char = $dent->get_maxlength(); // max. length for a dent

View file

@ -7,7 +7,6 @@
* Status: unsupported * Status: unsupported
*/ */
use Friendica\App;
use Friendica\Core\Hook; use Friendica\Core\Hook;
use Friendica\DI; use Friendica\DI;
@ -30,7 +29,12 @@ function tictac_module() {}
function tictac_content() { function tictac_content() {
$o = ''; $o = '';
$dimen = 3;
$handicap = 0;
$mefirst = 0;
$yours = '';
$mine = '';
if($_POST['move']) { if($_POST['move']) {
$handicap = DI::args()->get(1); $handicap = DI::args()->get(1);
@ -45,9 +49,6 @@ function tictac_content() {
$handicap = DI::args()->get(1); $handicap = DI::args()->get(1);
$dimen = 3; $dimen = 3;
} }
else {
$dimen = 3;
}
$o .= '<h3>' . DI::l10n()->t('3D Tic-Tac-Toe') . '</h3><br />'; $o .= '<h3>' . DI::l10n()->t('3D Tic-Tac-Toe') . '</h3><br />';
@ -163,7 +164,7 @@ class tictac {
]; ];
function __construct($dimen, $handicap, $mefirst, $yours, $mine) { function __construct($dimen, $handicap, $mefirst, $yours, $mine) {
$this->dimen = 3; $this->dimen = $dimen;
$this->handicap = $handicap ? 1 : 0; $this->handicap = $handicap ? 1 : 0;
$this->mefirst = $mefirst ? 1 : 0; $this->mefirst = $mefirst ? 1 : 0;
$this->yours = str_replace('XXX','',$yours); $this->yours = str_replace('XXX','',$yours);
@ -228,6 +229,8 @@ class tictac {
} }
function parse_moves($player) { function parse_moves($player) {
$str = '';
if($player == 'me') if($player == 'me')
$str = $this->mine; $str = $this->mine;
if($player == 'you') if($player == 'you')

View file

@ -259,9 +259,11 @@ EOT;
Logger::debug('wppost: data: ' . $xml); Logger::debug('wppost: data: ' . $xml);
$x = '';
if ($wp_blog !== 'test') { if ($wp_blog !== 'test') {
$x = DI::httpClient()->post($wp_blog, $xml)->getBodyString(); $x = DI::httpClient()->post($wp_blog, $xml)->getBodyString();
} }
Logger::info('posted to wordpress: ' . (($x) ? $x : '')); Logger::info('posted to wordpress: ' . $x);
} }
} }