Passed
Push — main ( 7e82e7...91ee3f )
by Michael
03:29
created

Decimal   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 5
c 0
b 0
f 0
dl 0
loc 28
ccs 4
cts 4
cp 1
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A value() 0 3 1
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MichaelRubel\ValueObjects\Collection\Primitive;
6
7
use MichaelRubel\ValueObjects\Concerns\SanitizesNumbers;
8
use MichaelRubel\ValueObjects\ValueObject;
9
use PHP\Math\BigNumber\BigNumber;
10
11
/**
12
 * @method static static make(int|float|string|null $number, int $scale = 2)
13
 */
14
class Decimal extends ValueObject
15
{
16
    use SanitizesNumbers;
17
18
    /**
19
     * @var BigNumber
20
     */
21
    protected BigNumber $number;
22
23
    /**
24
     * Create a new instance of the value object.
25
     *
26
     * @param  int|float|string|null  $number
27
     * @param  int  $scale
28
     */
29 12
    public function __construct(int|float|string|null $number, protected int $scale = 2)
30
    {
31 12
        $this->number = new BigNumber($this->sanitize($number), $this->scale);
32
    }
33
34
    /**
35
     * Get the object value.
36
     *
37
     * @return string
38
     */
39 11
    public function value(): string
40
    {
41 11
        return (string) $this->number;
42
    }
43
}
44