GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Pull Request — master (#58)
by joseph
17:08
created

MoneyEmbeddable::getMoney()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
ccs 4
cts 4
cp 1
cc 2
eloc 3
nc 2
nop 0
crap 2
1
<?php declare(strict_types=1);
2
3
namespace EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Objects\Financial;
4
5
use Doctrine\DBAL\Types\Type;
6
use Doctrine\ORM\Mapping\ClassMetadata;
7
use EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Interfaces\Objects\Financial\MoneyEmbeddableInterface;
8
use EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Objects\AbstractEmbeddableObject;
9
use EdmondsCommerce\DoctrineStaticMeta\MappingHelper;
10
use Money\Currency;
11
use Money\Money;
12
13
class MoneyEmbeddable extends AbstractEmbeddableObject implements MoneyEmbeddableInterface
14
{
15
    /**
16
     * @var string
17
     */
18
    private $amount = MoneyEmbeddableInterface::DEFAULT_AMOUNT;
19
20
    /**
21
     * @var string
22
     */
23
    private $currencyCode = MoneyEmbeddableInterface::DEFAULT_CURRENCY_CODE;
24
25
    /**
26
     * @var Money
27
     */
28
    private $money;
29
30 3
    public function getMoney(): Money
31
    {
32 3
        if (null === $this->money) {
33 2
            $this->money = new Money($this->amount, new Currency($this->currencyCode));
34
        }
35
36 3
        return $this->money;
37
    }
38
39 3
    public function setMoney(Money $money): MoneyEmbeddableInterface
40
    {
41 3
        $this->money        = $money;
42 3
        $this->amount       = $money->getAmount();
43 3
        $this->currencyCode = $money->getCurrency()->getCode();
44
45 3
        return $this;
46
    }
47
48 2
    public function addMoney(Money $money): MoneyEmbeddableInterface
49
    {
50 2
        $this->setMoney($this->getMoney()->add($money));
51
52 2
        return $this;
53
    }
54
55 2
    public function subtractMoney(Money $money): MoneyEmbeddableInterface
56
    {
57 2
        $this->setMoney($this->getMoney()->subtract($money));
58
59 2
        return $this;
60
    }
61
62
    /**
63
     * @param ClassMetadata $metadata
64
     * @SuppressWarnings(PHPMD.StaticAccess)
65
     */
66 1
    public static function loadMetadata(ClassMetadata $metadata): void
67
    {
68 1
        $builder = self::setEmbeddableAndGetBuilder($metadata);
69 1
        MappingHelper::setSimpleFields(
70
            [
71 1
                MoneyEmbeddableInterface::EMBEDDED_PROP_CURRENCY_CODE => MappingHelper::TYPE_STRING,
72
            ],
73 1
            $builder
74
        );
75
        //Using BIGINT to ensure we can store very (very) large sums of cash
76 1
        $builder->createField(MoneyEmbeddableInterface::EMBEDDED_PROP_AMOUNT, Type::BIGINT)
77 1
                ->columnName(MappingHelper::getColumnNameForField(MoneyEmbeddableInterface::EMBEDDED_PROP_AMOUNT))
78 1
                ->nullable(true)
79 1
                ->build();
80 1
    }
81
}
82