Passed
Push — 1.0.0 ( f58402...681a4e )
by Alex
01:36
created

Money::currency()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
ccs 2
cts 2
cp 1
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace StraTDeS\VO;
4
5
class Money
6
{
7
    private int $amount;
8
    private Currency $currency;
9
10 3
    private function __construct(int $amount, Currency $currency)
11
    {
12 3
        $this->amount = $amount;
13 3
        $this->currency = $currency;
14 3
    }
15
16 3
    public static function create(int $amount, Currency $currency): Money
17
    {
18 3
        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