GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

CanComment   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 90.91%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 42
ccs 20
cts 22
cp 0.9091
rs 10
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A hasCommentsOn() 0 8 1
A primaryId() 0 3 1
A canCommentWithoutApprove() 0 3 1
A comments() 0 3 1
A comment() 0 15 4
1
<?php
2
declare(strict_types=1);
3
4
namespace Actuallymab\LaravelComment;
5
6
use Actuallymab\LaravelComment\Contracts\Commentable;
7
use Actuallymab\LaravelComment\Models\Comment;
8
use Illuminate\Database\Eloquent\Relations\MorphMany;
9
10
trait CanComment
11
{
12 13
    public function comment(Commentable $commentable, string $commentText = '', int $rate = 0): Comment
13
    {
14 13
        $commentModel = config('comment.model');
15
16 13
        $comment = new $commentModel([
17 13
            'comment'        => $commentText,
18 13
            'rate'           => $commentable->canBeRated() ? $rate : null,
19 13
            'approved'       => $commentable->mustBeApproved() && !$this->canCommentWithoutApprove() ? false : true,
20 13
            'commented_id'   => $this->primaryId(),
21 13
            'commented_type' => get_class(),
22
        ]);
23
24 13
        $commentable->comments()->save($comment);
25
26 13
        return $comment;
27
    }
28
29
    public function canCommentWithoutApprove(): bool
30
    {
31
        return false;
32
    }
33
34 5
    public function comments(): MorphMany
35
    {
36 5
        return $this->morphMany(config('comment.model'), 'commented');
0 ignored issues
show
Bug introduced by
It seems like morphMany() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

36
        return $this->/** @scrutinizer ignore-call */ morphMany(config('comment.model'), 'commented');
Loading history...
37
    }
38
39 1
    public function hasCommentsOn(Commentable $commentable): bool
40
    {
41 1
        return $this->comments()
42 1
            ->where([
43 1
                'commentable_id'   => $commentable->primaryId(),
44 1
                'commentable_type' => get_class($commentable),
45
            ])
46 1
            ->exists();
47
    }
48
49 13
    private function primaryId(): string
50
    {
51 13
        return (string)$this->getAttribute($this->primaryKey);
0 ignored issues
show
Bug introduced by
It seems like getAttribute() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

51
        return (string)$this->/** @scrutinizer ignore-call */ getAttribute($this->primaryKey);
Loading history...
52
    }
53
}
54