Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
90.91% covered (success)
90.91%
30 / 33
82.35% covered (warning)
82.35%
14 / 17
CRAP
0.00% covered (danger)
0.00%
0 / 1
Currency
90.62% covered (success)
90.62%
29 / 32
82.35% covered (warning)
82.35%
14 / 17
20.33
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getCode
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getSymbol
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getExchangeRate
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setExchangeRate
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getNbpTableNo
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setNbpTableNo
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getEffectiveDate
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setEffectiveDate
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 isBase
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isActive
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getSortOrder
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 updateExchangeRate
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
2
 toArray
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
3
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\Currencies\Domain\Model;
8
9defined('AMMONLY_APP') || exit('Direct script access is forbidden.');
10
11/**
12 * Currency Domain Entity.
13 */
14final class Currency
15{
16    private string $code;
17
18    public function __construct(
19        private ?int $id,
20        string $code,
21        private string $name,
22        private string $symbol,
23        private float $exchangeRate = 1.0,
24        private ?string $nbpTableNo = null,
25        private ?string $effectiveDate = null,
26        private bool $isBase = false,
27        private bool $isActive = true,
28        private int $sortOrder = 10
29    ) {
30        $this->code = strtoupper($code);
31    }
32
33    public function getId(): ?int
34    {
35        return $this->id;
36    }
37
38    public function setId(int $id): void
39    {
40        $this->id = $id;
41    }
42
43    public function getCode(): string
44    {
45        return $this->code;
46    }
47
48    public function getName(): string
49    {
50        return $this->name;
51    }
52
53    public function getSymbol(): string
54    {
55        return $this->symbol;
56    }
57
58    public function getExchangeRate(): float
59    {
60        return $this->exchangeRate;
61    }
62
63    public function setExchangeRate(float $rate): void
64    {
65        $this->exchangeRate = $rate;
66    }
67
68    public function getNbpTableNo(): ?string
69    {
70        return $this->nbpTableNo;
71    }
72
73    public function setNbpTableNo(?string $tableNo): void
74    {
75        $this->nbpTableNo = $tableNo;
76    }
77
78    public function getEffectiveDate(): ?string
79    {
80        return $this->effectiveDate;
81    }
82
83    public function setEffectiveDate(?string $date): void
84    {
85        $this->effectiveDate = $date;
86    }
87
88    public function isBase(): bool
89    {
90        return $this->isBase;
91    }
92
93    public function isActive(): bool
94    {
95        return $this->isActive;
96    }
97
98    public function getSortOrder(): int
99    {
100        return $this->sortOrder;
101    }
102
103    public function updateExchangeRate(float $rate, ?string $tableNo, ?string $effectiveDate): void
104    {
105        if ($this->isBase) {
106            return;
107        }
108        $this->exchangeRate = $rate;
109        $this->nbpTableNo = $tableNo;
110        $this->effectiveDate = $effectiveDate;
111    }
112
113    /**
114     * @return array<string, mixed>
115     */
116    public function toArray(): array
117    {
118        return [
119            'id' => $this->id,
120            'code' => $this->code,
121            'name' => $this->name,
122            'symbol' => $this->symbol,
123            'exchange_rate' => $this->exchangeRate,
124            'nbp_table_no' => $this->nbpTableNo,
125            'effective_date' => $this->effectiveDate,
126            'is_base' => $this->isBase ? 1 : 0,
127            'is_active' => $this->isActive ? 1 : 0,
128            'sort_order' => $this->sortOrder,
129        ];
130    }
131}