Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| PackagingQueryBuilder | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
30 | |
0.00% |
0 / 1 |
| search | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
30 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Domain\Packaging\QueryBuilders; |
| 4 | |
| 5 | use Domain\Packaging\DTOs\PackagingSearchDTO; |
| 6 | use Illuminate\Database\Eloquent\Builder; |
| 7 | use function str_replace; |
| 8 | |
| 9 | class PackagingQueryBuilder extends Builder |
| 10 | { |
| 11 | public function search(PackagingSearchDTO $packagingSearchDTO): static |
| 12 | { |
| 13 | |
| 14 | if ($packagingSearchDTO->id) { |
| 15 | $this->where('id', $packagingSearchDTO->id); |
| 16 | } |
| 17 | |
| 18 | if ($packagingSearchDTO->type) { |
| 19 | $this->where('type', $packagingSearchDTO->type->value); |
| 20 | } |
| 21 | |
| 22 | if ($packagingSearchDTO->description) { |
| 23 | $searchTerm = str_replace(' ', '%', $packagingSearchDTO->description); |
| 24 | $this->where('description', 'ILIKE', '%' . $searchTerm . '%'); |
| 25 | } |
| 26 | |
| 27 | if ($packagingSearchDTO->codemb) { |
| 28 | $this->whereHas('integration', function (Builder $query) use ($packagingSearchDTO) { |
| 29 | $query->where('parameters->CODEMB', $packagingSearchDTO->codemb); |
| 30 | }); |
| 31 | } |
| 32 | |
| 33 | |
| 34 | return $this; |
| 35 | } |
| 36 | } |