Completed
Push — master ( 7e4a8d...1527e7 )
by Arthur
03:07
created

EquipmentRepository::findByDeviceKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php namespace BB\Repo;
2
3
use BB\Entities\Equipment;
4
use Illuminate\Database\Eloquent\ModelNotFoundException;
5
6
class EquipmentRepository extends DBRepository
7
{
8
9
    /**
10
     * @var Equipment
11
     */
12
    protected $model;
13
14
    public function __construct(Equipment $model)
15
    {
16
        $this->model = $model;
17
    }
18
19
    public function all()
20
    {
21
        return $this->model->all();
22
    }
23
24
    public function getRequiresInduction()
25
    {
26
        return $this->model->where('requires_induction', true)->get();
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<BB\Entities\Equipment>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
27
    }
28
29
    public function getDoesntRequireInduction()
30
    {
31
        return $this->model->where('requires_induction', false)->get();
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<BB\Entities\Equipment>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
32
    }
33
34
35
    public function allPaid()
36
    {
37
        return $this->model->where('access_fee', '!=', 0)->get();
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<BB\Entities\Equipment>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
38
    }
39
40
    /**
41
     * Return a device by its slug
42
     * @param $slug
43
     * @return Equipment
44
     */
45
    public function findBySLug($slug)
46
    {
47
        $record = $this->model->where('slug', $slug)->first();
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<BB\Entities\Equipment>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
48
        if ($record) {
49
            return $record;
50
        }
51
        throw new ModelNotFoundException();
52
    }
53
54
    /**
55
     * Return a device by its slug
56
     * @param $slug
57
     * @return Equipment
58
     */
59
    public function findByDeviceKey($device)
60
    {
61
        return $this->model->where('device_key', $device)->firstOrFail();
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<BB\Entities\Equipment>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
62
    }
63
} 
64