Completed
Pull Request — master (#142)
by Beñat
02:52
created

EditOrganizationHandler   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 6
dl 0
loc 30
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 20 3
1
<?php
2
3
/*
4
 * This file is part of the Kreta 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
declare(strict_types=1);
14
15
namespace Kreta\TaskManager\Application\Organization;
16
17
use Kreta\SharedKernel\Domain\Model\Identity\Slug;
18
use Kreta\TaskManager\Domain\Model\Organization\OrganizationDoesNotExistException;
19
use Kreta\TaskManager\Domain\Model\Organization\OrganizationId;
20
use Kreta\TaskManager\Domain\Model\Organization\OrganizationName;
21
use Kreta\TaskManager\Domain\Model\Organization\OrganizationRepository;
22
23
class EditOrganizationHandler
24
{
25
    private $repository;
26
27
    public function __construct(OrganizationRepository $repository)
28
    {
29
        $this->repository = $repository;
30
    }
31
32
    public function __invoke(EditOrganizationCommand $command)
33
    {
34
        $organization = $this->repository->organizationOfId(
35
            OrganizationId::generate(
36
                $command->id()
37
            )
38
        );
39
        if (null === $organization) {
40
            throw new OrganizationDoesNotExistException();
41
        }
42
        $organization->edit(
43
            new OrganizationName(
44
                $command->name()
45
            ),
46
            new Slug(
47
                null === $command->slug() ? $command->name() : $command->slug()
48
            )
49
        );
50
        $this->repository->persist($organization);
51
    }
52
}
53