CreateCategoryHandler   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 19
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 7 1
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Application\Command\Category\Create;
6
7
use App\Domain\Category\Category;
8
use App\Domain\Category\CategoryStore;
9
use App\Domain\Common\ValueObject\AggregateRootId;
10
use App\Domain\Common\ValueObject\Name;
11
use App\Infrastructure\Common\CommandHandler\CommandHandlerInterface;
12
13
class CreateCategoryHandler implements CommandHandlerInterface
14
{
15
    /**
16
     * @var CategoryStore
17
     */
18
    private $categoryStoreRepository;
19
20
    public function __construct(CategoryStore $categoryStoreRepository)
21
    {
22
        $this->categoryStoreRepository = $categoryStoreRepository;
23
    }
24
25
    public function __invoke(CreateCategoryCommand $command): void
26
    {
27
        $category = Category::create(
28
            AggregateRootId::generate(),
29
            Name::fromString($command->getName())
30
        );
31
        $this->categoryStoreRepository->save($category);
32
    }
33
}
34