<commit_before><?php declare(strict_types=1);

namespace EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Objects\Financial;

use Doctrine\DBAL\Types\Type;
use Doctrine\ORM\Mapping\ClassMetadata;
use EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Interfaces\Objects\Financial\MoneyEmbeddableInterface;
use EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Objects\AbstractEmbeddableObject;
use EdmondsCommerce\DoctrineStaticMeta\MappingHelper;
use Money\Currency;
use Money\Money;

class MoneyEmbeddable extends AbstractEmbeddableObject implements MoneyEmbeddableInterface
{
    /**
     * @var string
     */
    private $amount = MoneyEmbeddableInterface::DEFAULT_AMOUNT;

    /**
     * @var string
     */
    private $currencyCode = MoneyEmbeddableInterface::DEFAULT_CURRENCY_CODE;

    /**
     * @var Money
     */
    private $money;

    public function getMoney(): Money
    {
        if (null === $this->money) {
            $this->money = new Money($this->amount, new Currency($this->currencyCode));
        }

        return $this->money;
    }

    public function setMoney(Money $money): MoneyEmbeddableInterface
    {
        $this->money        = $money;
        $this->amount       = $money->getAmount();
        $this->currencyCode = $money->getCurrency()->getCode();

        return $this;
    }

    public function addMoney(Money $money): MoneyEmbeddableInterface
    {
        $this->setMoney($this->getMoney()->add($money));

        return $this;
    }

    public function subtractMoney(Money $money): MoneyEmbeddableInterface
    {
        $this->setMoney($this->getMoney()->subtract($money));

        return $this;
    }

    /**
     * @param ClassMetadata $metadata
     * @SuppressWarnings(PHPMD.StaticAccess)
     */
    public static function loadMetadata(ClassMetadata $metadata): void
    {
        $builder = self::setEmbeddableAndGetBuilder($metadata);
        MappingHelper::setSimpleFields(
            [
                MoneyEmbeddableInterface::EMBEDDED_PROP_CURRENCY_CODE => MappingHelper::TYPE_STRING,
            ],
            $builder
        );
        //Using BIGINT to ensure we can store very (very) large sums of cash
        $builder->createField(MoneyEmbeddableInterface::EMBEDDED_PROP_AMOUNT, Type::BIGINT)
                ->columnName(MappingHelper::getColumnNameForField(MoneyEmbeddableInterface::EMBEDDED_PROP_AMOUNT))
                ->nullable(true)
                ->build();
    }
}<commit_msg>trying to avoid CS line length issues<commit_after><?php declare(strict_types=1);

namespace EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Objects\Financial;

use Doctrine\DBAL\Types\Type;
use Doctrine\ORM\Mapping\ClassMetadata;
use EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Interfaces\Objects\Financial\MoneyEmbeddableInterface;
use EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Objects\AbstractEmbeddableObject;
use EdmondsCommerce\DoctrineStaticMeta\MappingHelper;
use Money\Currency;
use Money\Money;

class MoneyEmbeddable extends AbstractEmbeddableObject implements MoneyEmbeddableInterface
{
    /**
     * @var string
     */
    private $amount = MoneyEmbeddableInterface::DEFAULT_AMOUNT;

    /**
     * @var string
     */
    private $currencyCode = MoneyEmbeddableInterface::DEFAULT_CURRENCY_CODE;

    /**
     * @var Money
     */
    private $money;

    public function getMoney(): Money
    {
        if (null === $this->money) {
            $this->money = new Money($this->amount, new Currency($this->currencyCode));
        }

        return $this->money;
    }

    public function setMoney(Money $money): MoneyEmbeddableInterface
    {
        $this->money        = $money;
        $this->amount       = $money->getAmount();
        $this->currencyCode = $money->getCurrency()->getCode();

        return $this;
    }

    public function addMoney(Money $money): MoneyEmbeddableInterface
    {
        $this->setMoney($this->getMoney()->add($money));

        return $this;
    }

    public function subtractMoney(Money $money): MoneyEmbeddableInterface
    {
        $this->setMoney($this->getMoney()->subtract($money));

        return $this;
    }

    /**
     * @param ClassMetadata $metadata
     * @SuppressWarnings(PHPMD.StaticAccess)
     */
    public static function loadMetadata(ClassMetadata $metadata): void
    {
        $builder = self::setEmbeddableAndGetBuilder($metadata);
        MappingHelper::setSimpleFields(
            [
                MoneyEmbeddableInterface::EMBEDDED_PROP_CURRENCY_CODE => MappingHelper::TYPE_STRING,
            ],
            $builder
        );
        //Using BIGINT to ensure we can store very (very) large sums of cash
        $builder->createField(MoneyEmbeddableInterface::EMBEDDED_PROP_AMOUNT, Type::BIGINT)
                ->columnName(
                    MappingHelper::getColumnNameForField(
                        MoneyEmbeddableInterface::EMBEDDED_PROP_AMOUNT
                    )
                )
                ->nullable(true)
                ->build();
    }
}
{'fraction_non_alphanumeric': 0.10939357907253269, 'fraction_numerical': 0.00039635354736424893, 'mean_word_length': 2.838022813688213, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6125304', 'n_tokens_mistral': 1533, 'n_tokens_neox': 1407, 'n_words': 238}