| Total Complexity | 5 |
| Total Lines | 34 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 12 | final class PostService |
||
| 13 | { |
||
| 14 | private PostRepository $repository; |
||
| 15 | private TagRepository $tagRepository; |
||
| 16 | |||
| 17 | public function __construct(PostRepository $repository, TagRepository $tagRepository) |
||
| 18 | { |
||
| 19 | $this->repository = $repository; |
||
| 20 | $this->tagRepository = $tagRepository; |
||
| 21 | } |
||
| 22 | |||
| 23 | public function savePost(User $user, Post $model, PostForm $form): void |
||
| 24 | { |
||
| 25 | $model->setTitle($form->getTitle()); |
||
| 26 | $model->setContent($form->getContent()); |
||
|
|
|||
| 27 | $model->resetTags(); |
||
| 28 | |||
| 29 | foreach ($form->getTags() as $tag) { |
||
| 30 | $model->addTag($this->tagRepository->getOrCreate($tag)); |
||
| 31 | } |
||
| 32 | |||
| 33 | if ($model->isNewRecord()) { |
||
| 34 | $model->setPublic(true); |
||
| 35 | $model->setUser($user); |
||
| 36 | } |
||
| 37 | |||
| 38 | $this->repository->save($model); |
||
| 39 | } |
||
| 40 | |||
| 41 | public function getPostTags(Post $post): array |
||
| 46 | ); |
||
| 47 | } |
||
| 48 | } |
||
| 49 |