FileOfIdHandler   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 5
dl 0
loc 50
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A __invoke() 0 12 2
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\Application\DataTransformer\FileDataTransformer;
16
use BenGorFile\File\Domain\Model\FileDoesNotExistException;
17
use BenGorFile\File\Domain\Model\FileId;
18
use BenGorFile\File\Domain\Model\FileRepository;
19
20
/**
21
 * File of id query handler.
22
 *
23
 * @author Beñat Espiña <[email protected]>
24
 */
25
class FileOfIdHandler
26
{
27
    /**
28
     * The file data transformer.
29
     *
30
     * @var FileDataTransformer
31
     */
32
    private $dataTransformer;
33
34
    /**
35
     * The file repository.
36
     *
37
     * @var FileRepository
38
     */
39
    private $repository;
40
41
    /**
42
     * Constructor.
43
     *
44
     * @param FileRepository      $aRepository      The file repository
45
     * @param FileDataTransformer $aDataTransformer The file data transformer
46
     */
47
    public function __construct(FileRepository $aRepository, FileDataTransformer $aDataTransformer)
48
    {
49
        $this->repository = $aRepository;
50
        $this->dataTransformer = $aDataTransformer;
51
    }
52
53
    /**
54
     * Handles the given query.
55
     *
56
     * @param FileOfIdQuery $aQuery The query
57
     *
58
     * @throws FileDoesNotExistException when the file id does not exist
59
     *
60
     * @return mixed
61
     */
62
    public function __invoke(FileOfIdQuery $aQuery)
63
    {
64
        $fileId = new FileId($aQuery->id());
65
        $file = $this->repository->fileOfId($fileId);
66
        if (null === $file) {
67
            throw new FileDoesNotExistException();
68
        }
69
70
        $this->dataTransformer->write($file);
71
72
        return $this->dataTransformer->read();
73
    }
74
}
75