CommentService::createComment()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
nc 1
nop 2
dl 0
loc 12
ccs 7
cts 7
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace App\Services;
4
5
use App\Http\Requests\CommentStoreRequest;
6
use App\Models\Comment;
7
8
class CommentService
9
{
10
11
    /**
12
     * Create a comment
13
     *
14
     * @param \App\Http\Requests\CommentStoreRequest $data
15
     *
16
     * @param mixed $entity
17
     *
18
     * @return \App\Models\Comment
19
     */
20
    public function createComment(CommentStoreRequest $data, object $entity): Comment
21 1
    {
22
        $comment = new Comment();
23 1
        $comment->body = $data['body'];
24 1
        $comment->name = $data['name'];
25 1
        $comment->email = $data['email'];
26 1
27
        $entity->comments()->save($comment);
28 1
29
        //then publish comment
30 1
31
        return $comment;
32
    }
33
}