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.

HasComments::totalCommentsCount()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 10
1
<?php
2
declare(strict_types=1);
3
4
namespace Actuallymab\LaravelComment;
5
6
use Illuminate\Database\Eloquent\Relations\MorphMany;
7
use Illuminate\Database\Query\Builder;
8
use Illuminate\Support\Collection;
9
10
/**
11
 * @property Collection $comments
12
 */
13
trait HasComments
14
{
15 13
    public function comments(): MorphMany
16
    {
17 13
        return $this->morphMany(config('comment.model'), 'commentable');
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

17
        return $this->/** @scrutinizer ignore-call */ morphMany(config('comment.model'), 'commentable');
Loading history...
18
    }
19
20 1
    public function canBeRated(): bool
21
    {
22 1
        return false;
23
    }
24
25 1
    public function mustBeApproved(): bool
26
    {
27 1
        return false;
28
    }
29
30 1
    public function primaryId(): string
31
    {
32 1
        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

32
        return (string)$this->/** @scrutinizer ignore-call */ getAttribute($this->primaryKey);
Loading history...
33
    }
34
35 3
    public function averageRate(int $round = 2): float
36
    {
37 3
        if (!$this->canBeRated()) {
38 1
            return 0;
39
        }
40
41
        /** @var Builder $rates */
42 2
        $rates = $this->comments()->approvedComments();
43
44 2
        if (!$rates->exists()) {
45 2
            return 0;
46
        }
47
48 2
        return round((float)$rates->avg('rate'), $round);
49
    }
50
51 2
    public function totalCommentsCount(): int
52
    {
53 2
        if (!$this->mustBeApproved()) {
54 1
            return $this->comments()->count();
55
        }
56
57 1
        return $this->comments()->approvedComments()->count();
58
    }
59
}
60