ListOfValues::apply()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 5
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Noitran\Repositories\Criteria;
6
7
use Illuminate\Database\Eloquent\Builder;
8
use Noitran\Repositories\Contracts\Criteria\CriteriaInterface;
9
use Noitran\Repositories\Contracts\Repository\RepositoryInterface;
10
11
/**
12
 * Class ListOfValues.
13
 */
14
abstract class ListOfValues implements CriteriaInterface
15
{
16
    /**
17
     * @var array
18
     */
19
    protected $values;
20
21
    /**
22
     * ListOfValues constructor.
23
     *
24 1
     * @param string $valueList Comma separated sting of values
25
     */
26 1
    final public function __construct($valueList)
27 1
    {
28
        $this->values = explode(',', $valueList);
29
    }
30
31
    /**
32
     * Returns field name in schema.
33
     *
34
     * @return mixed
35
     */
36
    abstract protected function getField(): string;
37
38
    /**
39 1
     * @return array
40
     */
41 1
    public function getValues(): array
42
    {
43
        return $this->values;
44
    }
45
46
    /**
47
     * @param Builder $model
48
     * @param RepositoryInterface $repository
49
     *
50 1
     * @return Builder
51
     */
52 1
    public function apply($model, RepositoryInterface $repository) //: Builder
53
    {
54 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

54
        /** @scrutinizer ignore-call */ 
55
        $column = $repository->getColumnName($this->getField(), $model);
Loading history...
55
56
        return $model->whereIn($column, $this->getValues());
0 ignored issues
show
Bug Best Practice introduced by
The expression return $model->whereIn($...mn, $this->getValues()) also could return the type Illuminate\Database\Query\Builder which is incompatible with the documented return type Illuminate\Database\Eloquent\Builder.
Loading history...
57
    }
58
}
59