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

Decimal::value()   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
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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