Completed
Push — master ( 3dacf3...538517 )
by Anton
13s
created

HasAcceptedAtHelpers::unsetAcceptedFlag()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 5
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
use Illuminate\Support\Facades\Date;
17
18
trait HasAcceptedAtHelpers
19
{
20
    public function initializeHasAcceptedAtHelpers(): void
21
    {
22
        $this->dates[] = 'accepted_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
     * If entity is accepted.
27
     *
28
     * @return bool
29
     */
30
    public function isAccepted(): bool
31
    {
32
        return !is_null($this->getAttributeValue('accepted_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

32
        return !is_null($this->/** @scrutinizer ignore-call */ getAttributeValue('accepted_at'));
Loading history...
33
    }
34
35
    /**
36
     * If entity is rejected.
37
     *
38
     * @return bool
39
     */
40
    public function isRejected(): bool
41
    {
42
        return !$this->isAccepted();
43
    }
44
45
    /**
46
     * Mark entity as accepted.
47
     *
48
     * @return void
49
     */
50
    public function accept(): void
51
    {
52
        $this->setAttribute('accepted_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

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

53
        $this->/** @scrutinizer ignore-call */ 
54
               save();
Loading history...
54
55
        $this->fireModelEvent('accepted', 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

55
        $this->/** @scrutinizer ignore-call */ 
56
               fireModelEvent('accepted', false);
Loading history...
56
    }
57
58
    /**
59
     * Mark entity as rejected.
60
     *
61
     * @return void
62
     */
63
    public function reject(): void
64
    {
65
        $this->setAttribute('accepted_at', null);
66
        $this->save();
67
68
        $this->fireModelEvent('rejected', false);
69
    }
70
}
71