Test Setup Failed
Push — graphql_api ( 4ff753 )
by Herberto
07:48 queued 01:35
created

FindAuthorIdByPostIdQuery   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 3
dl 31
loc 31
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 7 7 1
A execute() 10 10 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\FindAuthorIdByPostIdQueryInterface;
18
use Acme\App\Core\Component\Blog\Domain\Post\Post;
19
use Acme\App\Core\Component\Blog\Domain\Post\PostId;
20
use Acme\App\Core\Port\Persistence\DQL\DqlQueryBuilderInterface;
21
use Acme\App\Core\Port\Persistence\QueryServiceRouterInterface;
22
use Acme\App\Core\SharedKernel\Component\User\Domain\User\UserId;
23
24 View Code Duplication
final class FindAuthorIdByPostIdQuery implements FindAuthorIdByPostIdQueryInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

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.

Loading history...
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(PostId $postId): UserId
45
    {
46
        $dqlQuery = $this->dqlQueryBuilder->create(Post::class)
47
            ->select('Post.authorId')
48
            ->where('Post.id = :postId')
49
            ->setParameter('postId', $postId)
50
            ->build();
51
52
        return $this->queryService->query($dqlQuery)->getSingleResult()['authorId'];
53
    }
54
}
55