Fix 10 PHPStan errors

This commit is contained in:
Art4 2025-03-13 09:14:48 +00:00
parent 9ea4f591c7
commit 7ce6afd151
9 changed files with 122 additions and 167 deletions

View file

@ -24,7 +24,7 @@ class BaseCollection extends \ArrayIterator
* @param BaseEntity[] $entities * @param BaseEntity[] $entities
* @param int|null $totalCount * @param int|null $totalCount
*/ */
public function __construct(array $entities = [], int $totalCount = null) public function __construct(array $entities = [], ?int $totalCount = null)
{ {
parent::__construct($entities); parent::__construct($entities);
@ -102,7 +102,7 @@ class BaseCollection extends \ArrayIterator
* @return BaseCollection * @return BaseCollection
* @see array_filter() * @see array_filter()
*/ */
public function filter(callable $callback = null, int $flag = 0): BaseCollection public function filter(?callable $callback = null, int $flag = 0): BaseCollection
{ {
$class = get_class($this); $class = get_class($this);
@ -111,8 +111,6 @@ class BaseCollection extends \ArrayIterator
/** /**
* Reverse the orders of the elements in the collection * Reverse the orders of the elements in the collection
*
* @return $this
*/ */
public function reverse(): BaseCollection public function reverse(): BaseCollection
{ {
@ -125,7 +123,6 @@ class BaseCollection extends \ArrayIterator
* Split the collection in smaller collections no bigger than the provided length * Split the collection in smaller collections no bigger than the provided length
* *
* @param int $length * @param int $length
* @return static[]
*/ */
public function chunk(int $length): array public function chunk(int $length): array
{ {
@ -133,11 +130,14 @@ class BaseCollection extends \ArrayIterator
throw new \RangeException('BaseCollection->chunk(): Size parameter expected to be greater than 0'); throw new \RangeException('BaseCollection->chunk(): Size parameter expected to be greater than 0');
} }
return array_map(function ($array) { return array_map(
function ($array) {
$class = get_class($this); $class = get_class($this);
return new $class($array); return new $class($array);
}, array_chunk($this->getArrayCopy(), $length)); },
array_chunk($this->getArrayCopy(), $length)
);
} }

View file

@ -8,11 +8,11 @@
namespace Friendica\Contact\FriendSuggest\Repository; namespace Friendica\Contact\FriendSuggest\Repository;
use Friendica\BaseRepository; use Friendica\BaseRepository;
use Friendica\Contact\FriendSuggest\Collection; use Friendica\Contact\FriendSuggest\Collection\FriendSuggests as FriendSuggestsCollection;
use Friendica\Contact\FriendSuggest\Entity\FriendSuggest as FriendSuggestEntity; use Friendica\Contact\FriendSuggest\Entity\FriendSuggest as FriendSuggestEntity;
use Friendica\Contact\FriendSuggest\Exception\FriendSuggestNotFoundException; use Friendica\Contact\FriendSuggest\Exception\FriendSuggestNotFoundException;
use Friendica\Contact\FriendSuggest\Exception\FriendSuggestPersistenceException; use Friendica\Contact\FriendSuggest\Exception\FriendSuggestPersistenceException;
use Friendica\Contact\FriendSuggest\Factory; use Friendica\Contact\FriendSuggest\Factory\FriendSuggest as FriendSuggestFactory;
use Friendica\Database\Database; use Friendica\Database\Database;
use Friendica\Network\HTTPException\NotFoundException; use Friendica\Network\HTTPException\NotFoundException;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
@ -20,12 +20,12 @@ use Psr\Log\LoggerInterface;
class FriendSuggest extends BaseRepository class FriendSuggest extends BaseRepository
{ {
/** @var Factory\FriendSuggest */ /** @var FriendSuggestFactory */
protected $factory; protected $factory;
protected static $table_name = 'fsuggest'; protected static $table_name = 'fsuggest';
public function __construct(Database $database, LoggerInterface $logger, Factory\FriendSuggest $factory) public function __construct(Database $database, LoggerInterface $logger, FriendSuggestFactory $factory)
{ {
parent::__construct($database, $logger, $factory); parent::__construct($database, $logger, $factory);
} }
@ -49,20 +49,17 @@ class FriendSuggest extends BaseRepository
*/ */
private function selectOne(array $condition, array $params = []): FriendSuggestEntity private function selectOne(array $condition, array $params = []): FriendSuggestEntity
{ {
return parent::_selectOne($condition, $params); $fields = $this->_selectFirstRowAsArray( $condition, $params);
return $this->factory->createFromTableRow($fields);
} }
/** /**
* @param array $condition
* @param array $params
*
* @return Collection\FriendSuggests
*
* @throws \Exception * @throws \Exception
*/ */
private function select(array $condition, array $params = []): Collection\FriendSuggests private function select(array $condition, array $params = []): FriendSuggestsCollection
{ {
return new Collection\FriendSuggests(parent::_select($condition, $params)->getArrayCopy()); return new FriendSuggestsCollection(parent::_select($condition, $params)->getArrayCopy());
} }
/** /**
@ -78,13 +75,9 @@ class FriendSuggest extends BaseRepository
} }
/** /**
* @param int $cid
*
* @return Collection\FriendSuggests
*
* @throws FriendSuggestPersistenceException In case the underlying storage cannot select the suggestion * @throws FriendSuggestPersistenceException In case the underlying storage cannot select the suggestion
*/ */
public function selectForContact(int $cid): Collection\FriendSuggests public function selectForContact(int $cid): FriendSuggestsCollection
{ {
try { try {
return $this->select(['cid' => $cid]); return $this->select(['cid' => $cid]);
@ -114,13 +107,9 @@ class FriendSuggest extends BaseRepository
} }
/** /**
* @param Collection\FriendSuggests $fsuggests
*
* @return bool
*
* @throws FriendSuggestNotFoundException in case the underlying storage cannot delete the suggestion * @throws FriendSuggestNotFoundException in case the underlying storage cannot delete the suggestion
*/ */
public function delete(Collection\FriendSuggests $fsuggests): bool public function delete(FriendSuggestsCollection $fsuggests): bool
{ {
try { try {
$ids = $fsuggests->column('id'); $ids = $fsuggests->column('id');

View file

@ -10,9 +10,9 @@ namespace Friendica\Contact\Introduction\Repository;
use Friendica\BaseRepository; use Friendica\BaseRepository;
use Friendica\Contact\Introduction\Exception\IntroductionNotFoundException; use Friendica\Contact\Introduction\Exception\IntroductionNotFoundException;
use Friendica\Contact\Introduction\Exception\IntroductionPersistenceException; use Friendica\Contact\Introduction\Exception\IntroductionPersistenceException;
use Friendica\Contact\Introduction\Collection; use Friendica\Contact\Introduction\Collection\Introductions as IntroductionsCollection;
use Friendica\Contact\Introduction\Entity; use Friendica\Contact\Introduction\Entity\Introduction as IntroductionEntity;
use Friendica\Contact\Introduction\Factory; use Friendica\Contact\Introduction\Factory\Introduction as IntroductionFactory;
use Friendica\Database\Database; use Friendica\Database\Database;
use Friendica\Network\HTTPException\NotFoundException; use Friendica\Network\HTTPException\NotFoundException;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
@ -20,37 +20,30 @@ use Psr\Log\LoggerInterface;
class Introduction extends BaseRepository class Introduction extends BaseRepository
{ {
/** @var Factory\Introduction */ /** @var IntroductionFactory */
protected $factory; protected $factory;
protected static $table_name = 'intro'; protected static $table_name = 'intro';
public function __construct(Database $database, LoggerInterface $logger, Factory\Introduction $factory) public function __construct(Database $database, LoggerInterface $logger, IntroductionFactory $factory)
{ {
parent::__construct($database, $logger, $factory); parent::__construct($database, $logger, $factory);
} }
/** /**
* @param array $condition
* @param array $params
*
* @return Entity\Introduction
*
* @throws NotFoundException the underlying exception if there's no Introduction with the given conditions * @throws NotFoundException the underlying exception if there's no Introduction with the given conditions
*/ */
private function selectOne(array $condition, array $params = []): Entity\Introduction private function selectOne(array $condition, array $params = []): IntroductionEntity
{ {
return parent::_selectOne($condition, $params); $fields = $this->_selectFirstRowAsArray( $condition, $params);
return $this->factory->createFromTableRow($fields);
} }
/** /**
* Converts a given Introduction into a DB compatible row array * Converts a given Introduction into a DB compatible row array
*
* @param Entity\Introduction $introduction
*
* @return array
*/ */
protected function convertToTableRow(Entity\Introduction $introduction): array protected function convertToTableRow(IntroductionEntity $introduction): array
{ {
return [ return [
'uid' => $introduction->uid, 'uid' => $introduction->uid,
@ -65,14 +58,9 @@ class Introduction extends BaseRepository
} }
/** /**
* @param int $id
* @param int $uid
*
* @return Entity\Introduction
*
* @throws IntroductionNotFoundException in case there is no Introduction with this id * @throws IntroductionNotFoundException in case there is no Introduction with this id
*/ */
public function selectOneById(int $id, int $uid): Entity\Introduction public function selectOneById(int $id, int $uid): IntroductionEntity
{ {
try { try {
return $this->selectOne(['id' => $id, 'uid' => $uid]); return $this->selectOne(['id' => $id, 'uid' => $uid]);
@ -88,10 +76,8 @@ class Introduction extends BaseRepository
* @param int|null $min_id * @param int|null $min_id
* @param int|null $max_id * @param int|null $max_id
* @param int $limit * @param int $limit
*
* @return Collection\Introductions
*/ */
public function selectForUser(int $uid, int $min_id = null, int $max_id = null, int $limit = self::LIMIT): Collection\Introductions public function selectForUser(int $uid, ?int $min_id = null, ?int $max_id = null, int $limit = self::LIMIT): IntroductionsCollection
{ {
try { try {
$BaseCollection = parent::_selectByBoundaries( $BaseCollection = parent::_selectByBoundaries(
@ -102,19 +88,15 @@ class Introduction extends BaseRepository
throw new IntroductionPersistenceException(sprintf('Cannot select Introductions for used %d', $uid), $e); throw new IntroductionPersistenceException(sprintf('Cannot select Introductions for used %d', $uid), $e);
} }
return new Collection\Introductions($BaseCollection->getArrayCopy(), $BaseCollection->getTotalCount()); return new IntroductionsCollection($BaseCollection->getArrayCopy(), $BaseCollection->getTotalCount());
} }
/** /**
* Selects the introduction for a given contact * Selects the introduction for a given contact
* *
* @param int $cid
*
* @return Entity\Introduction
*
* @throws IntroductionNotFoundException in case there is not Introduction for this contact * @throws IntroductionNotFoundException in case there is not Introduction for this contact
*/ */
public function selectForContact(int $cid): Entity\Introduction public function selectForContact(int $cid): IntroductionEntity
{ {
try { try {
return $this->selectOne(['contact-id' => $cid]); return $this->selectOne(['contact-id' => $cid]);
@ -150,13 +132,9 @@ class Introduction extends BaseRepository
} }
/** /**
* @param Entity\Introduction $introduction
*
* @return bool
*
* @throws IntroductionPersistenceException in case the underlying storage cannot delete the Introduction * @throws IntroductionPersistenceException in case the underlying storage cannot delete the Introduction
*/ */
public function delete(Entity\Introduction $introduction): bool public function delete(IntroductionEntity $introduction): bool
{ {
if (!$introduction->id) { if (!$introduction->id) {
return false; return false;
@ -170,13 +148,9 @@ class Introduction extends BaseRepository
} }
/** /**
* @param Entity\Introduction $introduction
*
* @return Entity\Introduction
*
* @throws IntroductionPersistenceException In case the underlying storage cannot save the Introduction * @throws IntroductionPersistenceException In case the underlying storage cannot save the Introduction
*/ */
public function save(Entity\Introduction $introduction): Entity\Introduction public function save(IntroductionEntity $introduction): IntroductionEntity
{ {
try { try {
$fields = $this->convertToTableRow($introduction); $fields = $this->convertToTableRow($introduction);

View file

@ -7,59 +7,54 @@
namespace Friendica\Contact\LocalRelationship\Repository; namespace Friendica\Contact\LocalRelationship\Repository;
use Friendica\Contact\LocalRelationship\Entity; use Exception;
use Friendica\Contact\LocalRelationship\Exception; use Friendica\BaseRepository;
use Friendica\Contact\LocalRelationship\Factory; use Friendica\Contact\LocalRelationship\Entity\LocalRelationship as LocalRelationshipEntity;
use Friendica\Contact\LocalRelationship\Exception\LocalRelationshipPersistenceException;
use Friendica\Contact\LocalRelationship\Factory\LocalRelationship as LocalRelationshipFactory;
use Friendica\Database\Database; use Friendica\Database\Database;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException\NotFoundException;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
class LocalRelationship extends \Friendica\BaseRepository class LocalRelationship extends BaseRepository
{ {
protected static $table_name = 'user-contact'; protected static $table_name = 'user-contact';
/** @var Factory\LocalRelationship */ /** @var LocalRelationshipFactory */
protected $factory; protected $factory;
public function __construct(Database $database, LoggerInterface $logger, Factory\LocalRelationship $factory) public function __construct(Database $database, LoggerInterface $logger, LocalRelationshipFactory $factory)
{ {
parent::__construct($database, $logger, $factory); parent::__construct($database, $logger, $factory);
} }
/** /**
* @param int $uid * @throws NotFoundException
* @param int $cid
* @return Entity\LocalRelationship
* @throws HTTPException\NotFoundException
*/ */
public function selectForUserContact(int $uid, int $cid): Entity\LocalRelationship public function selectForUserContact(int $uid, int $cid): LocalRelationshipEntity
{ {
return $this->_selectOne(['uid' => $uid, 'cid' => $cid]); $fields = $this->_selectFirstRowAsArray( ['uid' => $uid, 'cid' => $cid]);
return $this->factory->createFromTableRow($fields);
} }
/** /**
* Returns the existing local relationship between a user and a public contact or a default * Returns the existing local relationship between a user and a public contact or a default
* relationship if it doesn't. * relationship if it doesn't.
* *
* @param int $uid * @throws NotFoundException
* @param int $cid
* @return Entity\LocalRelationship
* @throws HTTPException\NotFoundException
*/ */
public function getForUserContact(int $uid, int $cid): Entity\LocalRelationship public function getForUserContact(int $uid, int $cid): LocalRelationshipEntity
{ {
try { try {
return $this->selectForUserContact($uid, $cid); return $this->selectForUserContact($uid, $cid);
} catch (HTTPException\NotFoundException $e) { } catch (NotFoundException $e) {
return $this->factory->createFromTableRow(['uid' => $uid, 'cid' => $cid]); return $this->factory->createFromTableRow(['uid' => $uid, 'cid' => $cid]);
} }
} }
/** /**
* @param int $uid * @throws Exception
* @param int $cid
* @return bool
* @throws \Exception
*/ */
public function existsForUserContact(int $uid, int $cid): bool public function existsForUserContact(int $uid, int $cid): bool
{ {
@ -68,12 +63,8 @@ class LocalRelationship extends \Friendica\BaseRepository
/** /**
* Converts a given local relationship into a DB compatible row array * Converts a given local relationship into a DB compatible row array
*
* @param Entity\LocalRelationship $localRelationship
*
* @return array
*/ */
protected function convertToTableRow(Entity\LocalRelationship $localRelationship): array protected function convertToTableRow(LocalRelationshipEntity $localRelationship): array
{ {
return [ return [
'uid' => $localRelationship->userId, 'uid' => $localRelationship->userId,
@ -97,13 +88,9 @@ class LocalRelationship extends \Friendica\BaseRepository
} }
/** /**
* @param Entity\LocalRelationship $localRelationship * @throws LocalRelationshipPersistenceException In case the underlying storage cannot save the LocalRelationship
*
* @return Entity\LocalRelationship
*
* @throws Exception\LocalRelationshipPersistenceException In case the underlying storage cannot save the LocalRelationship
*/ */
public function save(Entity\LocalRelationship $localRelationship): Entity\LocalRelationship public function save(LocalRelationshipEntity $localRelationship): LocalRelationshipEntity
{ {
try { try {
$fields = $this->convertToTableRow($localRelationship); $fields = $this->convertToTableRow($localRelationship);
@ -111,8 +98,8 @@ class LocalRelationship extends \Friendica\BaseRepository
$this->db->insert(self::$table_name, $fields, Database::INSERT_UPDATE); $this->db->insert(self::$table_name, $fields, Database::INSERT_UPDATE);
return $localRelationship; return $localRelationship;
} catch (\Exception $exception) { } catch (Exception $exception) {
throw new Exception\LocalRelationshipPersistenceException(sprintf('Cannot insert/update the local relationship %d for user %d', $localRelationship->contactId, $localRelationship->userId), $exception); throw new LocalRelationshipPersistenceException(sprintf('Cannot insert/update the local relationship %d for user %d', $localRelationship->contactId, $localRelationship->userId), $exception);
} }
} }
} }

View file

@ -7,10 +7,10 @@
namespace Friendica\Content\Conversation\Repository; namespace Friendica\Content\Conversation\Repository;
use Friendica\BaseCollection; use Friendica\BaseRepository;
use Friendica\Content\Conversation\Collection\UserDefinedChannels; use Friendica\Content\Conversation\Collection\UserDefinedChannels;
use Friendica\Content\Conversation\Entity; use Friendica\Content\Conversation\Entity\UserDefinedChannel as UserDefinedChannelEntity;
use Friendica\Content\Conversation\Factory; use Friendica\Content\Conversation\Factory\UserDefinedChannel as UserDefinedChannelFactory;
use Friendica\Core\Config\Capability\IManageConfigValues; use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Database\Database; use Friendica\Database\Database;
use Friendica\Database\DBA; use Friendica\Database\DBA;
@ -21,13 +21,16 @@ use Friendica\Model\User;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
class UserDefinedChannel extends \Friendica\BaseRepository class UserDefinedChannel extends BaseRepository
{ {
protected static $table_name = 'channel'; protected static $table_name = 'channel';
/** @var UserDefinedChannelFactory */
protected $factory;
private IManageConfigValues $config; private IManageConfigValues $config;
public function __construct(Database $database, LoggerInterface $logger, Factory\UserDefinedChannel $factory, IManageConfigValues $config) public function __construct(Database $database, LoggerInterface $logger, UserDefinedChannelFactory $factory, IManageConfigValues $config)
{ {
parent::__construct($database, $logger, $factory); parent::__construct($database, $logger, $factory);
@ -40,7 +43,7 @@ class UserDefinedChannel extends \Friendica\BaseRepository
* @return UserDefinedChannels * @return UserDefinedChannels
* @throws \Exception * @throws \Exception
*/ */
protected function _select(array $condition, array $params = []): BaseCollection protected function _select(array $condition, array $params = []): UserDefinedChannels
{ {
$rows = $this->db->selectToArray(static::$table_name, [], $condition, $params); $rows = $this->db->selectToArray(static::$table_name, [], $condition, $params);
@ -62,12 +65,13 @@ class UserDefinedChannel extends \Friendica\BaseRepository
* *
* @param int $id The id of the user defined channel * @param int $id The id of the user defined channel
* @param int $uid The user that this channel belongs to. (Not part of the primary key) * @param int $uid The user that this channel belongs to. (Not part of the primary key)
* @return Entity\UserDefinedChannel
* @throws \Friendica\Network\HTTPException\NotFoundException * @throws \Friendica\Network\HTTPException\NotFoundException
*/ */
public function selectById(int $id, int $uid): Entity\UserDefinedChannel public function selectById(int $id, int $uid): UserDefinedChannelEntity
{ {
return $this->_selectOne(['id' => $id, 'uid' => $uid]); $fields = $this->_selectFirstRowAsArray( ['id' => $id, 'uid' => $uid]);
return $this->factory->createFromTableRow($fields);
} }
/** /**
@ -106,7 +110,7 @@ class UserDefinedChannel extends \Friendica\BaseRepository
return $this->_select(['uid' => $uid]); return $this->_select(['uid' => $uid]);
} }
public function save(Entity\UserDefinedChannel $Channel): Entity\UserDefinedChannel public function save(UserDefinedChannelEntity $Channel): UserDefinedChannelEntity
{ {
$fields = [ $fields = [
'label' => $Channel->label, 'label' => $Channel->label,
@ -210,7 +214,7 @@ class UserDefinedChannel extends \Friendica\BaseRepository
$disposableFullTextSearch = new DisposableFullTextSearch($this->db, $searchtext); $disposableFullTextSearch = new DisposableFullTextSearch($this->db, $searchtext);
$filteredChannels = $this->select(['uid' => array_column($users, 'uid'), 'publish' => true, 'valid' => true])->filter( $filteredChannels = $this->select(['uid' => array_column($users, 'uid'), 'publish' => true, 'valid' => true])->filter(
function (Entity\UserDefinedChannel $channel) use ($owner_id, $reshare_id, $language, $tags, $media_type, $disposableFullTextSearch, $searchtext) { function (UserDefinedChannelEntity $channel) use ($owner_id, $reshare_id, $language, $tags, $media_type, $disposableFullTextSearch, $searchtext) {
static $uids = []; static $uids = [];
// Filter out channels from already picked users // Filter out channels from already picked users

View file

@ -13,7 +13,6 @@ use Friendica\Util\Images;
use Friendica\Util\Proxy; use Friendica\Util\Proxy;
use Psr\Http\Message\UriInterface; use Psr\Http\Message\UriInterface;
/** /**
* @property-read int $id * @property-read int $id
* @property-read int $uriId * @property-read int $uriId
@ -210,7 +209,7 @@ class PostMedia extends BaseEntity
* *
* @param \GuzzleHttp\Psr7\Uri $preview * @param \GuzzleHttp\Psr7\Uri $preview
* @param string $size * @param string $size
* @return $this * @return self
*/ */
public function withPreview(\GuzzleHttp\Psr7\Uri $preview, string $size = ''): self public function withPreview(\GuzzleHttp\Psr7\Uri $preview, string $size = ''): self
{ {

View file

@ -9,8 +9,9 @@ namespace Friendica\Content\Post\Factory;
use Friendica\BaseFactory; use Friendica\BaseFactory;
use Friendica\Capabilities\ICanCreateFromTableRow; use Friendica\Capabilities\ICanCreateFromTableRow;
use Friendica\Content\Post\Entity; use Friendica\Content\Post\Entity\PostMedia as PostMediaEntity;
use Friendica\Network; use Friendica\Network\Entity\MimeType as MimeTypeEntity;
use Friendica\Network\Factory\MimeType as MimeTypeFactory;
use Friendica\Util\Network as UtilNetwork; use Friendica\Util\Network as UtilNetwork;
use GuzzleHttp\Psr7\Uri; use GuzzleHttp\Psr7\Uri;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
@ -18,10 +19,10 @@ use stdClass;
class PostMedia extends BaseFactory implements ICanCreateFromTableRow class PostMedia extends BaseFactory implements ICanCreateFromTableRow
{ {
/** @var Network\Factory\MimeType */ /** @var MimeTypeFactory */
private $mimeTypeFactory; private $mimeTypeFactory;
public function __construct(Network\Factory\MimeType $mimeTypeFactory, LoggerInterface $logger) public function __construct(MimeTypeFactory $mimeTypeFactory, LoggerInterface $logger)
{ {
parent::__construct($logger); parent::__construct($logger);
@ -31,9 +32,9 @@ class PostMedia extends BaseFactory implements ICanCreateFromTableRow
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function createFromTableRow(array $row) public function createFromTableRow(array $row): PostMediaEntity
{ {
return new Entity\PostMedia( return new PostMediaEntity(
$row['uri-id'], $row['uri-id'],
UtilNetwork::createUriFromString($row['url']), UtilNetwork::createUriFromString($row['url']),
$row['type'], $row['type'],
@ -58,13 +59,13 @@ class PostMedia extends BaseFactory implements ICanCreateFromTableRow
); );
} }
public function createFromBlueskyImageEmbed(int $uriId, stdClass $image): Entity\PostMedia public function createFromBlueskyImageEmbed(int $uriId, stdClass $image): PostMediaEntity
{ {
return new Entity\PostMedia( return new PostMediaEntity(
$uriId, $uriId,
new Uri($image->fullsize), new Uri($image->fullsize),
Entity\PostMedia::TYPE_IMAGE, PostMediaEntity::TYPE_IMAGE,
new Network\Entity\MimeType('unkn', 'unkn'), new MimeTypeEntity('unkn', 'unkn'),
null, null,
null, null,
null, null,
@ -77,13 +78,13 @@ class PostMedia extends BaseFactory implements ICanCreateFromTableRow
} }
public function createFromBlueskyExternalEmbed(int $uriId, stdClass $external): Entity\PostMedia public function createFromBlueskyExternalEmbed(int $uriId, stdClass $external): PostMediaEntity
{ {
return new Entity\PostMedia( return new PostMediaEntity(
$uriId, $uriId,
new Uri($external->uri), new Uri($external->uri),
Entity\PostMedia::TYPE_HTML, PostMediaEntity::TYPE_HTML,
new Network\Entity\MimeType('text', 'html'), new MimeTypeEntity('text', 'html'),
null, null,
null, null,
null, null,

View file

@ -7,11 +7,10 @@
namespace Friendica\Content\Post\Repository; namespace Friendica\Content\Post\Repository;
use Friendica\BaseCollection;
use Friendica\BaseRepository; use Friendica\BaseRepository;
use Friendica\Content\Post\Collection; use Friendica\Content\Post\Collection\PostMedias as PostMediasCollection;
use Friendica\Content\Post\Entity; use Friendica\Content\Post\Entity\PostMedia as PostMediaEntity;
use Friendica\Content\Post\Factory; use Friendica\Content\Post\Factory\PostMedia as PostMediaFactory;
use Friendica\Database\Database; use Friendica\Database\Database;
use Friendica\Model\Post; use Friendica\Model\Post;
use Friendica\Util\Strings; use Friendica\Util\Strings;
@ -21,16 +20,19 @@ class PostMedia extends BaseRepository
{ {
protected static $table_name = 'post-media'; protected static $table_name = 'post-media';
public function __construct(Database $database, LoggerInterface $logger, Factory\PostMedia $factory) /** @var PostMediaFactory */
protected $factory;
public function __construct(Database $database, LoggerInterface $logger, PostMediaFactory $factory)
{ {
parent::__construct($database, $logger, $factory); parent::__construct($database, $logger, $factory);
} }
protected function _select(array $condition, array $params = []): BaseCollection protected function _select(array $condition, array $params = []): PostMediasCollection
{ {
$rows = $this->db->selectToArray(static::$table_name, [], $condition, $params); $rows = $this->db->selectToArray(static::$table_name, [], $condition, $params);
$Entities = new Collection\PostMedias(); $Entities = new PostMediasCollection();
foreach ($rows as $fields) { foreach ($rows as $fields) {
try { try {
$Entities[] = $this->factory->createFromTableRow($fields); $Entities[] = $this->factory->createFromTableRow($fields);
@ -42,17 +44,19 @@ class PostMedia extends BaseRepository
return $Entities; return $Entities;
} }
public function selectOneById(int $postMediaId): Entity\PostMedia public function selectOneById(int $postMediaId): PostMediaEntity
{ {
return $this->_selectOne(['id' => $postMediaId]); $fields = $this->_selectFirstRowAsArray( ['id' => $postMediaId]);
return $this->factory->createFromTableRow($fields);
} }
public function selectByUriId(int $uriId): Collection\PostMedias public function selectByUriId(int $uriId): PostMediasCollection
{ {
return $this->_select(["`uri-id` = ? AND `type` != ?", $uriId, Post\Media::UNKNOWN]); return $this->_select(["`uri-id` = ? AND `type` != ?", $uriId, Post\Media::UNKNOWN]);
} }
public function save(Entity\PostMedia $PostMedia): Entity\PostMedia public function save(PostMediaEntity $PostMedia): PostMediaEntity
{ {
$fields = [ $fields = [
'uri-id' => $PostMedia->uriId, 'uri-id' => $PostMedia->uriId,
@ -97,14 +101,14 @@ class PostMedia extends BaseRepository
* @param int $uri_id URI id * @param int $uri_id URI id
* @param array $links list of links that shouldn't be added * @param array $links list of links that shouldn't be added
* @param bool $has_media * @param bool $has_media
* @return Collection\PostMedias[] Three collections in "visual", "link" and "additional" keys * @return PostMediasCollection[] Three collections in "visual", "link" and "additional" keys
*/ */
public function splitAttachments(int $uri_id, array $links = [], bool $has_media = true): array public function splitAttachments(int $uri_id, array $links = [], bool $has_media = true): array
{ {
$attachments = [ $attachments = [
'visual' => new Collection\PostMedias(), 'visual' => new PostMediasCollection(),
'link' => new Collection\PostMedias(), 'link' => new PostMediasCollection(),
'additional' => new Collection\PostMedias(), 'additional' => new PostMediasCollection(),
]; ];
if (!$has_media) { if (!$has_media) {
@ -137,7 +141,7 @@ class PostMedia extends BaseRepository
// Currently these two types are ignored here. // Currently these two types are ignored here.
// Posts are added differently and contacts are not displayed as attachments. // Posts are added differently and contacts are not displayed as attachments.
if (in_array($PostMedia->type, [Entity\PostMedia::TYPE_ACCOUNT, Entity\PostMedia::TYPE_ACTIVITY])) { if (in_array($PostMedia->type, [PostMediaEntity::TYPE_ACCOUNT, PostMediaEntity::TYPE_ACTIVITY])) {
continue; continue;
} }
@ -148,17 +152,17 @@ class PostMedia extends BaseRepository
//$PostMedia->filetype = $filetype; //$PostMedia->filetype = $filetype;
//$PostMedia->subtype = $subtype; //$PostMedia->subtype = $subtype;
if ($PostMedia->type == Entity\PostMedia::TYPE_HTML || ($PostMedia->mimetype->type == 'text' && $PostMedia->mimetype->subtype == 'html')) { if ($PostMedia->type == PostMediaEntity::TYPE_HTML || ($PostMedia->mimetype->type == 'text' && $PostMedia->mimetype->subtype == 'html')) {
$attachments['link'][] = $PostMedia; $attachments['link'][] = $PostMedia;
continue; continue;
} }
if ( if (
in_array($PostMedia->type, [Entity\PostMedia::TYPE_AUDIO, Entity\PostMedia::TYPE_IMAGE, Entity\PostMedia::TYPE_HLS]) || in_array($PostMedia->type, [PostMediaEntity::TYPE_AUDIO, PostMediaEntity::TYPE_IMAGE, PostMediaEntity::TYPE_HLS]) ||
in_array($PostMedia->mimetype->type, ['audio', 'image']) in_array($PostMedia->mimetype->type, ['audio', 'image'])
) { ) {
$attachments['visual'][] = $PostMedia; $attachments['visual'][] = $PostMedia;
} elseif (($PostMedia->type == Entity\PostMedia::TYPE_VIDEO) || ($PostMedia->mimetype->type == 'video')) { } elseif (($PostMedia->type == PostMediaEntity::TYPE_VIDEO) || ($PostMedia->mimetype->type == 'video')) {
if (!empty($PostMedia->height)) { if (!empty($PostMedia->height)) {
// Peertube videos are delivered in many different resolutions. We pick a moderate one. // Peertube videos are delivered in many different resolutions. We pick a moderate one.
// Since only Peertube provides a "height" parameter, this wouldn't be executed // Since only Peertube provides a "height" parameter, this wouldn't be executed

View file

@ -8,11 +8,11 @@
namespace Friendica\Core\Worker\Repository; namespace Friendica\Core\Worker\Repository;
use Friendica\BaseRepository; use Friendica\BaseRepository;
use Friendica\Core\Worker\Entity\Process as ProcessEntity;
use Friendica\Core\Worker\Exception\ProcessPersistenceException; use Friendica\Core\Worker\Exception\ProcessPersistenceException;
use Friendica\Core\Worker\Factory\Process as ProcessFactory;
use Friendica\Database\Database; use Friendica\Database\Database;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
use Friendica\Core\Worker\Factory;
use Friendica\Core\Worker\Entity;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
/** /**
@ -24,13 +24,13 @@ class Process extends BaseRepository
protected static $table_name = 'process'; protected static $table_name = 'process';
/** @var Factory\Process */ /** @var ProcessFactory */
protected $factory; protected $factory;
/** @var string */ /** @var string */
private $currentHost; private $currentHost;
public function __construct(Database $database, LoggerInterface $logger, Factory\Process $factory, array $server) public function __construct(Database $database, LoggerInterface $logger, ProcessFactory $factory, array $server)
{ {
parent::__construct($database, $logger, $factory); parent::__construct($database, $logger, $factory);
@ -39,13 +39,8 @@ class Process extends BaseRepository
/** /**
* Starts and Returns the process for a given PID at the current host * Starts and Returns the process for a given PID at the current host
*
* @param int $pid
* @param string $command
*
* @return Entity\Process
*/ */
public function create(int $pid, string $command): Entity\Process public function create(int $pid, string $command): ProcessEntity
{ {
// Cleanup inactive process // Cleanup inactive process
$this->deleteInactive(); $this->deleteInactive();
@ -64,7 +59,9 @@ class Process extends BaseRepository
} }
} }
$result = $this->_selectOne(['pid' => $pid, 'hostname' => $this->currentHost]); $fields = $this->_selectFirstRowAsArray( ['pid' => $pid, 'hostname' => $this->currentHost]);
$result = $this->factory->createFromTableRow($fields);
$this->db->commit(); $this->db->commit();
@ -74,7 +71,7 @@ class Process extends BaseRepository
} }
} }
public function delete(Entity\Process $process) public function delete(ProcessEntity $process)
{ {
try { try {
if (!$this->db->delete(static::$table_name, [ if (!$this->db->delete(static::$table_name, [