Fix 4 PHPStan errors

This commit is contained in:
Art4 2025-02-25 15:26:16 +00:00
parent 8e7676bfd8
commit 35d95b991b
5 changed files with 65 additions and 81 deletions

View file

@ -15,8 +15,8 @@ use Friendica\Database\Database;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\Model\Post\UserNotification; use Friendica\Model\Post\UserNotification;
use Friendica\Model\Verb; use Friendica\Model\Verb;
use Friendica\Navigation\Notifications\Collection; use Friendica\Navigation\Notifications\Collection\Notifications as NotificationsCollection;
use Friendica\Navigation\Notifications\Entity; use Friendica\Navigation\Notifications\Entity\Notification as NotificationEntity;
use Friendica\Navigation\Notifications\Factory; use Friendica\Navigation\Notifications\Factory;
use Friendica\Network\HTTPException\NotFoundException; use Friendica\Network\HTTPException\NotFoundException;
use Friendica\Protocol\Activity; use Friendica\Protocol\Activity;
@ -41,19 +41,18 @@ class Notification extends BaseRepository
} }
/** /**
* @param array $condition
* @param array $params
* @return Entity\Notification
* @throws NotFoundException * @throws NotFoundException
*/ */
private function selectOne(array $condition, array $params = []): Entity\Notification private function selectOne(array $condition, array $params = []): NotificationEntity
{ {
return parent::_selectOne($condition, $params); $fields = $this->_selectFirstRowAsArray( $condition, $params);
return $this->factory->createFromTableRow($fields);
} }
private function select(array $condition, array $params = []): Collection\Notifications private function select(array $condition, array $params = []): NotificationsCollection
{ {
return new Collection\Notifications(parent::_select($condition, $params)->getArrayCopy()); return new NotificationsCollection(parent::_select($condition, $params)->getArrayCopy());
} }
public function countForUser($uid, array $condition, array $params = []): int public function countForUser($uid, array $condition, array $params = []): int
@ -71,23 +70,21 @@ class Notification extends BaseRepository
} }
/** /**
* @param int $id
* @return Entity\Notification
* @throws NotFoundException * @throws NotFoundException
*/ */
public function selectOneById(int $id): Entity\Notification public function selectOneById(int $id): NotificationEntity
{ {
return $this->selectOne(['id' => $id]); return $this->selectOne(['id' => $id]);
} }
public function selectOneForUser(int $uid, array $condition, array $params = []): Entity\Notification public function selectOneForUser(int $uid, array $condition, array $params = []): NotificationEntity
{ {
$condition = DBA::mergeConditions($condition, ['uid' => $uid]); $condition = DBA::mergeConditions($condition, ['uid' => $uid]);
return $this->selectOne($condition, $params); return $this->selectOne($condition, $params);
} }
public function selectForUser(int $uid, array $condition = [], array $params = []): Collection\Notifications public function selectForUser(int $uid, array $condition = [], array $params = []): NotificationsCollection
{ {
$condition = DBA::mergeConditions($condition, ['uid' => $uid]); $condition = DBA::mergeConditions($condition, ['uid' => $uid]);
@ -98,12 +95,9 @@ class Notification extends BaseRepository
/** /**
* Returns only the most recent notifications for the same conversation or contact * Returns only the most recent notifications for the same conversation or contact
* *
* @param int $uid
*
* @return Collection\Notifications
* @throws Exception * @throws Exception
*/ */
public function selectDetailedForUser(int $uid): Collection\Notifications public function selectDetailedForUser(int $uid): NotificationsCollection
{ {
$notify_type = $this->pconfig->get($uid, 'system', 'notify_type'); $notify_type = $this->pconfig->get($uid, 'system', 'notify_type');
if (!is_null($notify_type)) { if (!is_null($notify_type)) {
@ -113,11 +107,11 @@ class Notification extends BaseRepository
} }
if (!$this->pconfig->get($uid, 'system', 'notify_like')) { if (!$this->pconfig->get($uid, 'system', 'notify_like')) {
$condition = DBA::mergeConditions($condition, ['NOT `vid` IN (?, ?)', Verb::getID(\Friendica\Protocol\Activity::LIKE), Verb::getID(\Friendica\Protocol\Activity::DISLIKE)]); $condition = DBA::mergeConditions($condition, ['NOT `vid` IN (?, ?)', Verb::getID(Activity::LIKE), Verb::getID(Activity::DISLIKE)]);
} }
if (!$this->pconfig->get($uid, 'system', 'notify_announce')) { if (!$this->pconfig->get($uid, 'system', 'notify_announce')) {
$condition = DBA::mergeConditions($condition, ['`vid` != ?', Verb::getID(\Friendica\Protocol\Activity::ANNOUNCE)]); $condition = DBA::mergeConditions($condition, ['`vid` != ?', Verb::getID(Activity::ANNOUNCE)]);
} }
return $this->selectForUser($uid, $condition, ['limit' => 50, 'order' => ['id' => true]]); return $this->selectForUser($uid, $condition, ['limit' => 50, 'order' => ['id' => true]]);
@ -126,12 +120,9 @@ class Notification extends BaseRepository
/** /**
* Returns only the most recent notifications for the same conversation or contact * Returns only the most recent notifications for the same conversation or contact
* *
* @param int $uid
*
* @return Collection\Notifications
* @throws Exception * @throws Exception
*/ */
public function selectDigestForUser(int $uid): Collection\Notifications public function selectDigestForUser(int $uid): NotificationsCollection
{ {
$values = [$uid]; $values = [$uid];
@ -145,14 +136,14 @@ class Notification extends BaseRepository
$like_condition = ''; $like_condition = '';
if (!$this->pconfig->get($uid, 'system', 'notify_like')) { if (!$this->pconfig->get($uid, 'system', 'notify_like')) {
$like_condition = 'AND NOT `vid` IN (?, ?)'; $like_condition = 'AND NOT `vid` IN (?, ?)';
$values[] = Verb::getID(\Friendica\Protocol\Activity::LIKE); $values[] = Verb::getID(Activity::LIKE);
$values[] = Verb::getID(\Friendica\Protocol\Activity::DISLIKE); $values[] = Verb::getID(Activity::DISLIKE);
} }
$announce_condition = ''; $announce_condition = '';
if (!$this->pconfig->get($uid, 'system', 'notify_announce')) { if (!$this->pconfig->get($uid, 'system', 'notify_announce')) {
$announce_condition = 'AND vid != ?'; $announce_condition = 'AND vid != ?';
$values[] = Verb::getID(\Friendica\Protocol\Activity::ANNOUNCE); $values[] = Verb::getID(Activity::ANNOUNCE);
} }
$rows = $this->db->p(" $rows = $this->db->p("
@ -171,7 +162,7 @@ class Notification extends BaseRepository
LIMIT 50 LIMIT 50
", ...$values); ", ...$values);
$Entities = new Collection\Notifications(); $Entities = new NotificationsCollection();
foreach ($rows as $fields) { foreach ($rows as $fields) {
$Entities[] = $this->factory->createFromTableRow($fields); $Entities[] = $this->factory->createFromTableRow($fields);
} }
@ -179,7 +170,7 @@ class Notification extends BaseRepository
return $Entities; return $Entities;
} }
public function selectAllForUser(int $uid): Collection\Notifications public function selectAllForUser(int $uid): NotificationsCollection
{ {
return $this->selectForUser($uid); return $this->selectForUser($uid);
} }
@ -199,7 +190,7 @@ class Notification extends BaseRepository
{ {
$BaseCollection = parent::_selectByBoundaries($condition, $params, $min_id, $max_id, $limit); $BaseCollection = parent::_selectByBoundaries($condition, $params, $min_id, $max_id, $limit);
return new Collection\Notifications($BaseCollection->getArrayCopy(), $BaseCollection->getTotalCount()); return new NotificationsCollection($BaseCollection->getArrayCopy(), $BaseCollection->getTotalCount());
} }
public function setAllSeenForUser(int $uid, array $condition = []): bool public function setAllSeenForUser(int $uid, array $condition = []): bool
@ -217,11 +208,9 @@ class Notification extends BaseRepository
} }
/** /**
* @param Entity\Notification $Notification
* @return Entity\Notification
* @throws Exception * @throws Exception
*/ */
public function save(Entity\Notification $Notification): Entity\Notification public function save(NotificationEntity $Notification): NotificationEntity
{ {
$fields = [ $fields = [
'uid' => $Notification->uid, 'uid' => $Notification->uid,

View file

@ -20,7 +20,8 @@ use Friendica\Database\DBA;
use Friendica\Factory\Api\Mastodon\Notification as NotificationFactory; use Friendica\Factory\Api\Mastodon\Notification as NotificationFactory;
use Friendica\Model; use Friendica\Model;
use Friendica\Navigation\Notifications\Collection; use Friendica\Navigation\Notifications\Collection;
use Friendica\Navigation\Notifications\Entity; use Friendica\Navigation\Notifications\Entity\Notification as NotificationEntity;
use Friendica\Navigation\Notifications\Entity\Notify as NotifyEntity;
use Friendica\Navigation\Notifications\Exception; use Friendica\Navigation\Notifications\Exception;
use Friendica\Navigation\Notifications\Factory; use Friendica\Navigation\Notifications\Factory;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
@ -31,7 +32,7 @@ use Friendica\Util\Emailer;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
/** /**
* @deprecated since 2022.05 Use \Friendica\Navigation\Notifications\Repository\Notification instead * @deprecated 2022.05 Use `\Friendica\Navigation\Notifications\Repository\Notification` instead
*/ */
class Notify extends BaseRepository class Notify extends BaseRepository
{ {
@ -71,15 +72,13 @@ class Notify extends BaseRepository
} }
/** /**
* @param array $condition
* @param array $params
*
* @return Entity\Notify
* @throws HTTPException\NotFoundException * @throws HTTPException\NotFoundException
*/ */
private function selectOne(array $condition, array $params = []): Entity\Notify private function selectOne(array $condition, array $params = []): NotifyEntity
{ {
return parent::_selectOne($condition, $params); $fields = $this->_selectFirstRowAsArray( $condition, $params);
return $this->factory->createFromTableRow($fields);
} }
private function select(array $condition, array $params = []): Collection\Notifies private function select(array $condition, array $params = []): Collection\Notifies
@ -104,10 +103,9 @@ class Notify extends BaseRepository
/** /**
* @param int $id * @param int $id
* *
* @return Entity\Notify
* @throws HTTPException\NotFoundException * @throws HTTPException\NotFoundException
*/ */
public function selectOneById(int $id): Entity\Notify public function selectOneById(int $id): NotifyEntity
{ {
return $this->selectOne(['id' => $id]); return $this->selectOne(['id' => $id]);
} }
@ -139,14 +137,11 @@ class Notify extends BaseRepository
} }
/** /**
* @param Entity\Notify $Notify
*
* @return Entity\Notify
* @throws HTTPException\NotFoundException * @throws HTTPException\NotFoundException
* @throws HTTPException\InternalServerErrorException * @throws HTTPException\InternalServerErrorException
* @throws Exception\NotificationCreationInterceptedException * @throws Exception\NotificationCreationInterceptedException
*/ */
public function save(Entity\Notify $Notify): Entity\Notify public function save(NotifyEntity $Notify): NotifyEntity
{ {
$fields = [ $fields = [
'type' => $Notify->type, 'type' => $Notify->type,
@ -181,7 +176,7 @@ class Notify extends BaseRepository
return $Notify; return $Notify;
} }
public function setAllSeenForRelatedNotify(Entity\Notify $Notify): bool public function setAllSeenForRelatedNotify(NotifyEntity $Notify): bool
{ {
$condition = [ $condition = [
'(`link` = ? OR (`parent` != 0 AND `parent` = ? AND `otype` = ?)) AND `uid` = ?', '(`link` = ? OR (`parent` != 0 AND `parent` = ? AND `otype` = ?)) AND `uid` = ?',
@ -670,7 +665,7 @@ class Notify extends BaseRepository
return false; return false;
} }
public function shouldShowOnDesktop(Entity\Notification $Notification, string $type = null): bool public function shouldShowOnDesktop(NotificationEntity $Notification, string $type = null): bool
{ {
if (is_null($type)) { if (is_null($type)) {
$type = NotificationFactory::getType($Notification); $type = NotificationFactory::getType($Notification);
@ -702,7 +697,7 @@ class Notify extends BaseRepository
return false; return false;
} }
public function createFromNotification(Entity\Notification $Notification): bool public function createFromNotification(NotificationEntity $Notification): bool
{ {
$this->logger->info('Start', ['uid' => $Notification->uid, 'id' => $Notification->id, 'type' => $Notification->type]); $this->logger->info('Start', ['uid' => $Notification->uid, 'id' => $Notification->id, 'type' => $Notification->type]);

View file

@ -61,6 +61,34 @@ class Introduction implements \JsonSerializable
/** @var string */ /** @var string */
private $about; private $about;
public function __construct(array $data = [])
{
$this->label = $data['label'] ?? '';
$this->type = $data['str_type'] ?? '';
$this->intro_id = $data['intro_id'] ?? -1;
$this->madeBy = $data['madeBy'] ?? '';
$this->madeByUrl = $data['madeByUrl'] ?? '';
$this->madeByZrl = $data['madeByZrl'] ?? '';
$this->madeByAddr = $data['madeByAddr'] ?? '';
$this->contactId = $data['contactId'] ?? -1;
$this->photo = $data['photo'] ?? '';
$this->name = $data['name'] ?? '';
$this->url = $data['url'] ?? '';
$this->zrl = $data['zrl'] ?? '';
$this->hidden = $data['hidden'] ?? false;
$this->postNewFriend = $data['postNewFriend'] ?? '';
$this->knowYou = $data['knowYou'] ?? false;
$this->note = $data['note'] ?? '';
$this->request = $data['request'] ?? '';
$this->dfrnId = -1;
$this->addr = $data['addr'] ?? '';
$this->network = $data['network'] ?? '';
$this->uid = $data['uid'] ?? -1;
$this->keywords = $data['keywords'] ?? '';
$this->location = $data['location'] ?? '';
$this->about = $data['about'] ?? '';
}
public function getLabel(): string public function getLabel(): string
{ {
return $this->label; return $this->label;
@ -131,7 +159,7 @@ class Introduction implements \JsonSerializable
return $this->postNewFriend; return $this->postNewFriend;
} }
public function getKnowYou(): string public function getKnowYou(): bool
{ {
return $this->knowYou; return $this->knowYou;
} }
@ -181,34 +209,6 @@ class Introduction implements \JsonSerializable
return $this->about; return $this->about;
} }
public function __construct(array $data = [])
{
$this->label = $data['label'] ?? '';
$this->type = $data['str_type'] ?? '';
$this->intro_id = $data['intro_id'] ?? -1;
$this->madeBy = $data['madeBy'] ?? '';
$this->madeByUrl = $data['madeByUrl'] ?? '';
$this->madeByZrl = $data['madeByZrl'] ?? '';
$this->madeByAddr = $data['madeByAddr'] ?? '';
$this->contactId = $data['contactId'] ?? -1;
$this->photo = $data['photo'] ?? '';
$this->name = $data['name'] ?? '';
$this->url = $data['url'] ?? '';
$this->zrl = $data['zrl'] ?? '';
$this->hidden = $data['hidden'] ?? false;
$this->postNewFriend = $data['postNewFriend'] ?? '';
$this->knowYou = $data['knowYou'] ?? false;
$this->note = $data['note'] ?? '';
$this->request = $data['request'] ?? '';
$this->dfrnId = -1;
$this->addr = $data['addr'] ?? '';
$this->network = $data['network'] ?? '';
$this->uid = $data['uid'] ?? -1;
$this->keywords = $data['keywords'] ?? '';
$this->location = $data['location'] ?? '';
$this->about = $data['about'] ?? '';
}
/** /**
* @inheritDoc * @inheritDoc
*/ */

View file

@ -246,7 +246,7 @@ class CurlResult implements ICanHandleHttpResponses
/** {@inheritDoc} */ /** {@inheritDoc} */
public function getReturnCode(): string public function getReturnCode(): string
{ {
return $this->returnCode; return (string) $this->returnCode;
} }
/** {@inheritDoc} */ /** {@inheritDoc} */

View file

@ -100,7 +100,7 @@ class GuzzleResponse extends Response implements ICanHandleHttpResponses, Respon
/** {@inheritDoc} */ /** {@inheritDoc} */
public function getReturnCode(): string public function getReturnCode(): string
{ {
return $this->getStatusCode(); return (string) $this->getStatusCode();
} }
/** {@inheritDoc} */ /** {@inheritDoc} */