FileOfNameHandler::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 16
rs 9.4285
c 1
b 0
f 0
cc 2
eloc 9
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\FileDoesNotExistException;
17
use BenGorFile\File\Domain\Model\FileName;
18
use BenGorFile\File\Domain\Model\FileRepository;
19
use BenGorFile\File\Domain\Model\FileSpecificationFactory;
20
21
/**
22
 * File of name query handler.
23
 *
24
 * @author Beñat Espiña <[email protected]>
25
 */
26
class FileOfNameHandler
27
{
28
    /**
29
     * The file data transformer.
30
     *
31
     * @var FileDataTransformer
32
     */
33
    private $dataTransformer;
34
35
    /**
36
     * The file specification factory.
37
     *
38
     * @var FileSpecificationFactory
39
     */
40
    private $specificationFactory;
41
42
    /**
43
     * The file repository.
44
     *
45
     * @var FileRepository
46
     */
47
    private $repository;
48
49
    /**
50
     * Constructor.
51
     *
52
     * @param FileRepository           $aRepository           The file repository
53
     * @param FileSpecificationFactory $aSpecificationFactory The file specification factory
0 ignored issues
show
Documentation introduced by
There is no parameter named $aSpecificationFactory. Did you maybe mean $specificationFactory?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
54
     * @param FileDataTransformer      $aDataTransformer      The file data transformer
55
     */
56
    public function __construct(
57
        FileRepository $aRepository,
58
        FileSpecificationFactory $specificationFactory,
59
        FileDataTransformer $aDataTransformer
60
    ) {
61
        $this->repository = $aRepository;
62
        $this->dataTransformer = $aDataTransformer;
63
        $this->specificationFactory = $specificationFactory;
64
    }
65
66
    /**
67
     * Handles the given query.
68
     *
69
     * @param FileOfNameQuery $aQuery The query
70
     *
71
     * @throws FileDoesNotExistException when the file name does not exist
72
     *
73
     * @return mixed
74
     */
75
    public function __invoke(FileOfNameQuery $aQuery)
76
    {
77
        $fileName = new FileName($aQuery->name());
78
        $file = $this->repository->singleResultQuery(
79
            $this->specificationFactory->buildByNameSpecification(
80
                $fileName
81
            )
82
        );
83
        if (null === $file) {
84
            throw new FileDoesNotExistException();
85
        }
86
87
        $this->dataTransformer->write($file);
88
89
        return $this->dataTransformer->read();
90
    }
91
}
92