Completed
Push — master ( 4bfbe0...b20dd8 )
by Beñat
02:43
created

CountFilesHandler   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A __invoke() 0 8 1
1
<?php
2
3
/*
4
 * This file is part of the BenGorFile 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
namespace BenGorFile\File\Application\Query;
14
15
use BenGorFile\File\Domain\Model\FileRepository;
16
use BenGorFile\File\Domain\Model\FileSpecificationFactory;
17
18
/**
19
 * Counts files with the given query.
20
 *
21
 * @author Beñat Espiña <[email protected]>
22
 */
23
class CountFilesHandler
24
{
25
    /**
26
     * The file repository.
27
     *
28
     * @var FileRepository
29
     */
30
    private $repository;
31
32
    /**
33
     * The file specification factory.
34
     *
35
     * @var FileSpecificationFactory
36
     */
37
    private $specificationFactory;
38
39
    /**
40
     * Constructor.
41
     *
42
     * @param FileRepository           $aRepository              The file repository
43
     * @param FileSpecificationFactory $fileSpecificationFactory The file specification factory
44
     */
45
    public function __construct(FileRepository $aRepository, FileSpecificationFactory $fileSpecificationFactory)
46
    {
47
        $this->repository = $aRepository;
48
        $this->specificationFactory = $fileSpecificationFactory;
49
    }
50
51
    /**
52
     * Handles the given query.
53
     *
54
     * @param CountFilesQuery $aQuery The query
55
     *
56
     * @return mixed
57
     */
58
    public function __invoke(CountFilesQuery $aQuery)
59
    {
60
        return $this->repository->count(
61
            $this->specificationFactory->buildFilterByNameSpecification(
62
                $aQuery->query()
63
            )
64
        );
65
    }
66
}
67