Passed
Push — master ( 7219d5...ae3e5c )
by Anton
02:28
created

HasVerifiedAtHelpers   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 31
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A initializeHasVerifiedAtHelpers() 0 3 1
A isNotVerified() 0 3 1
A verify() 0 6 1
A isVerified() 0 3 1
A undoVerify() 0 6 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\Facades\Date;
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
    public function isVerified(): bool
26
    {
27
        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

27
        return !is_null($this->/** @scrutinizer ignore-call */ getAttributeValue('verified_at'));
Loading history...
28
    }
29
30
    public function isNotVerified(): bool
31
    {
32
        return !$this->isVerified();
33
    }
34
35
    public function verify(): void
36
    {
37
        $this->setAttribute('verified_at', Date::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

37
        $this->/** @scrutinizer ignore-call */ 
38
               setAttribute('verified_at', Date::now());
Loading history...
38
        $this->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

38
        $this->/** @scrutinizer ignore-call */ 
39
               save();
Loading history...
39
40
        $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

40
        $this->/** @scrutinizer ignore-call */ 
41
               fireModelEvent('verified', false);
Loading history...
41
    }
42
43
    public function undoVerify(): void
44
    {
45
        $this->setAttribute('verified_at', null);
46
        $this->save();
47
48
        $this->fireModelEvent('unverified', false);
49
    }
50
}
51