DefinesModelRelations   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 2
eloc 6
c 3
b 0
f 1
dl 0
loc 24
ccs 7
cts 7
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A redeemer() 0 3 1
A couponables() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MichaelRubel\Couponables\Models\Traits;
6
7
use Illuminate\Database\Eloquent\Model;
8
use Illuminate\Database\Eloquent\Relations\HasMany;
9
use Illuminate\Database\Eloquent\Relations\MorphTo;
10
use MichaelRubel\Couponables\Models\Contracts\CouponPivotContract;
11
12
trait DefinesModelRelations
13
{
14
    /**
15
     * Fetch the latest couponables - redeemed coupon records.
16
     *
17
     * @return HasMany
18
     */
19 3
    public function couponables(): HasMany
20
    {
21 3
        $pivot = app(CouponPivotContract::class);
22
23 3
        return $this
24 3
            ->hasMany($pivot::class)
0 ignored issues
show
Bug introduced by
It seems like hasMany() 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

24
            ->/** @scrutinizer ignore-call */ hasMany($pivot::class)
Loading history...
25 3
            ->orderBy($pivot->getRedeemedAtColumn(), 'desc');
26
    }
27
28
    /**
29
     * The only model allowed to redeem the coupon.
30
     *
31
     * @return MorphTo
32
     */
33 8
    public function redeemer(): MorphTo
34
    {
35 8
        return $this->morphTo();
0 ignored issues
show
Bug introduced by
It seems like morphTo() 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

35
        return $this->/** @scrutinizer ignore-call */ morphTo();
Loading history...
36
    }
37
}
38