Completed
Push — master ( e0683b...eed8e4 )
by ARCANEDEV
09:48 queued 08:04
created

Activatable::switchActive()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
ccs 3
cts 3
cp 1
cc 2
eloc 3
nc 2
nop 2
crap 2
1
<?php namespace Arcanedev\LaravelAuth\Models\Traits;
2
3
/**
4
 * Class     Activatable
5
 *
6
 * @package  Arcanedev\LaravelAuth\Traits
7
 * @author   ARCANEDEV <[email protected]>
8
 *
9
 * @property  bool  is_active
10
 *
11
 * @method    bool  save(array $options = [])
12
 */
13
trait Activatable
14
{
15
    /* ------------------------------------------------------------------------------------------------
16
     |  CRUD Functions
17
     | ------------------------------------------------------------------------------------------------
18
     */
19
    /**
20
     * Activate the model.
21
     *
22
     * @param  bool  $save
23
     *
24
     * @return bool
25
     */
26 18
    public function activate($save = true)
27
    {
28 18
        return $this->switchActive(true, $save);
29
    }
30
31
    /**
32
     * Deactivate the model.
33
     *
34
     * @param  bool  $save
35
     *
36
     * @return bool
37
     */
38 18
    public function deactivate($save = true)
39
    {
40 18
        return $this->switchActive(false, $save);
41
    }
42
43
    /**
44
     * Activate/deactivate the model.
45
     *
46
     * @param  bool  $active
47
     * @param  bool  $save
48
     *
49
     * @return bool
50
     */
51 18
    protected function switchActive($active, $save = true)
52
    {
53 18
        $this->is_active = boolval($active);
54
55 18
        return $save ? $this->save() : false;
56
    }
57
58
    /* ------------------------------------------------------------------------------------------------
59
     |  Check Functions
60
     | ------------------------------------------------------------------------------------------------
61
     */
62
    /**
63
     * Check if the model is active.
64
     *
65
     * @return bool
66
     */
67 54
    public function isActive()
68
    {
69 54
        return $this->is_active;
70
    }
71
}
72