Completed
Push — master ( e3919a...c23336 )
by Marceau
01:58
created

HasLoginsAndDevices::fails()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace Lab404\AuthChecker\Models;
4
5
use Illuminate\Database\Eloquent\Relations\HasMany;
6
7
/**
8
 * Class HasLoginsAndDevices
9
 *
10
 * @package Lab404\AuthChecker\Models
11
 * @property \Illuminate\Support\Collection $logins
12
 * @property \Illuminate\Support\Collection $auths
13
 * @property \Illuminate\Support\Collection $fails
14
 * @property \Illuminate\Support\Collection $lockouts
15
 * @property \Illuminate\Support\Collection $devices
16
 */
17
trait HasLoginsAndDevices
18
{
19
    /**
20
     * @param   void
21
     * @return  HasMany
22
     */
23
    public function logins()
24
    {
25
        return $this->hasMany(Login::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?

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...
26
    }
27
28
    /**
29
     * @param   void
30
     * @return  HasMany
31
     */
32
    public function auths()
33
    {
34
        $relation = $this->logins();
35
        $relation->where('type', Login::TYPE_LOGIN);
36
37
        return $relation;
38
    }
39
40
    /**
41
     * @param   void
42
     * @return  HasMany
43
     */
44
    public function fails()
45
    {
46
        $relation = $this->logins();
47
        $relation->where('type', Login::TYPE_FAILED);
48
49
        return $relation;
50
    }
51
52
    /**
53
     * @param   void
54
     * @return  HasMany
55
     */
56
    public function lockouts()
57
    {
58
        $relation = $this->logins();
59
        $relation->where('type', Login::TYPE_LOCKOUT);
60
61
        return $relation;
62
    }
63
64
    /**
65
     * @param   void
66
     * @return  HasMany
67
     */
68
    public function devices()
69
    {
70
        return $this->hasMany(Device::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?

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...
71
    }
72
73
    /**
74
     * @param   void
75
     * @return  bool
76
     */
77
    public function hasDevices()
78
    {
79
        return $this->devices()->get()->isNotEmpty();
80
    }
81
}
82