Passed
Pull Request — main (#8)
by Alex
03:11 queued 01:35
created

Money::equal()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 3
cts 3
cp 1
crap 2
1
<?php
2
3
namespace StraTDeS\VO\Single;
4
5
class Money
6
{
7
    private int $amount;
8
    private Currency $currency;
9
10 8
    private function __construct(int $amount, Currency $currency)
11
    {
12 8
        $this->amount = $amount;
13 8
        $this->currency = $currency;
14 8
    }
15
16 8
    public static function create(int $amount, Currency $currency): Money
17
    {
18 8
        return new self($amount, $currency);
19
    }
20
21 3
    public function amount(): int
22
    {
23 3
        return $this->amount;
24
    }
25
26 3
    public function amountFloat(): float
27
    {
28 3
        return (float)($this->amount() / pow(10, $this->currency->config()->decimals()));
29
    }
30
31 3
    public function currency(): Currency
32
    {
33 3
        return $this->currency;
34
    }
35
36 3
    public function formatted(string $thousandsSeparator = ',', string $decimalsSeparator = '.'): string
37
    {
38 3
        return $this->currency->value() . ' ' .
39 3
            number_format(
40 3
                $this->amountFloat(),
41 3
                $this->currency->config()->decimals(),
42
                $decimalsSeparator,
43
                $thousandsSeparator
44
            );
45
    }
46
47 3
    public function equal(Money $money): bool
48
    {
49 3
        return $this->amount == $money->amount &&
50 3
            $this->currency->equal($money->currency);
51
    }
52
}
53