| Total Complexity | 8 |
| Total Lines | 48 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 12 | class Like extends Component |
||
| 13 | { |
||
| 14 | |||
| 15 | public $comment; |
||
| 16 | public $count; |
||
| 17 | |||
| 18 | |||
| 19 | public function mount(\Usamamuneerchaudhary\Commentify\Models\Comment $comment): void |
||
| 20 | { |
||
| 21 | $this->comment = $comment; |
||
| 22 | $this->count = $comment->likes_count; |
||
|
|
|||
| 23 | } |
||
| 24 | |||
| 25 | public function like(): void |
||
| 26 | { |
||
| 27 | $ip = request()->ip(); |
||
| 28 | $userAgent = request()->userAgent(); |
||
| 29 | if ($this->comment->isLiked()) { |
||
| 30 | $this->comment->removeLike(); |
||
| 31 | |||
| 32 | $this->count--; |
||
| 33 | } elseif (auth()->user()) { |
||
| 34 | $this->comment->likes()->create([ |
||
| 35 | 'user_id' => auth()->id(), |
||
| 36 | ]); |
||
| 37 | |||
| 38 | $this->count++; |
||
| 39 | |||
| 40 | if (config('commentify.enable_notifications', false)) { |
||
| 41 | event(new CommentLiked($this->comment, auth()->id())); |
||
| 42 | } |
||
| 43 | } elseif ($ip && $userAgent) { |
||
| 44 | $this->comment->likes()->create([ |
||
| 45 | 'ip' => $ip, |
||
| 46 | 'user_agent' => $userAgent, |
||
| 47 | ]); |
||
| 48 | |||
| 49 | $this->count++; |
||
| 50 | } |
||
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @return Factory|Application|View|\Illuminate\Contracts\Foundation\Application|null |
||
| 55 | */ |
||
| 56 | public function render( |
||
| 60 | } |
||
| 61 | |||
| 62 | } |
||
| 63 |
Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.