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

HasPublishedFlagHelpers::isNotPublished()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
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 HasPublishedFlagHelpers
17
{
18
    public function initializeHasPublishedFlagHelpers(): void
19
    {
20
        $this->casts['is_published'] = '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 isPublished(): bool
24
    {
25
        return $this->getAttributeValue('is_published');
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_published');
Loading history...
26
    }
27
28
    public function isNotPublished(): bool
29
    {
30
        return !$this->isPublished();
31
    }
32
33
    public function publish(): void
34
    {
35
        $this->setAttribute('is_published', 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_published', 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('published', 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('published', false);
Loading history...
39
    }
40
41
    public function unpublish(): void
42
    {
43
        $this->setAttribute('is_published', false);
44
        $this->save();
45
46
        $this->fireModelEvent('unpublished', false);
47
    }
48
}
49