Completed
Push — master ( adef2f...37f76d )
by Beñat
01:35
created

ListFilesOfIdsHandler   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 66
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 4
dl 66
loc 66
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 9 9 1
A __invoke() 18 18 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\File;
17
use BenGorFile\File\Domain\Model\FileRepository;
18
use BenGorFile\File\Domain\Model\FileSpecificationFactory;
19
20
/**
21
 * @author Beñat Espiña <[email protected]>
22
 */
23 View Code Duplication
class ListFilesOfIdsHandler
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...
24
{
25
    /**
26
     * The file data transformer.
27
     *
28
     * @var FileDataTransformer
29
     */
30
    private $dataTransformer;
31
32
    /**
33
     * The file repository.
34
     *
35
     * @var FileRepository
36
     */
37
    private $repository;
38
39
    /**
40
     * The file specification factory.
41
     *
42
     * @var FileSpecificationFactory
43
     */
44
    private $specificationFactory;
45
46
    /**
47
     * Constructor.
48
     *
49
     * @param FileRepository           $aRepository              The file repository
50
     * @param FileSpecificationFactory $fileSpecificationFactory The file specification factory
51
     * @param FileDataTransformer      $aDataTransformer         The file data transformer
52
     */
53
    public function __construct(
54
        FileRepository $aRepository,
55
        FileSpecificationFactory $fileSpecificationFactory,
56
        FileDataTransformer $aDataTransformer
57
    ) {
58
        $this->repository = $aRepository;
59
        $this->specificationFactory = $fileSpecificationFactory;
60
        $this->dataTransformer = $aDataTransformer;
61
    }
62
63
    /**
64
     * Handles the given query.
65
     *
66
     * @param ListFilesOfIdsQuery $aQuery The query
67
     *
68
     * @return mixed
69
     */
70
    public function __invoke(ListFilesOfIdsQuery $aQuery)
71
    {
72
        $offset = $aQuery->limit() * ($aQuery->page() - 1);
73
74
        $files = $this->repository->query(
75
            $this->specificationFactory->buildListOfIdsSpecification(
76
                $aQuery->ids(),
77
                $offset,
78
                $aQuery->limit()
79
            )
80
        );
81
82
        return array_map(function (File $file) {
83
            $this->dataTransformer->write($file);
84
85
            return $this->dataTransformer->read();
86
        }, $files);
87
    }
88
}
89