HasLocationName::scopeNameStartsWith()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
namespace LaraGeoData\Models;
4
5
use Illuminate\Database\Eloquent\Builder;
6
7
trait HasLocationName
8
{
9
    /**
10
     * Filed name for location name.
11
     */
12 3
    public function locationNameColumn(): string
13
    {
14 3
        return $this->locationNameColumn ?? 'location_name';
15
    }
16
17 2
    public function locationName(): ?string
18
    {
19 2
        return $this->{$this->locationNameColumn()};
20
    }
21
22 1
    public function scopeOrderByName(Builder $query, string $direction = 'asc')
23
    {
24 1
        return $query->orderBy($this->locationNameColumn(), $direction);
25
    }
26
27 1
    public function scopeNameContain(Builder $query, string $value)
28
    {
29 1
        return $query->where($this->locationNameColumn(), 'like', "%$value%");
30
    }
31
32 1
    public function scopeNameStartsWith(Builder $query, string $value)
33
    {
34 1
        return $query->where($this->locationNameColumn(), 'like', "$value%");
35
    }
36
37 1
    public function scopeNameEndsWith(Builder $query, string $value)
38
    {
39 1
        return $query->where($this->locationNameColumn(), 'like', "$value%");
40
    }
41
}
42