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

Money   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 30
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A cents() 0 3 1
A dollars() 0 3 1
A __construct() 0 7 2
A equals() 0 3 1
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
}