Code Duplication    Length = 66-66 lines in 2 locations

src/BenGorFile/File/Application/Query/FilterFilesHandler.php 1 location

@@ 25-90 (lines=66) @@
22
 *
23
 * @author Beñat Espiña <[email protected]>
24
 */
25
class FilterFilesHandler
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
     * The file specification factory.
43
     *
44
     * @var FileSpecificationFactory
45
     */
46
    private $specificationFactory;
47
48
    /**
49
     * Constructor.
50
     *
51
     * @param FileRepository           $aRepository              The file repository
52
     * @param FileSpecificationFactory $fileSpecificationFactory The file specification factory
53
     * @param FileDataTransformer      $aDataTransformer         The file data transformer
54
     */
55
    public function __construct(
56
        FileRepository $aRepository,
57
        FileSpecificationFactory $fileSpecificationFactory,
58
        FileDataTransformer $aDataTransformer
59
    ) {
60
        $this->repository = $aRepository;
61
        $this->specificationFactory = $fileSpecificationFactory;
62
        $this->dataTransformer = $aDataTransformer;
63
    }
64
65
    /**
66
     * Handles the given query.
67
     *
68
     * @param FilterFilesQuery $aQuery The query
69
     *
70
     * @return mixed
71
     */
72
    public function __invoke(FilterFilesQuery $aQuery)
73
    {
74
        $offset = $aQuery->limit() * ($aQuery->page() - 1);
75
76
        $files = $this->repository->query(
77
            $this->specificationFactory->buildFilterByNameSpecification(
78
                $aQuery->query(),
79
                $offset,
80
                $aQuery->limit()
81
            )
82
        );
83
84
        return array_map(function (File $file) {
85
            $this->dataTransformer->write($file);
86
87
            return $this->dataTransformer->read();
88
        }, $files);
89
    }
90
}
91

src/BenGorFile/File/Application/Query/ListFilesOfIdsHandler.php 1 location

@@ 23-88 (lines=66) @@
20
/**
21
 * @author Beñat Espiña <[email protected]>
22
 */
23
class ListFilesOfIdsHandler
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