Passed
Push — master ( 257b57...81bbde )
by Adel
03:02
created

Money::getAmount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Domain\ValueObjects;
4
5
use Doctrine\ORM\Mapping AS ORM;
6
7
/** @ORM\Embeddable */
8
final class Money
9
{
10
    /**
11
     * @var int
12
     * @ORM\Column(type="integer")
13
     */
14
    private $amount;
15
16
    private function __construct(int $amount)
17
    {
18
        if ($amount < 0) {
19
            throw new \InvalidArgumentException('Money value cannot be negative');
20
        }
21
22
        $this->amount = $amount;
23
    }
24
25
    public static function dollars(float $amount): Money
26
    {
27
        return new Money(round($amount * 100));
0 ignored issues
show
Bug introduced by
round($amount * 100) of type double is incompatible with the type integer expected by parameter $amount of App\Domain\ValueObjects\Money::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

27
        return new Money(/** @scrutinizer ignore-type */ round($amount * 100));
Loading history...
28
    }
29
30
    public static function cents(int $amount): Money
31
    {
32
        return new Money($amount);
33
    }
34
35
    public function equals(Money $other): bool
36
    {
37
        return $this->amount === $other->amount;
38
    }
39
}