Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 17 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| CustomerDTO | |
0.00% |
0 / 17 |
|
0.00% |
0 / 3 |
20 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
| toArray | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
| fromRequest | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Domain\Customer\DTOs; |
| 4 | |
| 5 | use App\Models\Team\Team; |
| 6 | use Domain\Customer\Enums\CustomerStatusEnum; |
| 7 | use Domain\Integration\DTOs\IntegrationCustomerDTO; |
| 8 | use Domain\Shared\Interfaces\DataTransferObjectInterface; |
| 9 | use Illuminate\Foundation\Http\FormRequest; |
| 10 | |
| 11 | final readonly class CustomerDTO implements DataTransferObjectInterface |
| 12 | { |
| 13 | public string $description; |
| 14 | public CustomerStatusEnum $customerStatusEnum; |
| 15 | public ?IntegrationCustomerDTO $integrationCustomerDTO; |
| 16 | public ?Team $team; |
| 17 | |
| 18 | public function __construct(array $args) |
| 19 | { |
| 20 | $this->description = $args['description']; |
| 21 | $this->customerStatusEnum = $args['status']; |
| 22 | $this->team = $args['team'] ?? null; |
| 23 | $this->integrationCustomerDTO = isset($args['integration_code']) ? new IntegrationCustomerDTO([ |
| 24 | 'integration_code' => $args['integration_code'], |
| 25 | ]) : null; |
| 26 | } |
| 27 | |
| 28 | public function toArray(): array |
| 29 | { |
| 30 | return [ |
| 31 | 'description' => $this->description, |
| 32 | 'status' => $this->customerStatusEnum->value, |
| 33 | 'team_id' => $this->team?->getKey(), |
| 34 | 'integration_code' => $this->integrationCustomerDTO?->integrationCode, |
| 35 | ]; |
| 36 | } |
| 37 | |
| 38 | public static function fromRequest(FormRequest $request): CustomerDTO |
| 39 | { |
| 40 | return new self([ |
| 41 | 'description' => $request->validated('description'), |
| 42 | 'status' => CustomerStatusEnum::tryFrom($request->validated('status')), |
| 43 | 'team' => Team::find($request->validated('team_id')), |
| 44 | ]); |
| 45 | } |
| 46 | } |