Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
DiscountRate
100.00% covered (success)
100.00%
13 / 13
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%
12 / 12
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\Discount\Domain\Model;
8
9defined('AMMONLY_APP') || exit('Direct script access is forbidden.');
10
11use App\Modules\Discount\Domain\ValueObject\DiscountType;
12
13/**
14 * Domain Aggregate Root representing a discount rate configuration.
15 */
16final class DiscountRate
17{
18    /**
19     * DiscountRate constructor.
20     *
21     * @param int|null      $id            Database primary key ID
22     * @param string        $discountCode  Unique identifying code (e.g. RABAT_5)
23     * @param string        $discountName  Descriptive name of the discount
24     * @param DiscountType  $discountType  Calculation mode (percentage or fixed amount)
25     * @param float         $discountValue Numerical value of discount
26     * @param bool          $isDefault     Flag indicating if this is default discount
27     * @param bool          $isActive      Flag indicating if discount is currently active
28     * @param int           $owner         User ID of the owner
29     * @param string|null   $createdAt     Timestamp of creation
30     * @param string|null   $updatedAt     Timestamp of last update
31     */
32    public function __construct(
33        public ?int $id,
34        public string $discountCode,
35        public string $discountName,
36        public DiscountType $discountType,
37        public float $discountValue,
38        public bool $isDefault = false,
39        public bool $isActive = true,
40        public int $owner = 1,
41        public ?string $createdAt = null,
42        public ?string $updatedAt = null,
43    ) {
44    }
45
46    /**
47     * Convert DiscountRate aggregate to associative array.
48     *
49     * @return array<string, mixed>
50     */
51    public function toArray(): array
52    {
53        return [
54            'id' => $this->id,
55            'discount_code' => $this->discountCode,
56            'discount_name' => $this->discountName,
57            'discount_type' => $this->discountType->value,
58            'discount_value' => $this->discountValue,
59            'is_default' => $this->isDefault,
60            'is_active' => $this->isActive,
61            'owner' => $this->owner,
62            'created_at' => $this->createdAt,
63            'updated_at' => $this->updatedAt,
64        ];
65    }
66}