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