Passed
Push — master ( e72d83...d1ec6f )
by Бабичев
15:06 queued 05:14
created

MorphOneWallet   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A wallet() 0 9 2
1
<?php
2
3
namespace Bavix\Wallet\Traits;
4
5
use Bavix\Wallet\Models\Wallet as WalletModel;
6
use Illuminate\Database\Eloquent\Relations\MorphOne;
7
8
/**
9
 * Trait MorphOneWallet
10
 * @package Bavix\Wallet\Traits
11
 * @property-read WalletModel $wallet
12
 */
13
trait MorphOneWallet
14
{
15
16
    /**
17
     * Get default Wallet
18
     * this method is used for Eager Loading
19
     *
20
     * @return MorphOne|WalletModel
21
     */
22 65
    public function wallet(): MorphOne
23
    {
24 65
        return ($this instanceof WalletModel ? $this->holder : $this)
25 65
            ->morphOne(config('wallet.wallet.model'), 'holder')
0 ignored issues
show
Bug introduced by
It seems like morphOne() 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

25
            ->/** @scrutinizer ignore-call */ morphOne(config('wallet.wallet.model'), 'holder')
Loading history...
26 65
            ->where('slug', config('wallet.wallet.default.slug'))
27 65
            ->withDefault([
28 65
                'name' => config('wallet.wallet.default.name'),
29 65
                'slug' => config('wallet.wallet.default.slug'),
30 65
                'balance' => 0,
31
            ]);
32
    }
33
34
}
35