Model   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 8
c 1
b 0
f 0
dl 0
loc 32
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A scopeSearch() 0 4 3
A __construct() 0 3 1
1
<?php
2
3
namespace Turahe\Master\Models;
4
5
use Illuminate\Database\Eloquent\Model as BaseModel;
6
use Turahe\Master\Traits\AutoFilter;
7
use Turahe\Master\Traits\AutoSort;
8
9
/**
10
 * Class Model.
11
 */
12
abstract class Model extends BaseModel
13
{
14
    use AutoFilter;
15
    use AutoSort;
16
    /**
17
     * @var string
18
     */
19
    protected $keyType = 'string';
20
21
    /**
22
     * @var string[]
23
     */
24
    protected $searchableColumns = ['id', 'name'];
25
26
    /**
27
     * Model constructor.
28
     *
29
     * @param array $attributes
30
     */
31
    public function __construct(array $attributes = [])
32
    {
33
        parent::__construct($attributes);
34
    }
35
36
    /**
37
     * @param $query
38
     * @param $keyword
39
     */
40
    public function scopeSearch($query, $keyword)
41
    {
42
        if ($keyword && $this->searchableColumns) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->searchableColumns of type string[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
43
            $query->whereLike($this->searchableColumns, $keyword);
44
        }
45
    }
46
}
47