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\Material\UseCase\CreateMaterial; |
9
|
|
|
|
10
|
|
|
use Domain\Category\Entity\CategoryInterface; |
11
|
|
|
use Domain\Common\UseCase\ResponderAwareInterface; |
12
|
|
|
use Domain\Common\UseCase\ResponderAwareTrait; |
13
|
|
|
use Domain\Material\MaterialFactoryInterface; |
14
|
|
|
use Domain\Material\Repository\MaterialRepositoryInterface; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class CreateMaterialUseCase |
18
|
|
|
* |
19
|
|
|
* @package Domain\Material\UseCase\CreateMaterial |
20
|
|
|
*/ |
21
|
|
|
class CreateMaterialUseCase implements ResponderAwareInterface |
22
|
|
|
{ |
23
|
|
|
use ResponderAwareTrait; |
24
|
|
|
|
25
|
|
|
/** @var MaterialRepositoryInterface */ |
26
|
|
|
private $materialRepository; |
27
|
|
|
|
28
|
|
|
/** @var MaterialFactoryInterface */ |
29
|
|
|
private $materialFactory; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* CreateMaterialUseCase constructor. |
33
|
|
|
* |
34
|
|
|
* @param MaterialRepositoryInterface $materialRepository |
35
|
|
|
* @param MaterialFactoryInterface $materialFactory |
36
|
|
|
*/ |
37
|
|
|
public function __construct( |
38
|
|
|
MaterialRepositoryInterface $materialRepository, |
39
|
|
|
MaterialFactoryInterface $materialFactory |
40
|
|
|
) { |
41
|
|
|
$this->materialRepository = $materialRepository; |
42
|
|
|
$this->materialFactory = $materialFactory; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param CreateMaterialRequest $request |
47
|
|
|
*/ |
48
|
|
|
public function execute(CreateMaterialRequest $request) |
49
|
|
|
{ |
50
|
|
|
$category = $request->getCategory(); |
51
|
|
|
if (count($category->getChildren())) { |
|
|
|
|
52
|
|
|
$this->callWarningLimitationAssignOnlyToLeaf($category); |
53
|
|
|
|
54
|
|
|
return; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
$material = $this->materialFactory->create( |
58
|
|
|
$request->getName(), |
59
|
|
|
$request->getCode(), |
60
|
|
|
$request->getCategory(), |
61
|
|
|
$request->getUnit() |
62
|
|
|
); |
63
|
|
|
$this->materialRepository->add($material); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param CategoryInterface $category |
68
|
|
|
*/ |
69
|
|
|
private function callWarningLimitationAssignOnlyToLeaf(CategoryInterface $category) |
70
|
|
|
{ |
71
|
|
|
/** @var CreateMaterialResponderInterface $responder */ |
72
|
|
|
foreach ($this->responders as $responder) { |
73
|
|
|
$responder->callWarningLimitationAssignOnlyToLeaf($category); |
|
|
|
|
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
} |
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.