Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
64.29% |
18 / 28 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| RequestDTO | |
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\Request\DTOs; |
| 4 | |
| 5 | use App\Models\CostCenter\CostCenter; |
| 6 | use App\Models\CostCenter\ResourceCenter; |
| 7 | use Illuminate\Foundation\Http\FormRequest; |
| 8 | |
| 9 | use App\Models\User; |
| 10 | |
| 11 | use Domain\Shared\Interfaces\DataTransferObjectInterface; |
| 12 | |
| 13 | readonly final class RequestDTO implements DataTransferObjectInterface |
| 14 | { |
| 15 | public CostCenter $costCenter; |
| 16 | public ResourceCenter $resourceCenter; |
| 17 | public string $resource_code; |
| 18 | public string $resource_description; |
| 19 | public bool $urgent; |
| 20 | public array $items; |
| 21 | public string $applicant_badge; |
| 22 | public ?string $applicant_name; |
| 23 | |
| 24 | public function __construct(array $args) |
| 25 | { |
| 26 | $this->costCenter = $args['costCenter']; |
| 27 | $this->resourceCenter = $args['resourceCenter']; |
| 28 | $this->resource_code = $args['resource_code']; |
| 29 | $this->resource_description = $args['resource_description']; |
| 30 | $this->urgent = $args['urgent']; |
| 31 | $this->items = $args['items']; |
| 32 | $this->applicant_badge = $args['applicant_badge']; |
| 33 | $this->applicant_name = $args['applicant_name'] ?? null; |
| 34 | } |
| 35 | |
| 36 | public function toArray(): array |
| 37 | { |
| 38 | return [ |
| 39 | 'costCenter' => $this->costCenter, |
| 40 | 'resourceCenter' => $this->resourceCenter, |
| 41 | 'resource_code' => $this->resource_code, |
| 42 | 'resource_description' => $this->resource_description, |
| 43 | 'urgent' => $this->urgent, |
| 44 | 'items' => $this->items, |
| 45 | 'applicant_badge' => $this->applicant_badge, |
| 46 | 'applicant_name' => $this->applicant_name, |
| 47 | ]; |
| 48 | } |
| 49 | |
| 50 | public static function fromRequest(FormRequest $request): RequestDTO |
| 51 | { |
| 52 | return new self([ |
| 53 | 'costCenter' => CostCenter::find($request->validated('cost_center_id')), |
| 54 | 'resourceCenter' => ResourceCenter::find($request->validated('resource_center_id')), |
| 55 | 'resource_code' => $request->validated('resource_code'), |
| 56 | 'resource_description' => $request->validated('resource_description'), |
| 57 | 'urgent' => $request->validated('urgent'), |
| 58 | 'items' => $request->validated('items'), |
| 59 | 'applicant_badge' => $request->validated('applicant_badge'), |
| 60 | 'applicant_name' => $request->validated('applicant_name') |
| 61 | ]); |
| 62 | } |
| 63 | } |