StatusTrait::offlineAndOnline()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Distilleries\Expendable\Models;
4
5
use Distilleries\Expendable\Scopes\StatusScope;
6
7
trait StatusTrait
8
{
9
    /**
10
     * Boot the soft deleting trait for a model.
11
     *
12
     * @return void
13
     */
14 216
    public static function bootStatusTrait()
15
    {
16 216
        static::addGlobalScope(new StatusScope);
17
    }
18
19
    /**
20
     * Get a new query builder that only includes offline items.
21
     *
22
     * @return \Illuminate\Database\Eloquent\Builder|static
23
     */
24 2
    public static function onlyOffline()
25
    {
26
27 2
        $instance = new static;
28
29 2
        $column = $instance->getQualifiedStatusColumn();
30
31 2
        return $instance->withoutGlobalScope(StatusScope::class)->where($column, false);
0 ignored issues
show
Bug introduced by
It seems like withoutGlobalScope() 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

31
        return $instance->/** @scrutinizer ignore-call */ withoutGlobalScope(StatusScope::class)->where($column, false);
Loading history...
32
    }
33
34
    /**
35
     * Get a new query builder that include offline and online items.
36
     *
37
     * @return \Illuminate\Database\Eloquent\Builder
38
     */
39 4
    public static function offlineAndOnline()
40
    {
41 4
        $instance = new static;
42
43 4
        return $instance->withoutGlobalScope(StatusScope::class);
44
    }
45
46
    /**
47
     * Get the fully qualified "deleted at" column.
48
     *
49
     * @return string
50
     */
51 50
    public function getQualifiedStatusColumn()
52
    {
53 50
        return $this->getTable().'.'.$this->getStatusColumn();
0 ignored issues
show
Bug introduced by
It seems like getTable() 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

53
        return $this->/** @scrutinizer ignore-call */ getTable().'.'.$this->getStatusColumn();
Loading history...
54
    }
55
56
    /**
57
     * Get the name of the "deleted at" column.
58
     *
59
     * @return string
60
     */
61 50
    public function getStatusColumn()
62
    {
63 50
        return defined('static::STATUS') ? static::STATUS : 'status';
0 ignored issues
show
Bug introduced by
The constant Distilleries\Expendable\Models\StatusTrait::STATUS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
64
    }
65
}
66