Completed
Push — master ( 9b1ada...794d27 )
by Beñat
03:51
created

MenuOfIdHandler::sortByOrder()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 8
rs 9.4285
c 1
b 0
f 0
cc 3
eloc 4
nc 3
nop 2
1
<?php
2
3
/*
4
 * This file is part of the CMS Kernel package.
5
 *
6
 * Copyright (c) 2016-present LIN3S <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace LIN3S\CMSKernel\Application\Query\Menu;
13
14
use LIN3S\CMSKernel\Application\DataTransformer\Translation\TranslatableDataTransformer;
15
use LIN3S\CMSKernel\Domain\Model\Menu\Menu;
16
use LIN3S\CMSKernel\Domain\Model\Menu\MenuDoesNotExistException;
17
use LIN3S\CMSKernel\Domain\Model\Menu\MenuId;
18
use LIN3S\CMSKernel\Domain\Model\Menu\MenuRepository;
19
use LIN3S\CMSKernel\Domain\Model\Translation\Locale;
20
21
/**
22
 * @author Beñat Espiña <[email protected]>
23
 */
24 View Code Duplication
class MenuOfIdHandler
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...
25
{
26
    private $repository;
27
    private $dataTransformer;
28
29
    public function __construct(MenuRepository $repository, TranslatableDataTransformer $dataTransformer)
30
    {
31
        $this->repository = $repository;
32
        $this->dataTransformer = $dataTransformer;
33
    }
34
35
    public function __invoke(MenuOfIdQuery $query)
36
    {
37
        $locale = new Locale($query->locale());
38
        $menu = $this->repository->menuOfId(
39
            MenuId::generate(
40
                $query->menuId()
41
            )
42
        );
43
        if (!$menu instanceof Menu) {
44
            throw new MenuDoesNotExistException();
45
        }
46
47
        $this->dataTransformer->write($menu, $locale);
48
49
        return $this->dataTransformer->read();
50
    }
51
}
52