Completed
Pull Request — master (#857)
by Lex
13:03
created

Module::hasStatus()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Nwidart\Modules\Entities;
4
5
use Illuminate\Database\Eloquent\Model;
6
7
class Module extends Model
8
{
9
    /**
10
     * The attributes that are mass assignable.
11
     *
12
     * @var array
13
     */
14
    protected $fillable = [
15
        'name',
16
        'path',
17
    ];
18
19
    /**
20
     * @param string $name
21
     * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object|void|null
22
     */
23
    public static function findByName(string $name)
24
    {
25
        return static::query()->where('name', $name)->first();
26
    }
27
28
    /**
29
     * @param string $name
30
     * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object|void|null
31
     */
32
    public static function findByNameOrFail(string $name)
33
    {
34
        return static::query()->where('name', $name)->firstOrFail();
35
    }
36
37
    /**
38
     * @param string $name
39
     * @param string $path
40
     * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model
41
     */
42
    public static function findByNameOrCreate(string $name, string $path)
43
    {
44
        return static::query()->firstOrCreate(['name' => $name, 'path' => $path]);
45
    }
46
47
    /**
48
     * @return mixed
49
     */
50
    public static function deleteAll()
51
    {
52
        return static::query()
53
            ->delete();
54
    }
55
56
    /**
57
     * @param $column
58
     * @param $direction
59
     * @return \Illuminate\Database\Eloquent\Builder
60
     */
61
    public static function orderBy($column, $direction)
62
    {
63
        return static::query()
0 ignored issues
show
Bug introduced by
The method orderBy() does not exist on Illuminate\Database\Eloquent\Builder. Did you maybe mean enforceOrderBy()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
64
            ->orderBy($column, $direction);
65
    }
66
67
    /**
68
     * Determine whether the given status same with a module status.
69
     *
70
     * @param $status
71
     * @return bool
72
     */
73
    public function hasStatus(bool $status)
74
    {
75
        return $this->is_active === $status;
76
    }
77
78
    /**
79
     * Set active state for a module.
80
     *
81
     * @param bool $active
82
     */
83
    public function setActive(bool $active)
84
    {
85
        $this->is_active = $active;
86
        $this->save();
87
    }
88
}
89