Fix 7 PHPStan errors

This commit is contained in:
Art4 2025-03-05 14:27:34 +00:00
parent 0b162b4429
commit 4ebabd5997
6 changed files with 20 additions and 12 deletions

View file

@ -172,7 +172,7 @@ class Hook
* the provided data. * the provided data.
* *
* @param string $name of the hook to call * @param string $name of the hook to call
* @param string|array &$data to transmit to the callback handler * @param string|array|null $data to transmit to the callback handler
* @return void * @return void
* @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/ */

View file

@ -41,7 +41,6 @@ class Photo extends BaseFactory
* @param int $scale * @param int $scale
* @param int $uid * @param int $uid
* @param string $type * @param string $type
* @return Array
*/ */
public function createFromId(string $photo_id, int $scale = null, int $uid, string $type = 'json', bool $with_posts = true): array public function createFromId(string $photo_id, int $scale = null, int $uid, string $type = 'json', bool $with_posts = true): array
{ {
@ -66,7 +65,7 @@ class Photo extends BaseFactory
$data['id'] = $data['resource-id']; $data['id'] = $data['resource-id'];
if (is_int($scale)) { if (is_int($scale)) {
$data['data'] = base64_encode(ModelPhoto::getImageDataForPhoto($data)); $data['data'] = base64_encode(ModelPhoto::getImageDataForPhoto($data) ?? '');
} }
if ($type == 'xml') { if ($type == 'xml') {

View file

@ -672,7 +672,7 @@ class Item
/** /**
* Inserts item record * Inserts item record
* *
* @param array $item Item array to be inserted * @param array<string,mixed> $item Item array to be inserted
* @param int $notify Notification (type?) * @param int $notify Notification (type?)
* @param bool $post_local (???) * @param bool $post_local (???)
* @return int Zero means error, otherwise primary key (id) is being returned * @return int Zero means error, otherwise primary key (id) is being returned
@ -695,6 +695,7 @@ class Item
// If it is a posting where users should get notifications, then define it as wall posting // If it is a posting where users should get notifications, then define it as wall posting
if ($notify) { if ($notify) {
/** @var array<string,mixed> */
$item = $itemHelper->prepareOriginPost($item); $item = $itemHelper->prepareOriginPost($item);
if (is_int($notify) && in_array($notify, Worker::PRIORITIES)) { if (is_int($notify) && in_array($notify, Worker::PRIORITIES)) {
@ -708,6 +709,7 @@ class Item
$item['network'] = trim(($item['network'] ?? '') ?: Protocol::PHANTOM); $item['network'] = trim(($item['network'] ?? '') ?: Protocol::PHANTOM);
} }
/** @var array<string,mixed> */
$item = $itemHelper->prepareItemData($item, (bool) $notify); $item = $itemHelper->prepareItemData($item, (bool) $notify);
// Store conversation data // Store conversation data
@ -749,6 +751,7 @@ class Item
} }
} }
/** @var array<string,mixed> */
$item = $itemHelper->validateItemData($item); $item = $itemHelper->validateItemData($item);
// Ensure that there is an avatar cache // Ensure that there is an avatar cache
@ -846,6 +849,7 @@ class Item
$dummy_session = false; $dummy_session = false;
} }
/** @var array<string,mixed> */
$item = $eventDispatcher->dispatch( $item = $eventDispatcher->dispatch(
new ArrayFilterEvent(ArrayFilterEvent::POST_LOCAL, $item) new ArrayFilterEvent(ArrayFilterEvent::POST_LOCAL, $item)
)->getArray(); )->getArray();
@ -3061,7 +3065,14 @@ class Item
{ {
$appHelper = DI::appHelper(); $appHelper = DI::appHelper();
$uid = DI::userSession()->getLocalUserId(); $uid = DI::userSession()->getLocalUserId();
Hook::callAll('prepare_body_init', $item);
$item_copy = $item;
Hook::callAll('prepare_body_init', $item_copy);
if (is_array($item_copy)) {
$item = $item_copy;
}
// In order to provide theme developers more possibilities, event items // In order to provide theme developers more possibilities, event items
// are treated differently. // are treated differently.

View file

@ -21,7 +21,7 @@ class ParsedLogIterator implements \Iterator
/** @var ReversedFileReader */ /** @var ReversedFileReader */
private $reader; private $reader;
/** @var ParsedLogLine current iterator value*/ /** @var ParsedLogLine|null current iterator value*/
private $value = null; private $value = null;
/** @var int max number of lines to read */ /** @var int max number of lines to read */

View file

@ -244,7 +244,7 @@ class Photo
* *
* @param array $photo Photo data. Needs at least 'id', 'type', 'backend-class', 'backend-ref' * @param array $photo Photo data. Needs at least 'id', 'type', 'backend-class', 'backend-ref'
* *
* @return \Friendica\Object\Image|null Image object or null on error * @return string|null Image data as string or null on error
*/ */
public static function getImageDataForPhoto(array $photo) public static function getImageDataForPhoto(array $photo)
{ {
@ -254,7 +254,7 @@ class Photo
try { try {
$backendClass = DI::storageManager()->getByName($photo['backend-class'] ?? ''); $backendClass = DI::storageManager()->getByName($photo['backend-class'] ?? '');
/// @todo refactoring this returning, because the storage returns a "string" which is casted in different ways - a check "instanceof Image" will fail!
return $backendClass->get($photo['backend-ref'] ?? ''); return $backendClass->get($photo['backend-ref'] ?? '');
} catch (InvalidClassStorageException $storageException) { } catch (InvalidClassStorageException $storageException) {
try { try {
@ -834,10 +834,9 @@ class Photo
* - Sharing a post with a group will create a photo that only the group can see. * - Sharing a post with a group will create a photo that only the group can see.
* - Sharing a photo again that been shared non public before doesn't alter the permissions. * - Sharing a photo again that been shared non public before doesn't alter the permissions.
* *
* @return string
* @throws \Exception * @throws \Exception
*/ */
public static function setPermissionFromBody($body, $uid, $original_contact_id, $str_contact_allow, $str_circle_allow, $str_contact_deny, $str_circle_deny) public static function setPermissionFromBody($body, $uid, $original_contact_id, $str_contact_allow, $str_circle_allow, $str_contact_deny, $str_circle_deny): bool
{ {
// Simplify image codes // Simplify image codes
$img_body = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '[img]$3[/img]', $body); $img_body = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '[img]$3[/img]', $body);

View file

@ -170,9 +170,8 @@ class Delayed
* @param array $attachments * @param array $attachments
* @param int $preparation_mode * @param int $preparation_mode
* @param string $uri * @param string $uri
* @return bool
*/ */
public static function publish(array $item, int $notify = 0, array $taglist = [], array $attachments = [], int $preparation_mode = self::PREPARED, string $uri = '') public static function publish(array $item, int $notify = 0, array $taglist = [], array $attachments = [], int $preparation_mode = self::PREPARED, string $uri = ''): int
{ {
if (!empty($attachments)) { if (!empty($attachments)) {
$item['attachments'] = $attachments; $item['attachments'] = $attachments;