Passed
Push — master ( 0099ad...e2777a )
by Stephen
09:13 queued 06:59
created

AddressBuilder::whereAddressLike()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 7
c 1
b 1
f 0
nc 1
nop 1
dl 0
loc 11
rs 10
1
<?php
2
3
namespace Sfneal\Address\Builders;
4
5
use Sfneal\Builders\QueryBuilder;
6
7
class AddressBuilder extends QueryBuilder
8
{
9
    /**
10
     * Scope query results to Address's associated with a particular model.
11
     *
12
     * @param string $addressableType
13
     * @param string $operator
14
     * @param string $boolean
15
     *
16
     * @return $this
17
     */
18
    public function whereType(string $addressableType, string $operator = '=', string $boolean = 'and')
19
    {
20
        $this->where('addressable_type', $operator, $addressableType, $boolean);
21
22
        return $this;
23
    }
24
25
    /**
26
     * Use a 'wildcard' like search to several attributes for a match.
27
     *
28
     * @param string $search
29
     *
30
     * @return $this
31
     */
32
    public function whereAddressLike(string $search)
33
    {
34
        $this->where(function (self $builder) use ($search) {
35
            $builder->whereLike('address_1', $search);
36
            $builder->orWhereLike('address_2', $search);
37
            $builder->orWhereLike('city', $search);
38
            $builder->orWhereLike('state', $search);
39
            $builder->orWhereLike('zip', $search);
40
        });
41
42
        return $this;
43
    }
44
}
45