Total Complexity | 8 |
Total Lines | 42 |
Duplicated Lines | 0 % |
Coverage | 90.91% |
Changes | 0 |
1 | <?php |
||
10 | trait CanComment |
||
11 | { |
||
12 | 26 | public function comment(Commentable $commentable, string $commentText = '', int $rate = 0): Comment |
|
13 | { |
||
14 | 26 | $commentModel = config('comment.model'); |
|
15 | |||
16 | 26 | $comment = new $commentModel([ |
|
17 | 26 | 'comment' => $commentText, |
|
18 | 26 | 'rate' => $commentable->canBeRated() ? $rate : null, |
|
19 | 26 | 'approved' => $commentable->mustBeApproved() && !$this->canCommentWithoutApprove() ? false : true, |
|
20 | 26 | 'commented_id' => $this->primaryId(), |
|
21 | 26 | 'commented_type' => get_class(), |
|
22 | ]); |
||
23 | |||
24 | 26 | $commentable->comments()->save($comment); |
|
25 | |||
26 | 26 | return $comment; |
|
27 | } |
||
28 | |||
29 | public function canCommentWithoutApprove(): bool |
||
30 | { |
||
31 | return false; |
||
32 | } |
||
33 | |||
34 | 10 | public function comments(): MorphMany |
|
37 | } |
||
38 | |||
39 | 2 | public function hasCommentsOn(Commentable $commentable): bool |
|
47 | } |
||
48 | |||
49 | 26 | private function primaryId(): string |
|
52 | } |
||
53 | } |
||
54 |