Completed
Push — master ( 64e679...fc08d1 )
by Ashley
03:21
created

Invite::isUseless()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 2
eloc 2
nc 2
nop 0
1
<?php
2
3
namespace Clarkeash\Doorman\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
7
class Invite extends Model
8
{
9
    protected $dates = [ 'valid_until' ];
10
    
11
    public function __construct(array $attributes = [])
12
    {
13
        $this->table = config('doorman.invite_table_name');
14
        parent::__construct($attributes);
15
    }
16
17
    public function hasExpired()
18
    {
19
        if(is_null($this->valid_until)) return false;
20
21
        return $this->valid_until->isPast();
22
    }
23
24
    public function isFull()
25
    {
26
        if($this->max == 0) return false;
27
28
        return $this->uses >= $this->max;
29
    }
30
31
    public function isRestricted()
32
    {
33
        return !is_null($this->for);
34
    }
35
36
    public function isRestrictedFor($email)
37
    {
38
        return $email == $this->for;
39
    }
40
41
    public function isUseless()
42
    {
43
        return $this->hasExpired() || $this->isFull();
44
    }
45
}
46