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

Money   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 15
c 1
b 0
f 0
dl 0
loc 39
rs 10
ccs 17
cts 17
cp 1

6 Methods

Rating   Name   Duplication   Size   Complexity  
A currency() 0 3 1
A __construct() 0 4 1
A amount() 0 3 1
A amountFloat() 0 3 1
A create() 0 3 1
A formatted() 0 8 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