Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 19 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| ReadingLogDTO | |
0.00% |
0 / 19 |
|
0.00% |
0 / 3 |
12 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| toArray | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
| fromRequest | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Domain\ReadingLog\DTOs; |
| 4 | |
| 5 | use Carbon\Carbon; |
| 6 | use Domain\ReadingLog\Enums\ReadingLogFormatEnum; |
| 7 | use Domain\ReadingLog\Enums\ReadingLogTypeEnum; |
| 8 | use Domain\Shared\Interfaces\DataTransferObjectInterface; |
| 9 | use Illuminate\Foundation\Http\FormRequest; |
| 10 | |
| 11 | readonly final class ReadingLogDTO implements DataTransferObjectInterface |
| 12 | { |
| 13 | public ReadingLogTypeEnum $type; |
| 14 | public ReadingLogFormatEnum $format; |
| 15 | public string $data; |
| 16 | public Carbon $readAt; |
| 17 | public bool $isValid; |
| 18 | |
| 19 | public function __construct(array $args) |
| 20 | { |
| 21 | $this->type = $args['type']; |
| 22 | $this->data = $args['data']; |
| 23 | $this->readAt = $args['read_at']; |
| 24 | $this->format = $args['format']; |
| 25 | $this->isValid = $args['is_valid']; |
| 26 | } |
| 27 | |
| 28 | public function toArray(): array |
| 29 | { |
| 30 | return [ |
| 31 | 'type' => $this->type->value, |
| 32 | 'format' => $this->format->value, |
| 33 | 'data' => $this->data, |
| 34 | 'read_at' => $this->readAt, |
| 35 | 'is_valid' => $this->isValid, |
| 36 | ]; |
| 37 | } |
| 38 | |
| 39 | public static function fromRequest(FormRequest $request): DataTransferObjectInterface |
| 40 | { |
| 41 | return new self([ |
| 42 | 'type' => ReadingLogTypeEnum::tryFrom($request->validated('type')), |
| 43 | 'format' => ReadingLogFormatEnum::tryFrom($request->validated('format')), |
| 44 | 'data' => $request->validated('data'), |
| 45 | 'read_at' => Carbon::createFromFormat('d/m/Y H:i:s', $request->validated('read_at')), |
| 46 | 'is_valid' => $request->validated('is_valid'), |
| 47 | ]); |
| 48 | } |
| 49 | } |