Completed
Push — ft/states ( d9d02a...d4f7ca )
by Ben
45:58 queued 35:27
created

Publishable   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 71.43%

Importance

Changes 0
Metric Value
wmc 6
eloc 8
c 0
b 0
f 0
dl 0
loc 30
ccs 10
cts 14
cp 0.7143
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A scopeDrafted() 0 3 1
A isDraft() 0 3 1
A getAllPublished() 0 3 1
A isPublished() 0 3 1
A scopePublished() 0 8 2
1
<?php
2
3
namespace Thinktomorrow\Chief\States\Publishable;
4
5
use Thinktomorrow\Chief\States\PageState;
6
7
trait Publishable
8
{
9 89
    public function isPublished(): bool
10
    {
11 89
        return $this->state() === PageState::PUBLISHED;
0 ignored issues
show
Bug introduced by
It seems like state() 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

11
        return $this->/** @scrutinizer ignore-call */ state() === PageState::PUBLISHED;
Loading history...
12
    }
13
14 85
    public function isDraft(): bool
15
    {
16 85
        return $this->state() === PageState::DRAFT;
17
    }
18
19 5
    public function scopePublished($query)
20
    {
21
        // Here we widen up the results in case of preview mode and ignore the published scope
22 5
        if (PreviewMode::fromRequest()->check()) {
23
            return;
24
        }
25
26 5
        $query->where('current_state', PageState::PUBLISHED);
27 5
    }
28
29
    public function scopeDrafted($query)
30
    {
31
        $query->where('current_state', PageState::DRAFT);
32
    }
33
34 3
    public static function getAllPublished()
35
    {
36 3
        return self::published()->get();
37
    }
38
}
39