Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
TaxGroupItem
100.00% covered (success)
100.00%
9 / 9
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%
8 / 8
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 entity representing an individual tax rate component within a Tax Group.
13 */
14final readonly class TaxGroupItem
15{
16    /**
17     * TaxGroupItem constructor.
18     *
19     * @param int|null $id Database primary key
20     * @param int $taxGroupId Associated tax group ID
21     * @param int $taxRateId Target tax rate ID
22     * @param int $sequenceOrder Order of calculation
23     * @param bool $isCompound True if calculated on base + preceding taxes
24     * @param TaxRate|null $taxRate Optional resolved TaxRate model
25     */
26    public function __construct(
27        public ?int $id,
28        public int $taxGroupId,
29        public int $taxRateId,
30        public int $sequenceOrder = 1,
31        public bool $isCompound = false,
32        public ?TaxRate $taxRate = null,
33    ) {
34    }
35
36    /**
37     * Convert to array representation.
38     *
39     * @return array<string, mixed>
40     */
41    public function toArray(): array
42    {
43        return [
44            'id' => $this->id,
45            'tax_group_id' => $this->taxGroupId,
46            'tax_rate_id' => $this->taxRateId,
47            'sequence_order' => $this->sequenceOrder,
48            'is_compound' => $this->isCompound,
49            'tax_rate' => $this->taxRate?->toArray(),
50        ];
51    }
52}