DefinesModelRelations::couponables()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 4
c 2
b 0
f 0
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 10
cc 1
nc 1
nop 0
crap 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