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\EditMaterial; |
9
|
|
|
|
10
|
|
|
use Domain\Category\Entity\CategoryInterface; |
11
|
|
|
use Domain\Common\UseCase\ResponderAwareTrait; |
12
|
|
|
use Domain\Common\UseCase\ResponderInterface; |
13
|
|
|
use Domain\Material\Repository\MaterialRepositoryInterface; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class EditMaterialUseCase |
17
|
|
|
* |
18
|
|
|
* @package Domain\Material\UseCase\EditMaterial |
19
|
|
|
*/ |
20
|
|
|
class EditMaterialUseCase implements ResponderInterface |
21
|
|
|
{ |
22
|
|
|
use ResponderAwareTrait; |
23
|
|
|
|
24
|
|
|
/** @var MaterialRepositoryInterface */ |
25
|
|
|
private $materialRepository; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* EditMaterialUseCase constructor. |
29
|
|
|
* |
30
|
|
|
* @param MaterialRepositoryInterface $materialRepository |
31
|
|
|
*/ |
32
|
|
|
public function __construct(MaterialRepositoryInterface $materialRepository) |
33
|
|
|
{ |
34
|
|
|
$this->materialRepository = $materialRepository; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param EditMaterialRequest $request |
39
|
|
|
*/ |
40
|
|
|
public function execute(EditMaterialRequest $request) |
41
|
|
|
{ |
42
|
|
|
$material = $this->materialRepository->findById($request->getMaterialId()); |
43
|
|
|
|
44
|
|
|
$category = $request->getCategory(); |
45
|
|
|
if (count($category->getChildren())) { |
|
|
|
|
46
|
|
|
$this->callWarningLimitationAssignOnlyToLeaf($category); |
47
|
|
|
|
48
|
|
|
return; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
$material->compose($request->getNewName(), $request->getNewCode()); |
53
|
|
|
$material->setCategory($category); |
54
|
|
|
$material->setUnit($request->getUnit()); |
55
|
|
|
|
56
|
|
|
$this->materialRepository->update($material); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param CategoryInterface $category |
61
|
|
|
*/ |
62
|
|
|
private function callWarningLimitationAssignOnlyToLeaf(CategoryInterface $category) |
63
|
|
|
{ |
64
|
|
|
/** @var EditMaterialResponderInterface $responder */ |
65
|
|
|
foreach ($this->responders as $responder) { |
66
|
|
|
$responder->callWarningLimitationAssignOnlyToLeaf($category); |
|
|
|
|
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
} |
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.