Passed
Push — master ( 36df2b...89c2b4 )
by noitran
03:13
created

ListOfValues::getValues()   A

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
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Noitran\Repositories\Criteria;
4
5
use Noitran\Repositories\Contracts\Criteria\CriteriaInterface;
6
use Noitran\Repositories\Contracts\Repository\RepositoryInterface;
7
use Illuminate\Database\Eloquent\Builder;
8
9
/**
10
 * Class ListOfValues
11
 */
12
abstract class ListOfValues implements CriteriaInterface
13
{
14
    /**
15
     * @var array
16
     */
17
    protected $values;
18
19
    /**
20
     * ListOfValues constructor.
21
     *
22
     * @param string $valueList Comma separated sting of values
23
     */
24 1
    final public function __construct($valueList)
25
    {
26 1
        $this->values = explode(',', $valueList);
27 1
    }
28
29
    /**
30
     * Returns field name in schema
31
     *
32
     * @return mixed
33
     */
34
    abstract protected function getField(): string;
35
36
    /**
37
     * @return array
38
     */
39 1
    public function getValues(): array
40
    {
41 1
        return $this->values;
42
    }
43
44
    /**
45
     * @param Builder $model
46
     * @param RepositoryInterface $repository
47
     *
48
     * @return Builder
49
     */
50 1
    public function apply($model, RepositoryInterface $repository): Builder
51
    {
52 1
        $column = $repository->getColumnName($this->getField(), $model);
0 ignored issues
show
Bug introduced by
The method getColumnName() does not exist on Noitran\Repositories\Con...ory\RepositoryInterface. It seems like you code against a sub-type of said class. However, the method does not exist in Noitran\Repositories\Tes...sitories\UserRepository. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

52
        /** @scrutinizer ignore-call */ 
53
        $column = $repository->getColumnName($this->getField(), $model);
Loading history...
53
54 1
        return $model->whereIn($column, $this->getValues());
0 ignored issues
show
Bug Best Practice introduced by
The expression return $model->whereIn($...mn, $this->getValues()) could return the type Illuminate\Database\Query\Builder which is incompatible with the type-hinted return Illuminate\Database\Eloquent\Builder. Consider adding an additional type-check to rule them out.
Loading history...
55
    }
56
}
57