GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

HasWallets   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 29
c 0
b 0
f 0
wmc 5
lcom 0
cbo 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A wallets() 0 4 1
A wallet() 0 16 4
1
<?php
2
3
namespace CoreProc\WalletPlus\Models\Traits;
4
5
use CoreProc\WalletPlus\Models\Wallet;
6
7
trait HasWallets
8
{
9
    public function wallets()
10
    {
11
        return $this->morphMany(Wallet::class, 'user');
0 ignored issues
show
Bug introduced by
It seems like morphMany() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
12
    }
13
14
    /**
15
     * @param int|string|null $walletType Can either be the name, or the wallet type ID. Can also be null if you're not
16
     * using wallet types.
17
     * @return Wallet
18
     */
19
    public function wallet($walletType = null)
20
    {
21
        if(is_null($walletType)) {
22
            return $this->wallets()->whereNull('wallet_type_id')->first();
23
        }
24
25
        if(is_int($walletType)) {
26
            return $this->wallets()->where('wallet_type_id', $walletType)->first();
27
        }
28
29
        if(is_string($walletType)) {
30
            return $this->wallets()->whereHas('walletType', function($q) use ($walletType) {
31
                return $q->where('name', $walletType);
32
            })->first();
33
        }
34
    }
35
}
36