Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| CustomerQueryBuilder | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
20 | |
0.00% |
0 / 1 |
| search | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
20 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Domain\Customer\QueryBuilder; |
| 4 | |
| 5 | use Domain\Customer\DTOs\CustomerSearchDTO; |
| 6 | use Illuminate\Database\Eloquent\Builder; |
| 7 | use Illuminate\Support\Facades\DB; |
| 8 | use function strtolower; |
| 9 | |
| 10 | class CustomerQueryBuilder extends Builder |
| 11 | { |
| 12 | public function search(CustomerSearchDTO $searchDTO): static |
| 13 | { |
| 14 | if ($searchDTO->id) { |
| 15 | $this->query->where('id', $searchDTO->id); |
| 16 | } |
| 17 | |
| 18 | if ($searchDTO->description) { |
| 19 | $preparedValue = '%' . strtolower(str_replace(' ', '%', $searchDTO->description)) . '%'; |
| 20 | $this->query->where(DB::raw('LOWER(description)'), 'ilike', $preparedValue); |
| 21 | } |
| 22 | |
| 23 | if ($searchDTO->integrationCode) { |
| 24 | $this->whereHas('integration', function ($query) use ($searchDTO) { |
| 25 | $query->where('parameters->integration_code', $searchDTO->integrationCode); |
| 26 | }); |
| 27 | } |
| 28 | |
| 29 | return $this; |
| 30 | } |
| 31 | } |