Test Failed
Push — ft/states ( eebc9c )
by Ben
29:42 queued 08:49
created

Publishable   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 9
eloc 13
c 0
b 0
f 0
dl 0
loc 47
rs 10

8 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 draft() 0 4 1
A scopeSortedByPublished() 0 3 1
A publish() 0 4 1
A scopePublished() 0 8 2
1
<?php
2
3
namespace Thinktomorrow\Chief\States\Publishable;
4
5
trait Publishable
6
{
7
    public function isPublished()
8
    {
9
        return (!!$this->published);
10
    }
11
12
    public function isDraft()
13
    {
14
        return (!$this->published);
15
    }
16
17
    public function scopePublished($query)
18
    {
19
        // Here we widen up the results in case of preview mode and ignore the published scope
20
        if (PreviewMode::fromRequest()->check()) {
21
            return;
22
        }
23
24
        $query->where('published', 1);
25
    }
26
27
    public function scopeDrafted($query)
28
    {
29
        $query->where('published', 0);
30
    }
31
32
    public function publish()
33
    {
34
        $this->published = 1;
0 ignored issues
show
Bug Best Practice introduced by
The property published does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
35
        $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

35
        $this->/** @scrutinizer ignore-call */ 
36
               save();
Loading history...
36
    }
37
38
    public function draft()
39
    {
40
        $this->published = 0;
0 ignored issues
show
Bug Best Practice introduced by
The property published does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
41
        $this->save();
42
    }
43
44
    public static function getAllPublished()
45
    {
46
        return self::published()->get();
0 ignored issues
show
Bug introduced by
The method published() does not exist on Thinktomorrow\Chief\States\Publishable\Publishable. Did you maybe mean publish()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

46
        return self::/** @scrutinizer ignore-call */ published()->get();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
47
    }
48
49
    public function scopeSortedByPublished($query)
50
    {
51
        return $query->orderBy('published', 'DESC');
52
    }
53
}
54