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

HasVerifiedAtHelpers   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 73
rs 10
c 0
b 0
f 0
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A unverify() 0 5 1
A setVerifiedFlag() 0 5 1
A unsetVerifiedFlag() 0 5 1
A verify() 0 5 1
A isUnverified() 0 3 1
A initializeHasVerifiedAtHelpers() 0 3 1
A isVerified() 0 3 1
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
use Illuminate\Support\Carbon;
17
18
trait HasVerifiedAtHelpers
19
{
20
    public function initializeHasVerifiedAtHelpers(): void
21
    {
22
        $this->dates[] = 'verified_at';
0 ignored issues
show
Bug Best Practice introduced by
The property dates does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
23
    }
24
25
    /**
26
     * Set verified flag.
27
     *
28
     * @return static
29
     */
30
    public function setVerifiedFlag()
31
    {
32
        $this->setAttribute('verified_at', Carbon::now());
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

32
        $this->/** @scrutinizer ignore-call */ 
33
               setAttribute('verified_at', Carbon::now());
Loading history...
33
34
        return $this;
35
    }
36
37
    /**
38
     * Unset verified flag.
39
     *
40
     * @return static
41
     */
42
    public function unsetVerifiedFlag()
43
    {
44
        $this->setAttribute('verified_at', null);
45
46
        return $this;
47
    }
48
49
    /**
50
     * If entity is verified.
51
     *
52
     * @return bool
53
     */
54
    public function isVerified(): bool
55
    {
56
        return !is_null($this->getAttributeValue('verified_at'));
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

56
        return !is_null($this->/** @scrutinizer ignore-call */ getAttributeValue('verified_at'));
Loading history...
57
    }
58
59
    /**
60
     * If entity is unverified.
61
     *
62
     * @return bool
63
     */
64
    public function isUnverified(): bool
65
    {
66
        return !$this->isVerified();
67
    }
68
69
    /**
70
     * Mark entity as verified.
71
     *
72
     * @return void
73
     */
74
    public function verify(): void
75
    {
76
        $this->setVerifiedFlag()->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

76
        $this->setVerifiedFlag()->/** @scrutinizer ignore-call */ save();
Loading history...
77
78
        $this->fireModelEvent('verified', 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

78
        $this->/** @scrutinizer ignore-call */ 
79
               fireModelEvent('verified', false);
Loading history...
79
    }
80
81
    /**
82
     * Mark entity as unverified.
83
     *
84
     * @return void
85
     */
86
    public function unverify(): void
87
    {
88
        $this->unsetVerifiedFlag()->save();
89
90
        $this->fireModelEvent('unverified', false);
91
    }
92
}
93