Skip to content

Commit

Permalink
* excluding BaseRepository from symfony autowire as `ServiceEntityR…
Browse files Browse the repository at this point in the history
…epositoryProxy->__construct()` require param `string $entityClass` that was set by its derived repository classes

* fix the returned type of `getForum()` should be partial projected DTO array @ `ForumRepository`
@ `App\Repository`

* prefer static closure for microbenchmark: laravel/framework#33126
$ ./vendor/bin/pint
@ be
  • Loading branch information
n0099 committed Oct 11, 2024
1 parent 63881f6 commit 7ef020e
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion be/bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if (!is_file(dirname(__DIR__).'/vendor/autoload_runtime.php')) {

require_once dirname(__DIR__).'/vendor/autoload_runtime.php';

return function (array $context) {
return static function (array $context) {
$kernel = new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);

return new Application($kernel);
Expand Down
2 changes: 1 addition & 1 deletion be/public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

require_once dirname(__DIR__) . '/vendor/autoload_runtime.php';

return function (array $context) {
return static function (array $context) {
return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
};
2 changes: 2 additions & 0 deletions be/src/Repository/BaseRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\ORM\AbstractQuery;
use Doctrine\ORM\Query;
use Symfony\Component\DependencyInjection\Attribute\Exclude;

/**
* @template T
* @extends ServiceEntityRepository<T>
*/
#[Exclude]
class BaseRepository extends ServiceEntityRepository
{
protected function createQuery(string $dql): Query
Expand Down
2 changes: 1 addition & 1 deletion be/src/Repository/ForumRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function isForumExists(int $fid): bool
return $this->isEntityExists($dql, 'fid', $fid);
}

public function getForum(int $fid): Forum
public function getForum(int $fid): array
{
$dql = 'SELECT t.fid, t.name FROM App\Entity\Forum t WHERE t.fid = :fid';
return $this->createQueryWithSingleParam($dql, 'fid', $fid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected function getTableNameSuffix(): string
{
return 'subReply_content';
}

public function getPostsContent(\ArrayAccess $postsId): array
{
$dql = 'SELECT t FROM App\Entity\Post\Content\SubReplyContent t WHERE t.spid IN (:spid)';
Expand Down
4 changes: 2 additions & 2 deletions be/src/Repository/Post/ReplyRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ protected function getTableNameSuffix(): string
{
return 'reply';
}

public function getPosts(\ArrayAccess $postsId): array
{
$dql = 'SELECT t FROM App\Entity\Post\Reply t WHERE t.pid IN (:pid)';
return $this->getQueryResultWithSingleParam($dql, 'pid', $postsId);
}

public function isPostExists(int $postId): bool
{
$dql = 'SELECT 1 FROM App\Entity\Post\Reply t WHERE t.pid = :pid';
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 @@ -20,7 +20,7 @@ protected function getTableNameSuffix(): string
{
return 'subReply';
}

public function getPosts(\ArrayAccess $postsId): array
{
$dql = 'SELECT t FROM App\Entity\Post\SubReply t WHERE t.spid IN (:spid)';
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 @@ -12,7 +12,7 @@ public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, User::class);
}

public function getUsers(\ArrayAccess $usersId): array
{
$dql = 'SELECT t FROM App\Entity\User t WHERE t.uid IN (:usersId)';
Expand Down
2 changes: 1 addition & 1 deletion be/src/Validator/DateTimeRangeValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function validate(mixed $value, Constraint $constraint): void
return;
}

$values = array_map(fn(string $value) => new \DateTimeImmutable($value), explode(',', $value));
$values = array_map(static fn(string $value) => new \DateTimeImmutable($value), explode(',', $value));
$errors = $this->context->getValidator()->validate($values, new Assert\Count(2));
$errors->addAll($this->context->getValidator()->validate(
$values[0],
Expand Down

0 comments on commit 7ef020e

Please sign in to comment.