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   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 45
ccs 19
cts 19
cp 1
rs 10
wmc 9

6 Methods

Rating   Name   Duplication   Size   Complexity  
A comments() 0 3 1
A canBeRated() 0 3 1
A mustBeApproved() 0 3 1
A averageRate() 0 14 3
A primaryId() 0 3 1
A totalCommentsCount() 0 7 2
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