|
4 | 4 |
|
5 | 5 | namespace Podium\Api\Services\Category; |
6 | 6 |
|
| 7 | +use InvalidArgumentException; |
7 | 8 | use Podium\Api\Components\PodiumResponse; |
8 | 9 | use Podium\Api\Events\SortEvent; |
9 | 10 | use Podium\Api\Interfaces\CategoryRepositoryInterface; |
@@ -39,11 +40,27 @@ private function beforeReplace(): bool |
39 | 40 | */ |
40 | 41 | public function replace(RepositoryInterface $firstCategory, RepositoryInterface $secondCategory): PodiumResponse |
41 | 42 | { |
42 | | - if ( |
43 | | - !$firstCategory instanceof CategoryRepositoryInterface |
44 | | - || !$secondCategory instanceof CategoryRepositoryInterface |
45 | | - || !$this->beforeReplace() |
46 | | - ) { |
| 43 | + if (!$firstCategory instanceof CategoryRepositoryInterface) { |
| 44 | + return PodiumResponse::error( |
| 45 | + [ |
| 46 | + 'exception' => new InvalidArgumentException( |
| 47 | + 'First category must be instance of Podium\Api\Interfaces\CategoryRepositoryInterface!' |
| 48 | + ), |
| 49 | + ] |
| 50 | + ); |
| 51 | + } |
| 52 | + |
| 53 | + if (!$secondCategory instanceof CategoryRepositoryInterface) { |
| 54 | + return PodiumResponse::error( |
| 55 | + [ |
| 56 | + 'exception' => new InvalidArgumentException( |
| 57 | + 'Second category must be instance of Podium\Api\Interfaces\CategoryRepositoryInterface!' |
| 58 | + ), |
| 59 | + ] |
| 60 | + ); |
| 61 | + } |
| 62 | + |
| 63 | + if (!$this->beforeReplace()) { |
47 | 64 | return PodiumResponse::error(); |
48 | 65 | } |
49 | 66 |
|
@@ -98,7 +115,17 @@ private function beforeSort(): bool |
98 | 115 | */ |
99 | 116 | public function sort(RepositoryInterface $category): PodiumResponse |
100 | 117 | { |
101 | | - if (!$category instanceof CategoryRepositoryInterface || !$this->beforeSort()) { |
| 118 | + if (!$category instanceof CategoryRepositoryInterface) { |
| 119 | + return PodiumResponse::error( |
| 120 | + [ |
| 121 | + 'exception' => new InvalidArgumentException( |
| 122 | + 'Category must be instance of Podium\Api\Interfaces\CategoryRepositoryInterface!' |
| 123 | + ), |
| 124 | + ] |
| 125 | + ); |
| 126 | + } |
| 127 | + |
| 128 | + if (!$this->beforeSort()) { |
102 | 129 | return PodiumResponse::error(); |
103 | 130 | } |
104 | 131 |
|
|
0 commit comments