CreateCategoryUseCase::execute()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
rs 9.6666
cc 1
eloc 5
nc 1
nop 1
1
<?php
2
/**
3
 * (c) Tomasz Kunicki <[email protected]>
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
namespace Domain\Category\UseCase\CreateCategory;
9
10
use Domain\Category\CategoryFactoryInterface;
11
use Domain\Category\Repository\CategoryRepositoryInterface;
12
use Domain\CategoryStructure\Structure\Tree\TreeManager;
13
use Domain\Common\UseCase\ResponderAwareInterface;
14
use Domain\Common\UseCase\ResponderAwareTrait;
15
16
/**
17
 * Class CreateCategoryUseCase
18
 *
19
 * @package Domain\Category\UseCase\CreateCategory
20
 */
21
class CreateCategoryUseCase implements ResponderAwareInterface
22
{
23
    use ResponderAwareTrait;
24
25
    /** @var  CategoryRepositoryInterface */
26
    private $categoryRepository;
27
28
    /** @var  CategoryFactoryInterface */
29
    private $categoryFactory;
30
31
    /** @var  TreeManager */
32
    private $treeManager;
33
34
    /**
35
     * CreateCategoryUseCase constructor.
36
     *
37
     * @param CategoryRepositoryInterface $categoryRepository
38
     * @param CategoryFactoryInterface $categoryFactory
39
     * @param TreeManager $treeManager
40
     */
41
    public function __construct(
42
        CategoryRepositoryInterface $categoryRepository,
43
        CategoryFactoryInterface $categoryFactory,
44
        TreeManager $treeManager
45
    ) {
46
        $this->categoryRepository = $categoryRepository;
47
        $this->categoryFactory = $categoryFactory;
48
        $this->treeManager = $treeManager;
49
    }
50
51
    /**
52
     * @param CreateCategoryRequest $request
53
     */
54
    public function execute(CreateCategoryRequest $request)
55
    {
56
        $category = $this->categoryFactory->create($request->getName());
57
58
        $this->categoryRepository->add($category);
59
        $this->treeManager->assignParent($category, $request->getParent());
60
61
        $this->categoryCreated();
62
    }
63
64
    private function categoryCreated()
65
    {
66
        /** @var CreateCategoryResponderInterface $responder */
67
        foreach ($this->responders as $responder) {
68
            $responder->categoryCreated();
0 ignored issues
show
Bug introduced by
The method categoryCreated() does not seem to exist on object<Domain\Common\UseCase\ResponderInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
69
        }
70
    }
71
}