Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
13 / 13 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| AddressOrderGroupDTO | |
100.00% |
13 / 13 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| toArray | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| fromRequest | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Domain\Address\DTOs; |
| 4 | |
| 5 | use App\Models\Team\Team; |
| 6 | use Domain\Shared\Interfaces\DataTransferObjectInterface; |
| 7 | use Illuminate\Foundation\Http\FormRequest; |
| 8 | |
| 9 | readonly final class AddressOrderGroupDTO implements DataTransferObjectInterface |
| 10 | { |
| 11 | public string $description; |
| 12 | public int $order; |
| 13 | public Team $team; |
| 14 | |
| 15 | public function __construct(array $args) |
| 16 | { |
| 17 | $this->description = $args['description']; |
| 18 | $this->order = $args['order']; |
| 19 | $this->team = $args['team']; |
| 20 | } |
| 21 | |
| 22 | public function toArray(): array |
| 23 | { |
| 24 | return [ |
| 25 | 'description' => $this->description, |
| 26 | 'order' => $this->order, |
| 27 | 'team_id' => $this->team->getKey(), |
| 28 | ]; |
| 29 | } |
| 30 | |
| 31 | public static function fromRequest(FormRequest $request): AddressOrderGroupDTO |
| 32 | { |
| 33 | return new self([ |
| 34 | 'description' => $request->validated('description'), |
| 35 | 'order' => $request->validated('order'), |
| 36 | 'team' => Team::find($request->validated('team_id')), |
| 37 | ]); |
| 38 | } |
| 39 | } |