|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the Explicit Architecture POC, |
|
7
|
|
|
* which is created on top of the Symfony Demo application. |
|
8
|
|
|
* |
|
9
|
|
|
* (c) Herberto Graça <[email protected]> |
|
10
|
|
|
* |
|
11
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
12
|
|
|
* file that was distributed with this source code. |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace Acme\App\Core\Component\Blog\Application\Query\DQL; |
|
16
|
|
|
|
|
17
|
|
|
use Acme\App\Core\Component\Blog\Application\Query\FindAuthorIdByCommentIdQueryInterface; |
|
18
|
|
|
use Acme\App\Core\Component\Blog\Domain\Post\Comment\Comment; |
|
19
|
|
|
use Acme\App\Core\Port\Persistence\DQL\DqlQueryBuilderInterface; |
|
20
|
|
|
use Acme\App\Core\Port\Persistence\QueryServiceRouterInterface; |
|
21
|
|
|
use Acme\App\Core\SharedKernel\Component\Blog\Domain\Post\Comment\CommentId; |
|
22
|
|
|
use Acme\App\Core\SharedKernel\Component\User\Domain\User\UserId; |
|
23
|
|
|
|
|
24
|
|
View Code Duplication |
final class FindAuthorIdByCommentIdQuery implements FindAuthorIdByCommentIdQueryInterface |
|
|
|
|
|
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* @var DqlQueryBuilderInterface |
|
28
|
|
|
*/ |
|
29
|
|
|
private $dqlQueryBuilder; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var QueryServiceRouterInterface |
|
33
|
|
|
*/ |
|
34
|
|
|
private $queryService; |
|
35
|
|
|
|
|
36
|
|
|
public function __construct( |
|
37
|
|
|
DqlQueryBuilderInterface $dqlQueryBuilder, |
|
38
|
|
|
QueryServiceRouterInterface $queryService |
|
39
|
|
|
) { |
|
40
|
|
|
$this->dqlQueryBuilder = $dqlQueryBuilder; |
|
41
|
|
|
$this->queryService = $queryService; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function execute(CommentId $commentId): UserId |
|
45
|
|
|
{ |
|
46
|
|
|
$dqlQuery = $this->dqlQueryBuilder->create(Comment::class) |
|
47
|
|
|
->select('Comment.authorId') |
|
48
|
|
|
->where('Comment.id = :commentId') |
|
49
|
|
|
->setParameter('commentId', $commentId) |
|
50
|
|
|
->build(); |
|
51
|
|
|
|
|
52
|
|
|
return $this->queryService->query($dqlQuery)->getSingleResult()['authorId']; |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.