| Conditions | 6 |
| Paths | 17 |
| Total Lines | 26 |
| Code Lines | 17 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 11 |
| CRAP Score | 7.0986 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 29 | 2 | public function apply($query) |
|
| 30 | { |
||
| 31 | 2 | $value = $this->value(); |
|
| 32 | 2 | if (is_null($value)) { |
|
| 33 | 1 | return; |
|
| 34 | } |
||
| 35 | |||
| 36 | 1 | $leftPart = $this->like['left'] ? '%' : ''; |
|
| 37 | 1 | $rightPart = $this->like['right'] ? '%' : ''; |
|
| 38 | 1 | $sign = array_filter($this->like) ? 'like' : $this->sign; |
|
| 39 | |||
| 40 | 1 | if ($this->field()->isRelationField()) { |
|
| 41 | $query->whereHas($this->field()->getRelationMethod(), function ($query) use ($value, $sign, $leftPart, $rightPart) { |
||
| 42 | $query->where( |
||
| 43 | $this->field()->getRelationTitleField(), |
||
| 44 | $sign, |
||
| 45 | $leftPart . $value . $rightPart |
||
| 46 | ); |
||
| 47 | }); |
||
| 48 | return; |
||
| 49 | } |
||
| 50 | |||
| 51 | 1 | $query->where( |
|
| 52 | 1 | $this->field->name(), |
|
| 53 | $sign, |
||
| 54 | 1 | $leftPart . $value . $rightPart |
|
| 55 | ); |
||
| 58 |