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

HasAcceptedFlagHelpers::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
trait HasAcceptedFlagHelpers
17
{
18
    public function initializeHasAcceptedFlagHelpers(): void
19
    {
20
        $this->casts['is_accepted'] = '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
     * If entity is accepted.
25
     *
26
     * @return bool
27
     */
28
    public function isAccepted(): bool
29
    {
30
        return $this->getAttributeValue('is_accepted');
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

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

50
        $this->/** @scrutinizer ignore-call */ 
51
               setAttribute('is_accepted', true);
Loading history...
51
        $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

51
        $this->/** @scrutinizer ignore-call */ 
52
               save();
Loading history...
52
53
        $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

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