| Conditions | 2 |
| Paths | 2 |
| Total Lines | 26 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 13 |
| CRAP Score | 2 |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 17 | 2 | public function add( |
|
| 18 | FavoriteAbleInterface $obj, |
||
| 19 | UserInterface $user, |
||
| 20 | ): bool { |
||
| 21 | 2 | $itemId = $obj->getId(); |
|
| 22 | 2 | $type = $obj->getType(); |
|
| 23 | |||
| 24 | 2 | $favorite = $this->favoriteRepository->findOneBy([ |
|
| 25 | 'user' => $user, |
||
| 26 | 'item_id' => $itemId, |
||
| 27 | 'type' => $type, |
||
| 28 | ]); |
||
| 29 | |||
| 30 | 2 | if ($favorite === null) { |
|
| 31 | 1 | $favorite = $this->favoriteRepository->prototype() |
|
| 32 | 1 | ->setUser($user) |
|
| 33 | 1 | ->setType($type) |
|
| 34 | 1 | ->setItemId($itemId) |
|
| 35 | 1 | ->setDate(new \DateTime()); |
|
| 36 | |||
| 37 | 1 | $this->favoriteRepository->save($favorite); |
|
| 38 | |||
| 39 | 1 | return true; |
|
| 40 | } |
||
| 41 | |||
| 42 | 1 | return false; |
|
| 43 | } |
||
| 64 |