Completed
Push — master ( f7103c...fb6e23 )
by Beñat
12s
created

CountProjectsHandler   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 6
dl 0
loc 26
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A __invoke() 0 12 3
1
<?php
2
3
/*
4
 * This file is part of the Kreta package.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
7
 * (c) Gorka Laucirica <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
declare(strict_types=1);
14
15
namespace Kreta\TaskManager\Application\Query\Project;
16
17
use Kreta\TaskManager\Domain\Model\Organization\OrganizationId;
18
use Kreta\TaskManager\Domain\Model\Project\ProjectName;
19
use Kreta\TaskManager\Domain\Model\Project\ProjectRepository;
20
use Kreta\TaskManager\Domain\Model\Project\ProjectSpecificationFactory;
21
use Kreta\TaskManager\Domain\Model\User\UserId;
22
23
class CountProjectsHandler
24
{
25
    private $repository;
26
    private $specificationFactory;
27
28
    public function __construct(
29
        ProjectRepository $repository,
30
        ProjectSpecificationFactory $specificationFactory
31
    ) {
32
        $this->repository = $repository;
33
        $this->specificationFactory = $specificationFactory;
34
    }
35
36
    public function __invoke(CountProjectsQuery $query)
37
    {
38
        return $this->repository->count(
39
            $this->specificationFactory->buildFilterableSpecification(
40
                UserId::generate(
41
                    $query->userId()
42
                ),
43
                null === $query->organizationId() ? null : OrganizationId::generate($query->organizationId()),
44
                null === $query->name() ? null : new ProjectName($query->name())
45
            )
46
        );
47
    }
48
}
49