Skip to content

Commit

Permalink
* add union type array for all usages to type ArrayAccess @ be
Browse files Browse the repository at this point in the history
  • Loading branch information
n0099 committed Oct 11, 2024
1 parent 7425b88 commit 24c92db
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 20 deletions.
8 changes: 4 additions & 4 deletions be/src/PostsQuery/BaseQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,17 +178,17 @@ static function (string $postIDName) use ($result): array {
$parentThreadsID = $replies->pluck('tid')->concat($subReplies->pluck('tid'))->unique();
/** @var Collection<int, Thread> $threads */
$threads = collect($postModels['thread']->getPosts($parentThreadsID->concat($tids)))
->each(static fn(Thread $thread) =>
$thread->setIsMatchQuery($tids->contains($thread->getTid())));
->each(static fn(Thread $thread) =>
$thread->setIsMatchQuery($tids->contains($thread->getTid())));
$this->stopwatch->stop('fillWithThreadsFields');

$this->stopwatch->start('fillWithRepliesFields');
/** @var Collection<int, int> $parentRepliesID parent pid of all sub replies */
$parentRepliesID = $subReplies->pluck('pid')->unique();
$allRepliesId = $parentRepliesID->concat($pids);
$replies = collect($postModels['reply']->getPosts($allRepliesId))
->each(static fn(Reply $reply) =>
$reply->setIsMatchQuery($pids->contains($reply->getPid())));
->each(static fn(Reply $reply) =>
$reply->setIsMatchQuery($pids->contains($reply->getPid())));
$this->stopwatch->stop('fillWithRepliesFields');

$this->stopwatch->start('fillWithSubRepliesFields');
Expand Down
16 changes: 11 additions & 5 deletions be/src/Repository/BaseRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,23 @@ protected function createQuery(string $dql): Query
return $this->getEntityManager()->createQuery($dql);
}

