Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
TaxGroup
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 toArray
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5/** @license For full copyright and license information, please see the LICENSE.md file. */
6
7namespace App\Modules\Tax\Domain\Model;
8
9defined('AMMONLY_APP') || exit('Direct script access is forbidden.');
10
11/**
12 * Domain aggregate representing a Tax Group composed of multiple tax rates.
13 */
14final class TaxGroup
15{
16    /**
17     * TaxGroup constructor.
18     *
19     * @param int|null $id Database primary key
20     * @param string $groupCode Unique identifier code (e.g. USA_NY_TAX)
21     * @param string $groupName Display name of tax group
22     * @param string|null $description Optional description
23     * @param bool $isActive Availability flag
24     * @param TaxGroupItem[] $items Tax rates included in this group
25     * @param int $owner User ID of the owner
26     * @param string|null $createdAt Creation timestamp
27     * @param string|null $updatedAt Last update timestamp
28     */
29    public function __construct(
30        public ?int $id,
31        public string $groupCode,
32        public string $groupName,
33        public ?string $description = null,
34        public bool $isActive = true,
35        public array $items = [],
36        public int $owner = 1,
37        public ?string $createdAt = null,
38        public ?string $updatedAt = null,
39    ) {
40    }
41
42    /**
43     * Convert TaxGroup to associative array.
44     *
45     * @return array<string, mixed>
46     */
47    public function toArray(): array
48    {
49        return [
50            'id' => $this->id,
51            'group_code' => $this->groupCode,
52            'group_name' => $this->groupName,
53            'description' => $this->description,
54            'is_active' => $this->isActive,
55            'items' => array_map(
56                static fn(TaxGroupItem $item): array => $item->toArray(),
57                $this->items
58            ),
59            'owner' => $this->owner,
60            'created_at' => $this->createdAt,
61            'updated_at' => $this->updatedAt,
62        ];
63    }
64}