<commit_before><?php

namespace Harp\Money;

use CL\CurrencyConvert\Converter;
use Harp\Harp\Config;
use SebastianBergmann\Money\Money;
use SebastianBergmann\Money\Currency;

/**
 * A combination of FreezableTrait and ValueTrait
 * Adds value and isFrozen properties
 * Adds present and number asserts on value property
 *
 * @author    <NAME> <<EMAIL>>
 * @copyright 2014, Clippings Ltd.
 * @license   http://spdx.org/licenses/BSD-3-Clause
 */
trait FreezableValueTrait
{
    use FreezableTrait;
    use ValueTrait {
        ValueTrait::getValue as getFrozenValue;
    }

    public static function initialize(Config $config)
    {
        ValueTrait::initialize($config);
    }

    /**
     * @return Money
     */
    abstract public function getSourceValue();

    /**
     * @return Money
     */
    public function getValue()
    {
        return $this->isFrozen
            ? $this->getFrozenValue()
            : $this->getConvertedSourceValue();
    }

    /**
     * Converts the currency of "getSourceValue" if the currency is different
     * Uses Converter class
     *
     * @return Money
     */
    public function getConvertedSourceValue()
    {
        $currency = $this->getCurrency();
        $value = $this->getSourceValue();

        if ($currency != $value->getCurrency()) {
            $value = Converter::get()->convert($value, $currency);
        }

        return $value;
    }

    /**
     * @return static
     */
    public function freezeValue()
    {
        $this->setValue($this->getValue());
    }

    /**
     * @return static
     */
    public function unfreezeValue()
    {
        $this->value = 0;
    }
<commit_msg>allow chaining of freeze methods<commit_after><?php

namespace Harp\Money;

use CL\CurrencyConvert\Converter;
use Harp\Harp\Config;
use SebastianBergmann\Money\Money;
use SebastianBergmann\Money\Currency;

/**
 * A combination of FreezableTrait and ValueTrait
 * Adds value and isFrozen properties
 * Adds present and number asserts on value property
 *
 * @author    <NAME> <<EMAIL>>
 * @copyright 2014, Clippings Ltd.
 * @license   http://spdx.org/licenses/BSD-3-Clause
 */
trait FreezableValueTrait
{
    use FreezableTrait;
    use ValueTrait {
        ValueTrait::getValue as getFrozenValue;
    }

    public static function initialize(Config $config)
    {
        ValueTrait::initialize($config);
    }

    /**
     * @return Money
     */
    abstract public function getSourceValue();

    /**
     * @return Money
     */
    public function getValue()
    {
        return $this->isFrozen
            ? $this->getFrozenValue()
            : $this->getConvertedSourceValue();
    }

    /**
     * Converts the currency of "getSourceValue" if the currency is different
     * Uses Converter class
     *
     * @return Money
     */
    public function getConvertedSourceValue()
    {
        $currency = $this->getCurrency();
        $value = $this->getSourceValue();

        if ($currency != $value->getCurrency()) {
            $value = Converter::get()->convert($value, $currency);
        }

        return $value;
    }

    /**
     * @return static
     */
    public function freezeValue()
    {
        $this->setValue($this->getValue());

        return $this;
    }

    /**
     * @return static
     */
    public function unfreezeValue()
    {
        $this->value = 0;

        return $this;
    }

{'fraction_non_alphanumeric': 0.12097964001180289, 'fraction_numerical': 0.0035408675125405725, 'mean_word_length': 2.294460641399417, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 29, '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': '746249', 'n_tokens_mistral': 1030, 'n_tokens_neox': 1003, 'n_words': 232}