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

Publishable::scopeSortedByPublished()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
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