Completed
Push — master ( e48405...3cf851 )
by Karl
27s
created

Recruiter   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 45
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 8 1
A scopeWhereNameLike() 0 5 1
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 2
    protected static function boot()
30
    {
31 2
        parent::boot();
32
33 2
        static::creating(function ($model) {
34 1
            $model->{$model->getKeyName()} = Uuid::uuid4();
35 2
        });
36 2
    }
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
        $where = "to_tsvector('english', name) @@ plainto_tsquery('english', ?)";
49 1
        return $query->whereRaw($where, [$name]);
50
    }
51
}
52