PostListQuery   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A execute() 0 15 1
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\PostListQueryInterface;
18
use Acme\App\Core\Component\Blog\Domain\Post\Post;
19
use Acme\App\Core\Port\Persistence\DQL\DqlQueryBuilderInterface;
20
use Acme\App\Core\Port\Persistence\QueryServiceInterface;
21
use Acme\App\Core\Port\Persistence\QueryServiceRouterInterface;
22
use Acme\App\Core\Port\Persistence\ResultCollectionInterface;
23
use Acme\App\Core\SharedKernel\Component\User\Domain\User\UserId;
24
25
final class PostListQuery implements PostListQueryInterface
26
{
27
    /**
28
     * @var DqlQueryBuilderInterface
29
     */
30
    private $dqlQueryBuilder;
31
32
    /**
33
     * @var QueryServiceInterface
34
     */
35
    private $queryService;
36
37
    public function __construct(
38
        DqlQueryBuilderInterface $dqlQueryBuilder,
39
        QueryServiceRouterInterface $queryService
40
    ) {
41
        $this->dqlQueryBuilder = $dqlQueryBuilder;
42
        $this->queryService = $queryService;
0 ignored issues
show
Documentation Bug introduced by
It seems like $queryService of type object<Acme\App\Core\Por...ServiceRouterInterface> is incompatible with the declared type object<Acme\App\Core\Por...\QueryServiceInterface> of property $queryService.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
43
    }
44
45
    /**
46
     * Since this class only has one public method, it makes sense that it is designed as a callable, using the
47
     * magic method name `__invoke()`, instead of having a single public method called `execute()` which adds nothing
48
     * to code readability.
49
     * However, by using `__invoke()` we lose code completion, so in the end I prefer to use this `execute()` method.
50
     */
51
    public function execute(UserId $userId): ResultCollectionInterface
52
    {
53
        $dqlQuery = $this->dqlQueryBuilder->create(Post::class, 'Post')
54
            ->select(
55
                'Post.id',
56
                'Post.title',
57
                'Post.publishedAt'
58
            )
59
            ->where('Post.authorId = :authorId')
60
            ->orderBy('Post.publishedAt', 'DESC')
61
            ->setParameter('authorId', $userId)
62
            ->build();
63
64
        return $this->queryService->query($dqlQuery);
0 ignored issues
show
Bug introduced by
The method query() does not seem to exist on object<Acme\App\Core\Por...\QueryServiceInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
65
    }
66
}
67