Passed
Push — main ( 79e4f1...ed1bb6 )
by Slawomir
04:28
created

DoctrineCommentsCreationRepository::updateCommentsCount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 16
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 19
ccs 16
cts 16
cp 1
crap 1
rs 9.7333
1
<?php
2
3
namespace App\Modules\Comments\Persistence\Doctrine\Repository;
4
5
use App\Modules\Comments\Domain\Dto\CreateNewCommentDto;
6
use App\Modules\Comments\Domain\Repository\CommentsCreationRepositoryInterface;
7
use App\Modules\Comments\Persistence\Doctrine\Entity\Comment;
8
use App\Modules\Comments\Persistence\Doctrine\Entity\CommentPostHeader;
9
use Symfony\Component\Uid\Ulid;
10
11
class DoctrineCommentsCreationRepository extends DoctrineCommentsRepository implements CommentsCreationRepositoryInterface
12
{
13
14
    /**
15
     * @param CreateNewCommentDto $newComment
16
     * @return Ulid
17
     * @throws \Doctrine\ORM\ORMException
18
     */
19 2
    public function createComment(CreateNewCommentDto $newComment): Ulid
20
    {
21 2
        $em = $this->getEntityManager();
22 2
        $comment = new Comment();
23 2
        $id = new Ulid();
24 2
        $comment->setId($id);
25 2
        $comment->setAuthor($newComment->getAuthor());
26 2
        $comment->setBody($newComment->getBody());
27 2
        $comment->setPost($em->getReference(CommentPostHeader::class, $newComment->getPostId()));
28 2
        $comment->setCreatedAt($newComment->getCreatedAt());
29 2
        if ($newComment->getParentId() != null) {
30 2
            $comment->setParentComment($em->getReference(Comment::class, $newComment->getParentId()));
31
        }
32 2
        $em->persist($comment);
33 2
        return $id;
34
    }
35
}