<commit_before><?php

namespace EasyCorp\Bundle\EasyAdminBundle\Field\Configurator;

use EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext;
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Field\FieldConfiguratorInterface;
use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;
use EasyCorp\Bundle\EasyAdminBundle\Dto\FieldDto;
use EasyCorp\Bundle\EasyAdminBundle\Field\MoneyField;
use EasyCorp\Bundle\EasyAdminBundle\Intl\IntlFormatter;
use Symfony\Component\Intl\Currencies;
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;

/**
 * @author <NAME> <<EMAIL>>
 */
final class MoneyConfigurator implements FieldConfiguratorInterface
{
    private $intlFormatter;
    private $propertyAccessor;

    public function __construct(IntlFormatter $intlFormatter, PropertyAccessorInterface $propertyAccessor)
    {
        $this->intlFormatter = $intlFormatter;
        $this->propertyAccessor = $propertyAccessor;
    }

    public function supports(FieldDto $field, EntityDto $entityDto): bool
    {
        return MoneyField::class === $field->getFieldFqcn();
    }

    public function configure(FieldDto $field, EntityDto $entityDto, AdminContext $context): void
    {
        if (null === $field->getValue()) {
            return;
        }

        $currencyCode = $this->getCurrency($field, $entityDto);
        if (!$this->isValidCurrencyCode($currencyCode)) {
            throw new \InvalidArgumentException(sprintf('The "%s" value used as the currency of the "%s" money field is not a valid ICU currency code.', $currencyCode, $field->getProperty()));
        }

        $numDecimals = $field->getCustomOption(MoneyField::OPTION_NUM_DECIMALS);
        $storedAsCents = $field->getCustomOption(MoneyField::OPTION_STORED_AS_CENTS);
        $amount = $storedAsCents ? $field->getValue() / 100 : $field->getValue();

        $formattedValue = $this->intlFormatter->formatCurrency($amount, $currencyCode, ['fraction_digit' => $numDecimals]);
        $field->setFormattedValue($formattedValue);
<commit_msg>Configured the currency property in the MoneyField form type<commit_after><?php

namespace EasyCorp\Bundle\EasyAdminBundle\Field\Configurator;

use EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext;
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Field\FieldConfiguratorInterface;
use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;
use EasyCorp\Bundle\EasyAdminBundle\Dto\FieldDto;
use EasyCorp\Bundle\EasyAdminBundle\Field\MoneyField;
use EasyCorp\Bundle\EasyAdminBundle\Intl\IntlFormatter;
use Symfony\Component\Intl\Currencies;
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;

/**
 * @author <NAME> <<EMAIL>>
 */
final class MoneyConfigurator implements FieldConfiguratorInterface
{
    private $intlFormatter;
    private $propertyAccessor;

    public function __construct(IntlFormatter $intlFormatter, PropertyAccessorInterface $propertyAccessor)
    {
        $this->intlFormatter = $intlFormatter;
        $this->propertyAccessor = $propertyAccessor;
    }

    public function supports(FieldDto $field, EntityDto $entityDto): bool
    {
        return MoneyField::class === $field->getFieldFqcn();
    }

    public function configure(FieldDto $field, EntityDto $entityDto, AdminContext $context): void
    {
        if (null === $field->getValue()) {
            return;
        }

        $currencyCode = $this->getCurrency($field, $entityDto);
        if (!$this->isValidCurrencyCode($currencyCode)) {
            throw new \InvalidArgumentException(sprintf('The "%s" value used as the currency of the "%s" money field is not a valid ICU currency code.', $currencyCode, $field->getProperty()));
        }

        $numDecimals = $field->getCustomOption(MoneyField::OPTION_NUM_DECIMALS);
        $storedAsCents = $field->getCustomOption(MoneyField::OPTION_STORED_AS_CENTS);
        $amount = $storedAsCents ? $field->getValue() / 100 : $field->getValue();

        $formattedValue = $this->intlFormatter->formatCurrency($amount, $currencyCode, ['fraction_digit' => $numDecimals]);
        $field->setFormattedValue($formattedValue);

        $field->setFormTypeOption('currency', $field->getCustomOption(MoneyField::OPTION_CURRENCY));
{'fraction_non_alphanumeric': 0.11733716475095786, 'fraction_numerical': 0.0014367816091954023, 'mean_word_length': 4.5471447543160695, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 41, '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': '924122', 'n_tokens_mistral': 1213, 'n_tokens_neox': 1185, 'n_words': 224}