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.
Completed
Pull Request — master (#75)
by joseph
14:44
created

MoneyEmbeddable::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 9
ccs 0
cts 5
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
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\Financial\HasMoneyEmbeddableInterface;
8
use EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Interfaces\Objects\Financial\MoneyEmbeddableInterface;
9
use EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Objects\AbstractEmbeddableObject;
10
use EdmondsCommerce\DoctrineStaticMeta\MappingHelper;
11
use Money\Currency;
12
use Money\Money;
13
14
class MoneyEmbeddable extends AbstractEmbeddableObject implements MoneyEmbeddableInterface
15
{
16
    /**
17
     * @var string
18
     */
19
    private $amount = MoneyEmbeddableInterface::DEFAULT_AMOUNT;
20
21
    /**
22
     * @var string
23
     */
24
    private $currencyCode = MoneyEmbeddableInterface::DEFAULT_CURRENCY_CODE;
25
26
    /**
27
     * @var Money
28
     */
29
    private $money;
30
31 4
    public function getMoney(): Money
32
    {
33 4
        if (null === $this->money) {
34 2
            $this->money = new Money($this->amount, new Currency($this->currencyCode));
35
        }
36
37 4
        return $this->money;
38
    }
39
40 4
    public function setMoney(Money $money): MoneyEmbeddableInterface
41
    {
42 4
        $amount = $money->getAmount();
43 4
        $this->notifyEmbeddablePrefixedProperties(
44 4
            'amount',
45 4
            $this->amount,
46 4
            $amount
47
        );
48 4
        $currencyCode = $money->getCurrency()->getCode();
49 4
        $this->notifyEmbeddablePrefixedProperties(
50 4
            'currencyCode',
51 4
            $this->currencyCode,
52 4
            $money->getAmount()
53
        );
54 4
        $this->money        = $money;
55 4
        $this->amount       = $amount;
56 4
        $this->currencyCode = $currencyCode;
57
58 4
        return $this;
59
    }
60
61 2
    public function addMoney(Money $money): MoneyEmbeddableInterface
62
    {
63 2
        $this->setMoney($this->getMoney()->add($money));
64
65 2
        return $this;
66
    }
67
68 2
    public function subtractMoney(Money $money): MoneyEmbeddableInterface
69
    {
70 2
        $this->setMoney($this->getMoney()->subtract($money));
71
72 2
        return $this;
73
    }
74
75
    /**
76
     * @param ClassMetadata $metadata
77
     * @SuppressWarnings(PHPMD.StaticAccess)
78
     */
79 2
    public static function loadMetadata(ClassMetadata $metadata): void
80
    {
81 2
        $builder = self::setEmbeddableAndGetBuilder($metadata);
82 2
        MappingHelper::setSimpleFields(
83
            [
84 2
                MoneyEmbeddableInterface::EMBEDDED_PROP_CURRENCY_CODE => MappingHelper::TYPE_STRING,
85
            ],
86 2
            $builder
87
        );
88
        //Using BIGINT to ensure we can store very (very) large sums of cash
89 2
        $builder->createField(MoneyEmbeddableInterface::EMBEDDED_PROP_AMOUNT, Type::BIGINT)
90 2
                ->columnName(
91 2
                    MappingHelper::getColumnNameForField(
92 2
                        MoneyEmbeddableInterface::EMBEDDED_PROP_AMOUNT
93
                    )
94
                )
95 2
                ->nullable(true)
96 2
                ->build();
97 2
    }
98
99
    public function __toString(): string
100
    {
101
        return (string)print_r(
102
            [
103
                'moneyEmbeddable' => [
104
                    'amount'   => $this->getMoney()->getAmount(),
105
                    'currency' => $this->getMoney()->getCurrency(),
106
                ],
107
            ], true);
108
    }
109
110 2
    protected function getPrefix(): string
111
    {
112 2
        return HasMoneyEmbeddableInterface::PROP_MONEY_EMBEDDABLE;
113
    }
114
}
115