Passed
Push — main ( ba4320...d07568 )
by Michael
03:19
created

DefinesModelRelations   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 5
c 1
b 0
f 0
dl 0
loc 22
ccs 5
cts 5
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A redeemer() 0 3 1
A couponables() 0 5 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 MichaelRubel\Couponables\Models\Contracts\CouponPivotContract;
10
11
trait DefinesModelRelations
12
{
13
    /**
14
     * Fetch the latest couponables - redeemed coupon records.
15
     *
16
     * @return HasMany
17
     */
18 1
    public function couponables(): HasMany
19
    {
20
        return $this
21 1
            ->hasMany(app(CouponPivotContract::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

21
            ->/** @scrutinizer ignore-call */ hasMany(app(CouponPivotContract::class))
Loading history...
22 1
            ->latest();
23
    }
24
25
    /**
26
     * The only model allowed to redeem the coupon.
27
     *
28
     * @return Model|null
29
     */
30 2
    public function redeemer(): ?Model
31
    {
32 2
        return $this->morphTo()->first();
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

32
        return $this->/** @scrutinizer ignore-call */ morphTo()->first();
Loading history...
33
    }
34
}
35