Completed
Pull Request — master (#5)
by Beñat
03:29
created

FileOfNameHandler::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 12
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 12
loc 12
rs 9.4285
cc 2
eloc 7
nc 2
nop 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\Application\DataTransformer\FileDataTransformer;
16
use BenGorFile\File\Domain\Model\FileException;
17
use BenGorFile\File\Domain\Model\FileName;
18
use BenGorFile\File\Domain\Model\FileRepository;
19
20
/**
21
 * File of name query handler.
22
 *
23
 * @author Beñat Espiña <[email protected]>
24
 */
25 View Code Duplication
class FileOfNameHandler
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...
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 FileOfNameQuery $aQuery The query
57
     *
58
     * @throws FileException when the file name does not exist
59
     *
60
     * @return mixed
61
     */
62
    public function __invoke(FileOfNameQuery $aQuery)
63
    {
64
        $fileName = new FileName($aQuery->name());
65
        $file = $this->repository->fileOfName($fileName);
66
        if (null === $file) {
67
            throw FileException::doesNotExist($fileName);
68
        }
69
70
        $this->dataTransformer->write($file);
71
72
        return $this->dataTransformer->read();
73
    }
74
}
75