Completed
Push — master ( 49518f...3dd743 )
by Karl
10s
created

Recruiter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 90.91%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 48
ccs 10
cts 11
cp 0.9091
rs 10
c 2
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 8 1
A scopeWhereNameLike() 0 8 2
1
<?php namespace JobApis\JobsToMail\Models;
2
3
use Illuminate\Database\Eloquent\Model;
4
use Illuminate\Support\Facades\DB;
5
use Ramsey\Uuid\Uuid;
6
7
class Recruiter extends Model
8
{
9
    /**
10
     * Indicates that the IDs are not auto-incrementing.
11
     *
12
     * @var bool
13
     */
14
    public $incrementing = false;
15
16
    /**
17
     * The attributes that are mass assignable.
18
     *
19
     * @var array
20
     */
21
    protected $fillable = [
22
        'name',
23
        'url',
24
    ];
25
26
    /**
27
     * Boot function from laravel.
28
     */
29 3
    protected static function boot()
30
    {
31 3
        parent::boot();
32
33 3
        static::creating(function ($model) {
34 2
            $model->{$model->getKeyName()} = Uuid::uuid4();
35 3
        });
36 3
    }
37
38
    /**
39
     * Very simple filter to get recruiting firms by name
40
     *
41
     * @param $query
42
     * @param string $name
43
     *
44
     * @return \Illuminate\Database\Eloquent\Builder
45
     */
46 1
    public function scopeWhereNameLike($query, $name = null)
47
    {
48 1
        if ($name) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $name of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
49 1
            $where = "to_tsvector('english', name) @@ plainto_tsquery('english', ?)";
50 1
            return $query->whereRaw($where, [$name]);
51
        }
52
        return $query;
53
    }
54
}
55