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