MorphOneWallet::wallet()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 9
ccs 8
cts 8
cp 1
crap 2
rs 10
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
 * @property-read WalletModel $wallet
11
 */
12
trait MorphOneWallet
13
{
14
    /**
15
     * Get default Wallet
16
     * this method is used for Eager Loading.
17
     *
18
     * @return MorphOne|WalletModel
19
     */
20 117
    public function wallet(): MorphOne
21
    {
22 117
        return ($this instanceof WalletModel ? $this->holder : $this)
23 117
            ->morphOne(config('wallet.wallet.model', WalletModel::class), '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

23
            ->/** @scrutinizer ignore-call */ morphOne(config('wallet.wallet.model', WalletModel::class), 'holder')
Loading history...
24 117
            ->where('slug', config('wallet.wallet.default.slug', 'default'))
25 117
            ->withDefault([
26 117
                'name' => config('wallet.wallet.default.name', 'Default Wallet'),
27 117
                'slug' => config('wallet.wallet.default.slug', 'default'),
28 117
                'balance' => 0,
29
            ]);
30
    }
31
}
32