Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
64.29% |
18 / 28 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| TransactionSearchDTO | |
64.29% |
18 / 28 |
|
66.67% |
2 / 3 |
3.41 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
1 | |||
| toArray | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
2 | |||
| fromRequest | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Domain\Transaction\DTOs; |
| 4 | |
| 5 | use App\Models\Product\Product; |
| 6 | use App\Models\User; |
| 7 | |
| 8 | use Domain\Shared\Interfaces\DataTransferObjectInterface; |
| 9 | |
| 10 | use Domain\Shared\Traits\DateRangeDTOTrait; |
| 11 | use Domain\Transaction\Enums\TransactionTypeEnum; |
| 12 | use Illuminate\Foundation\Http\FormRequest; |
| 13 | |
| 14 | readonly final class TransactionSearchDTO implements DataTransferObjectInterface |
| 15 | { |
| 16 | use DateRangeDTOTrait; |
| 17 | |
| 18 | public ?string $productionOrder; |
| 19 | public ?string $integrationCode; |
| 20 | public ?string $priorityValue; |
| 21 | public ?User $user; |
| 22 | public ?Product $product; |
| 23 | public ?array $type; |
| 24 | public ?array $created_at; |
| 25 | public ?array $reason; |
| 26 | |
| 27 | public function __construct(array $args) |
| 28 | { |
| 29 | $this->productionOrder = $args['production_order'] ?? null; |
| 30 | $this->integrationCode = $args['integration_code'] ?? null; |
| 31 | $this->priorityValue = $args['priority_value'] ?? null; |
| 32 | $this->user = $args['user'] ?? null; |
| 33 | $this->product = $args['product'] ?? null; |
| 34 | $this->type = $args['type'] ?? []; |
| 35 | $this->created_at = $args['created_at'] ?? null; |
| 36 | $this->reason = $args['reason'] ?? []; |
| 37 | } |
| 38 | |
| 39 | public function toArray(): array |
| 40 | { |
| 41 | return [ |
| 42 | 'production_order' => $this->productionOrder, |
| 43 | 'integration_code' => $this->integrationCode, |
| 44 | 'priority_value' => $this->priorityValue, |
| 45 | 'user' => $this->user, |
| 46 | 'product' => $this->product, |
| 47 | 'type' => $this->type, |
| 48 | 'created_at' => $this->created_at, |
| 49 | 'reason' => $this->reason, |
| 50 | |
| 51 | ]; |
| 52 | } |
| 53 | |
| 54 | public static function fromRequest(FormRequest $request): TransactionSearchDTO |
| 55 | { |
| 56 | return new self([ |
| 57 | 'production_order' => $request->validated('production_order'), |
| 58 | 'integration_code' => $request->validated('integration_code'), |
| 59 | 'priority_value' => $request->validated('priority_value'), |
| 60 | 'user' => User::find($request->validated('user_id')), |
| 61 | 'product' => Product::find($request->validated('product_id')), |
| 62 | 'type' => $request->validated('type'), |
| 63 | 'created_at' => self::processDate($request->validated('created_at'), 'd/m/Y H:i:s'), |
| 64 | 'reason' => $request->validated('reason'), |
| 65 | ]); |
| 66 | } |
| 67 | } |