Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
12 / 12 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| TaxRuleDto | |
100.00% |
11 / 11 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| fromArray | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** @license For full copyright and license information, please see the LICENSE.md file. */ |
| 6 | |
| 7 | namespace App\Modules\Tax\Application\DTO; |
| 8 | |
| 9 | defined('AMMONLY_APP') || exit('Direct script access is forbidden.'); |
| 10 | |
| 11 | /** |
| 12 | * Data Transfer Object for creating or updating a TaxRule. |
| 13 | */ |
| 14 | final readonly class TaxRuleDto |
| 15 | { |
| 16 | /** |
| 17 | * TaxRuleDto constructor. |
| 18 | */ |
| 19 | public function __construct( |
| 20 | public ?int $id, |
| 21 | public string $ruleName, |
| 22 | public int $priority = 10, |
| 23 | public string $customerType = 'all', |
| 24 | public string $geoZone = 'domestic', |
| 25 | public string $itemType = 'all', |
| 26 | public int $targetTaxRateId = 0, |
| 27 | public bool $isActive = true, |
| 28 | ) { |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Create DTO from raw array. |
| 33 | * |
| 34 | * @param array<string, mixed> $data |
| 35 | */ |
| 36 | public static function fromArray(array $data, ?int $id = null): self |
| 37 | { |
| 38 | return new self( |
| 39 | id: $id ?? (isset($data['id']) ? (int) $data['id'] : null), |
| 40 | ruleName: trim((string) ($data['rule_name'] ?? '')), |
| 41 | priority: (int) ($data['priority'] ?? 10), |
| 42 | customerType: (string) ($data['customer_type'] ?? 'all'), |
| 43 | geoZone: (string) ($data['geo_zone'] ?? 'domestic'), |
| 44 | itemType: (string) ($data['item_type'] ?? 'all'), |
| 45 | targetTaxRateId: (int) ($data['target_tax_rate_id'] ?? 0), |
| 46 | isActive: isset($data['is_active']) ? (bool) $data['is_active'] : true, |
| 47 | ); |
| 48 | } |
| 49 | } |