protected function createQueryWithSingleParam(string $dql, string $paramName, int|\ArrayAccess $paramValue): Query
{
protected function createQueryWithSingleParam(
string $dql,
string $paramName,
int|array|\ArrayAccess $paramValue,
): Query {
return $this->createQuery($dql)->setParameter($paramName, $paramValue);
}

protected function getQueryResultWithSingleParam(string $dql, string $paramName, int|\ArrayAccess $paramValue): array
{
protected function getQueryResultWithSingleParam(
string $dql,
string $paramName,
int|array|\ArrayAccess $paramValue,
): array {
return $this->createQueryWithSingleParam($dql, $paramName, $paramValue)->getResult();
}

protected function isEntityExists(string $dql, string $paramName, int|\ArrayAccess $paramValue): bool
protected function isEntityExists(string $dql, string $paramName, int|array|\ArrayAccess $paramValue): bool
{
return $this->createQueryWithSingleParam($dql, $paramName, $paramValue)
->getOneOrNullResult(AbstractQuery::HYDRATE_SINGLE_SCALAR) === 1;
Expand Down
2 changes: 1 addition & 1 deletion be/src/Repository/LatestReplierRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function __construct(ManagerRegistry $registry)
parent::__construct($registry, LatestReplier::class);
}

public function getLatestRepliersWithoutNameWhenHasUid(\ArrayAccess $latestRepliersId): Collection
public function getLatestRepliersWithoutNameWhenHasUid(array|\ArrayAccess $latestRepliersId): Collection
{
// removeSelect('t.name', 't.displayName')
return collect($this->getQueryResultWithSingleParam(<<<'DQL'
Expand Down
2 changes: 1 addition & 1 deletion be/src/Repository/Post/Content/PostContentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
*/
abstract class PostContentRepository extends RepositoryWithSplitFid
{
abstract public function getPostsContent(\ArrayAccess $postsId): array;
abstract public function getPostsContent(array|\ArrayAccess $postsId): array;
}
2 changes: 1 addition & 1 deletion be/src/Repository/Post/Content/ReplyContentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected function getTableNameSuffix(): string
return 'reply_content';
}

public function getPostsContent(\ArrayAccess $postsId): array
public function getPostsContent(array|\ArrayAccess $postsId): array
{
$dql = 'SELECT t FROM App\Entity\Post\Content\ReplyContent t WHERE t.pid IN (:pid)';
return $this->getQueryResultWithSingleParam($dql, 'pid', $postsId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected function getTableNameSuffix(): string
return 'subReply_content';
}

public function getPostsContent(\ArrayAccess $postsId): array
public function getPostsContent(array|\ArrayAccess $postsId): array
{
$dql = 'SELECT t FROM App\Entity\Post\Content\SubReplyContent t WHERE t.spid IN (:spid)';
return $this->getQueryResultWithSingleParam($dql, 'spid', $postsId);
Expand Down
2 changes: 1 addition & 1 deletion be/src/Repository/Post/PostRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function selectCurrentAndParentPostID(): QueryBuilder
->all());
}

abstract public function getPosts(\ArrayAccess $postsId): array;
abstract public function getPosts(array|\ArrayAccess $postsId): array;

abstract public function isPostExists(int $postId): bool;
}
2 changes: 1 addition & 1 deletion be/src/Repository/Post/ReplyRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected function getTableNameSuffix(): string
return 'reply';
}

public function getPosts(\ArrayAccess $postsId): array
public function getPosts(array|\ArrayAccess $postsId): array
{
$dql = 'SELECT t FROM App\Entity\Post\Reply t WHERE t.pid IN (:pid)';
return $this->getQueryResultWithSingleParam($dql, 'pid', $postsId);
Expand Down
2 changes: 1 addition & 1 deletion be/src/Repository/Post/SubReplyRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected function getTableNameSuffix(): string
return 'subReply';
}

public function getPosts(\ArrayAccess $postsId): array
public function getPosts(array|\ArrayAccess $postsId): array
{
$dql = 'SELECT t FROM App\Entity\Post\SubReply t WHERE t.spid IN (:spid)';
return $this->getQueryResultWithSingleParam($dql, 'spid', $postsId);
Expand Down
2 changes: 1 addition & 1 deletion be/src/Repository/Post/ThreadRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected function getTableNameSuffix(): string
return 'thread';
}

public function getPosts(\ArrayAccess $postsId): array
public function getPosts(array|\ArrayAccess $postsId): array
{
$dql = 'SELECT t FROM App\Entity\Post\Thread t WHERE t.tid IN (:tid)';
return $this->getQueryResultWithSingleParam($dql, 'tid', $postsId);
Expand Down
2 changes: 1 addition & 1 deletion be/src/Repository/Revision/AuthorExpGradeRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function __construct(ManagerRegistry $registry)
parent::__construct($registry, AuthorExpGrade::class);
}

public function getLatestOfUsers(int $fid, \ArrayAccess $usersId)
public function getLatestOfUsers(int $fid, array|\ArrayAccess $usersId)
{
$entityManager = $this->getEntityManager();
$tableName = $entityManager->getClassMetadata(AuthorExpGrade::class)->getTableName();
Expand Down
2 changes: 1 addition & 1 deletion be/src/Repository/Revision/ForumModeratorRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function __construct(ManagerRegistry $registry)
parent::__construct($registry, ForumModerator::class);
}

public function getLatestOfUsers(int $fid, \ArrayAccess $portraits)
public function getLatestOfUsers(int $fid, array|\ArrayAccess $portraits)
{
$entityManager = $this->getEntityManager();
$tableName = $entityManager->getClassMetadata(ForumModerator::class)->getTableName();
Expand Down
2 changes: 1 addition & 1 deletion be/src/Repository/UserRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function __construct(ManagerRegistry $registry)
parent::__construct($registry, User::class);
}

public function getUsers(\ArrayAccess $usersId): array
public function getUsers(array|\ArrayAccess $usersId): array
{
$dql = 'SELECT t FROM App\Entity\User t WHERE t.uid IN (:usersId)';
return $this->getQueryResultWithSingleParam($dql, 'usersId', $usersId);
Expand Down

0 comments on commit 24c92db

Please sign in to comment.