Completed
Push — master ( 538517...7219d5 )
by Anton
02:52
created

HasApprovedFlagHelpers   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 initializeHasApprovedFlagHelpers() 0 3 1
A disapprove() 0 6 1
A approve() 0 6 1
A isNotApproved() 0 3 1
A isApproved() 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
trait HasApprovedFlagHelpers
17
{
18
    public function initializeHasApprovedFlagHelpers(): void
19
    {
20
        $this->casts['is_approved'] = '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
    public function isApproved(): bool
24
    {
25
        return $this->getAttributeValue('is_approved');
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

25
        return $this->/** @scrutinizer ignore-call */ getAttributeValue('is_approved');
Loading history...
26
    }
27
28
    public function isNotApproved(): bool
29
    {
30
        return !$this->isApproved();
31
    }
32
33
    public function approve(): void
34
    {
35
        $this->setAttribute('is_approved', 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

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

36
        $this->/** @scrutinizer ignore-call */ 
37
               save();
Loading history...
37
38
        $this->fireModelEvent('approved', 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

38
        $this->/** @scrutinizer ignore-call */ 
39
               fireModelEvent('approved', false);
Loading history...
39
    }
40
41
    public function disapprove(): void
42
    {
43
        $this->setAttribute('is_approved', false);
44
        $this->save();
45
46
        $this->fireModelEvent('disapproved', false);
47
    }
48
}
49