Completed
Push — master ( 8dafd6...46bcfe )
by Anton
02:53
created

initializeHasActiveFlagHelpers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of Laravel Eloquent Flag.
5
 *
6
 * (c) Anton Komarev <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Cog\Flag\Traits\Classic;
15
16
trait HasActiveFlagHelpers
17
{
18
    public function initializeHasActiveFlagHelpers(): void
19
    {
20
        $this->casts['is_active'] = 'boolean';
0 ignored issues
show
Bug Best Practice introduced by
The property casts does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
21
    }
22
23
    /**
24
     * Set active flag.
25
     *
26
     * @return static
27
     */
28
    public function setActivatedFlag()
29
    {
30
        $this->setAttribute('is_active', true);
0 ignored issues
show
Bug introduced by
It seems like setAttribute() 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

30
        $this->/** @scrutinizer ignore-call */ 
31
               setAttribute('is_active', true);
Loading history...
31
32
        return $this;
33
    }
34
35
    /**
36
     * Unset active flag.
37
     *
38
     * @return static
39
     */
40
    public function unsetActivatedFlag()
41
    {
42
        $this->setAttribute('is_active', false);
43
44
        return $this;
45
    }
46
47
    /**
48
     * If entity is activated.
49
     *
50
     * @return bool
51
     */
52
    public function isActivated(): bool
53
    {
54
        return $this->getAttributeValue('is_active');
0 ignored issues
show
Bug introduced by
It seems like getAttributeValue() 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

54
        return $this->/** @scrutinizer ignore-call */ getAttributeValue('is_active');
Loading history...
55
    }
56
57
    /**
58
     * If entity is deactivated.
59
     *
60
     * @return bool
61
     */
62
    public function isDeactivated(): bool
63
    {
64
        return !$this->isActivated();
65
    }
66
67
    /**
68
     * Mark entity as active.
69
     *
70
     * @return void
71
     */
72
    public function activate(): void
73
    {
74
        $this->setActivatedFlag()->save();
0 ignored issues
show
Bug introduced by
It seems like save() 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

74
        $this->setActivatedFlag()->/** @scrutinizer ignore-call */ save();
Loading history...
75
76
        $this->fireModelEvent('activated', false);
0 ignored issues
show
Bug introduced by
It seems like fireModelEvent() 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

76
        $this->/** @scrutinizer ignore-call */ 
77
               fireModelEvent('activated', false);
Loading history...
77
    }
78
79
    /**
80
     * Mark entity as deactivated.
81
     *
82
     * @return void
83
     */
84
    public function deactivate(): void
85
    {
86
        $this->unsetActivatedFlag()->save();
87
88
        $this->fireModelEvent('deactivated', false);
89
    }
90
}
91