Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
25 / 25 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| RequestUpdateDTO | |
100.00% |
25 / 25 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
| toArray | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
1 | |||
| fromRequest | |
100.00% |
9 / 9 |
|
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 Domain\Shared\Interfaces\DataTransferObjectInterface; |
| 10 | |
| 11 | readonly final class RequestUpdateDTO implements DataTransferObjectInterface |
| 12 | { |
| 13 | public ?string $applicant_badge; |
| 14 | public ?string $applicant_name; |
| 15 | public ?string $resource_code; |
| 16 | public ?string $resource_description; |
| 17 | public ?array $items; |
| 18 | public ?CostCenter $cost_center; |
| 19 | public ?ResourceCenter $resource_center; |
| 20 | |
| 21 | public function __construct(array $args) |
| 22 | { |
| 23 | $this->applicant_badge = $args['applicant_badge'] ?? null; |
| 24 | $this->applicant_name = $args['applicant_name'] ?? null; |
| 25 | $this->resource_code = $args['resource_code'] ?? null; |
| 26 | $this->resource_description = $args['resource_description'] ?? null; |
| 27 | $this->cost_center = $args['cost_center'] ?? null; |
| 28 | $this->resource_center = $args['resource_center'] ?? null; |
| 29 | $this->items = $args['items'] ?? []; |
| 30 | } |
| 31 | |
| 32 | public function toArray(): array |
| 33 | { |
| 34 | return [ |
| 35 | 'applicant_badge' => $this->applicant_badge, |
| 36 | 'applicant_name' => $this->applicant_name, |
| 37 | 'resource_code' => $this->resource_code, |
| 38 | 'resource_description' => $this->resource_description, |
| 39 | 'resource_center' => $this->resource_center, |
| 40 | 'cost_center' => $this->cost_center, |
| 41 | 'items' => $this->items, |
| 42 | ]; |
| 43 | } |
| 44 | |
| 45 | public static function fromRequest(FormRequest $request): RequestUpdateDTO |
| 46 | { |
| 47 | return new self([ |
| 48 | 'applicant_badge' => $request->validated('applicant_badge'), |
| 49 | 'applicant_name' => $request->validated('applicant_name'), |
| 50 | 'resource_code' => $request->validated('resource_code'), |
| 51 | 'resource_description' => $request->validated('resource_description'), |
| 52 | 'resource_center' => ResourceCenter::find($request->validated('resource_center_id')), |
| 53 | 'cost_center' => CostCenter::find($request->validated('cost_center_id')), |
| 54 | 'items' => $request->validated('items'), |
| 55 | ]); |
| 56 | } |
| 57 | } |