RemoveMenuTranslationHandler::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
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\Command\Menu;
13
14
use LIN3S\CMSKernel\Domain\Model\Menu\Menu;
15
use LIN3S\CMSKernel\Domain\Model\Menu\MenuDoesNotExistException;
16
use LIN3S\CMSKernel\Domain\Model\Menu\MenuId;
17
use LIN3S\CMSKernel\Domain\Model\Menu\MenuRepository;
18
use LIN3S\CMSKernel\Domain\Model\Translation\Locale;
19
20
/**
21
 * @author Beñat Espiña <[email protected]>
22
 */
23
class RemoveMenuTranslationHandler
24
{
25
    private $repository;
26
27
    public function __construct(MenuRepository $repository)
28
    {
29
        $this->repository = $repository;
30
    }
31
32
    public function __invoke(RemoveMenuTranslationCommand $command)
33
    {
34
        $menu = $this->repository->menuOfId(
35
            MenuId::generate(
36
                $command->menuId()
37
            )
38
        );
39
        if (!$menu instanceof Menu) {
40
            throw new MenuDoesNotExistException();
41
        }
42
43
        $menu->removeTranslation(
44
            new Locale(
45
                $command->locale()
46
            )
47
        );
48
        $this->repository->persist($menu);
49
    }
50
}
51