ronantakizawa/codereview-bench huggingface dataset:
Repository: symfony/symfony
File: src/Symfony/Component/Console/Command/Command.php (PHP)

Code before:
            $this->setDescription($defaultDescription ?? '');
        }

        if ('' === $this->help) {
            $this->setHelp($attribute?->help ?? '');
        }

        foreach ($attribute?->usages ?? [] as $usage) {
            $this->addUsage($usage);
        }

        $this->configure();
    }

    /**
     * Ignores validation errors.
     *
     * This is mainly useful for the help command.
     */
    public function ignoreValidationErrors(): void
    {
        $this->ignoreValidationErrors = true;
    }

    public function setApplication(?Application $application): void
    {
        $this->application = $application;
        if ($application) {
            $this->setHelperSet($application->getHelperSet());
        } else {
            $this->helperSet = null;
        }

        $this->fullDefinition = null;
    }

    public function setHelperSet(HelperSet $helperSet): void
    {
        $this->helperSet = $helperSet;
    }

    /**
     * Gets the helper set.
     */
    public function getHelperSet(): ?HelperSet
    {
        return $this->helperSet;
    }

    /**
     * Gets the application instance for this command.

Review comment (bug):
This lines are here to support invokable classes that extend the `Command` class. This is a supported feature, see `InvokableCommandTest::testCallInvokeMethodWhenExtendingCommandClass` that is now failing.

I would add `if (!$code && ...` to the condition.

Code after:
            $this->setDescription($defaultDescription ?? '');
        }

        if ('' === $this->help) {
            $this->setHelp($attribute?->help ?? '');
        }

        foreach ($attribute?->usages ?? [] as $usage) {
            $this->addUsage($usage);
        }

        if (!$code && \is_callable($this) && self::class === (new \ReflectionMethod($this, 'execute'))->getDeclaringClass()->name) {
            $this->code = new InvokableCommand($this, $this(...));
        }

        $this->configure();
    }

    /**
     * Ignores validation errors.
     *
     * This is mainly useful for the help command.
     */
    public function ignoreValidationErrors(): void
    {
        $this->ignoreValidationErrors = true;
    }

    public function setApplication(?Application $application): void
    {
        $this->application = $application;
        if ($application) {
            $this->setHelperSet($application->getHelperSet());
        } else {
            $this->helperSet = null;
        }

        $this->fullDefinition = null;
    }

    public function setHelperSet(HelperSet $helperSet): void
    {
        $this->helperSet = $helperSet;
    }

    /**
     * Gets the helper set.
     */
    public function getHelperSet(): ?HelperSet
    {
        return $this->helperSet;
Repository: symfony/symfony
File: src/Symfony/Component/HttpKernel/Controller/ArgumentResolver/RequestPayloadValueResolver.php (PHP)

Code before:

        if ('' === ($data = $request->getContent()) && ($argument->isNullable() || $argument->hasDefaultValue())) {
            return null;
        }

        if ('form' === $format) {
            throw new BadRequestHttpException('Request payload contains invalid "form" data.');
        }

        try {
            return $this->serializer->deserialize($data, $type, $format, self::CONTEXT_DESERIALIZE + $attribute->serializationContext);
        } catch (UnsupportedFormatException $e) {
            throw new UnsupportedMediaTypeHttpException(\sprintf('Unsupported format: "%s".', $format), $e);
        } catch (NotEncodableValueException $e) {
            throw new BadRequestHttpException(\sprintf('Request payload contains invalid "%s" data.', $format), $e);
        } catch (UnexpectedPropertyException $e) {
            throw new BadRequestHttpException(\sprintf('Request payload contains invalid "%s" property.', $e->property), $e);
        }
    }

    private function mapUploadedFile(Request $request, ArgumentMetadata $argument, MapUploadedFile $attribute): UploadedFile|array|null
    {
        if (!($files = $request->files->get($attribute->name ?? $argument->getName())) && !($argument->isNullable() || $argument->hasDefaultValue())) {
            return null;
        }

        return $files;
    }
}


Review comment (suggestion):
```suggestion
return $request->files->get($attribute->name ?? $argument->getName());
```

Code after:

        if ('' === ($data = $request->getContent()) && ($argument->isNullable() || $argument->hasDefaultValue())) {
            return null;
        }

        if ('form' === $format) {
            throw new BadRequestHttpException('Request payload contains invalid "form" data.');
        }

        try {
            return $this->serializer->deserialize($data, $type, $format, self::CONTEXT_DESERIALIZE + $attribute->serializationContext);
        } catch (UnsupportedFormatException $e) {
            throw new UnsupportedMediaTypeHttpException(\sprintf('Unsupported format: "%s".', $format), $e);
        } catch (NotEncodableValueException $e) {
            throw new BadRequestHttpException(\sprintf('Request payload contains invalid "%s" data.', $format), $e);
        } catch (UnexpectedPropertyException $e) {
            throw new BadRequestHttpException(\sprintf('Request payload contains invalid "%s" property.', $e->property), $e);
        }
    }

    private function mapUploadedFile(Request $request, ArgumentMetadata $argument, MapUploadedFile $attribute): UploadedFile|array|null
    {
        if (!($files = $request->files->get($attribute->name ?? $argument->getName())) && ($argument->isNullable() || $argument->hasDefaultValue())) {
            return null;
        }

        return $files ?? ('array' === $argument->getType() ? [] : null);
    }
}
Repository: symfony/symfony
File: src/Symfony/Component/Intl/Tests/CurrenciesTest.php (PHP)

Code before:
        $this->assertFalse(Currencies::isValidInCountry('FR', 'USD', active: null, date: new \DateTimeImmutable('2025-01-01', new \DateTimeZone('Etc/UTC'))));
    }

    public function testChfCurrencyNotConsideredLegalTender()
    {
        $this->assertFalse(Currencies::isValidInCountry('CH', 'CHF', false, null));
    }

    public function testCheCurrencyDoesNotHaveValidityDatesInSwitzerland()
    {
        $this->expectException(\RuntimeException::class);
        $this->expectExceptionMessage('Cannot check whether the currency CHE is active or not in CH because they are no validity dates available.');

        Currencies::isValidInCountry('CH', 'CHE', false, false);
    }

    /**
     * Special case because the official dataset contains XXX to indicate that Antartica has no currency, but it is
     * excluded from the generated data on purpose.
     */
    public function testAntarticaHasNoCurrenciesIn2025()
    {
        $this->assertSame(
            [],
            Currencies::forCountry('AQ', null, true, new \DateTimeImmutable('2025-01-01', new \DateTimeZone('Etc/UTC'))),
        );
    }
}


Review comment (suggestion):
```suggestion
        $this->assertSame([], Currencies::forCountry('AQ', null, true, new \DateTimeImmutable('2025-01-01', new \DateTimeZone('Etc/UTC'))));
```

Code after:

    public function testCheCurrencyDoesNotHaveValidityDatesInSwitzerland()
    {
        $this->expectException(\RuntimeException::class);
        $this->expectExceptionMessage('Cannot check whether the currency CHE is active or not in CH because they are no validity dates available.');

        Currencies::isValidInCountry('CH', 'CHE', false, false);
    }

    /**
     * Special case because the official dataset contains XXX to indicate that Antartica has no currency, but it is
     * excluded from the generated data on purpose.
     */
    public function testAntarticaHasNoCurrenciesIn2025()
    {
        $this->assertSame([], Currencies::forCountry('AQ', null, true, new \DateTimeImmutable('2025-01-01', new \DateTimeZone('Etc/UTC'))));
    }

    public function testIsValidInCountryWithUnknownCurrencyThrowsException()
    {
        $this->expectException(\InvalidArgumentException::class);
        $this->expectExceptionMessage('The currency UNKNOWN-CURRENCY-FROM-ISO-4217 does not exist.');

        Currencies::isValidInCountry('CH', 'UNKNOWN-CURRENCY-FROM-ISO-4217');
    }

    public function testIsValidInAnyCountryWithUnknownCurrencyThrowsException()
    {
        $this->expectException(\InvalidArgumentException::class);
        $this->expectExceptionMessage('The currency UNKNOWN-CURRENCY-FROM-ISO-4217 does not exist.');

        Currencies::isValidInAnyCountry('UNKNOWN-CURRENCY-FROM-ISO-4217');
    }
}
Repository: symfony/symfony
File: src/Symfony/Component/Mailer/Bridge/Sendgrid/Header/SuppressionGroupHeader.php (PHP)

Code before:
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Mailer\Bridge\Sendgrid\Header;

use Symfony\Component\Mailer\Exception\InvalidArgumentException;
use Symfony\Component\Mime\Header\UnstructuredHeader;

/**
 * @author Kieran Cross
 */
final class SuppressionGroupHeader extends UnstructuredHeader
{
    public function __construct(
        private int $group_id,
        private array $groups_to_display = [],
    ) {
        if (\count($groups_to_display) > 25) {
            throw new InvalidArgumentException(\sprintf('SendGrid must not contain more than 25 groups to display, %d given.', \count($groups_to_display)));
        }

        parent::__construct('X-Sendgrid-SuppressionGroup', json_encode([
            'group_id' => $group_id,
            'groups_to_display' => array_values(array_map('intval', $groups_to_display)),
        ], \JSON_THROW_ON_ERROR));
    }

    public function getGroupId(): int
    {
        return $this->group_id;
    }

    public function getGroupsToDisplay(): array
    {
        return array_values(array_map('intval', $this->groups_to_display));
    }
}


Review comment (refactor):
Thus error should be returned by the api if you send more then 25, right? If so let's remove this userland check here

Code after:
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Mailer\Bridge\Sendgrid\Header;

use Symfony\Component\Mime\Header\UnstructuredHeader;

/**
 * @author Kieran Cross
 */
final class SuppressionGroupHeader extends UnstructuredHeader
{
    /**
     * @param int[] $groupsToDisplay
     */
    public function __construct(
        private int $groupId,
        private array $groupsToDisplay = [],
    ) {
        $this->groupsToDisplay = array_values(array_map('intval', $groupsToDisplay));

        parent::__construct('X-Sendgrid-SuppressionGroup', json_encode([
            'group_id' => $groupId,
            'groups_to_display' => $this->groupsToDisplay,
        ], \JSON_THROW_ON_ERROR));
    }

    public function getGroupId(): int
    {
        return $this->groupId;
    }

    public function getGroupsToDisplay(): array
    {
        return $this->groupsToDisplay;
    }
}
Repository: symfony/symfony
File: src/Symfony/Component/Mailer/Bridge/Sendgrid/Header/SuppressionGroupHeader.php (PHP)

Code before:
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Mailer\Bridge\Sendgrid\Header;

use Symfony\Component\Mailer\Exception\InvalidArgumentException;
use Symfony\Component\Mime\Header\UnstructuredHeader;

/**
 * @author Kieran Cross
 */
final class SuppressionGroupHeader extends UnstructuredHeader
{
    public function __construct(
        private int $group_id,
        private array $groups_to_display = [],
    ) {
        if (\count($groups_to_display) > 25) {
            throw new InvalidArgumentException(\sprintf('SendGrid must not contain more than 25 groups to display, %d given.', \count($groups_to_display)));
        }

        parent::__construct('X-Sendgrid-SuppressionGroup', json_encode([
            'group_id' => $group_id,
            'groups_to_display' => array_values(array_map('intval', $groups_to_display)),
        ], \JSON_THROW_ON_ERROR));
    }

    public function getGroupId(): int
    {
        return $this->group_id;
    }

    public function getGroupsToDisplay(): array
    {
        return array_values(array_map('intval', $this->groups_to_display));
    }
}


Review comment (suggestion):
```suggestion
        private int $groupId
```
No snake case please

Code after:
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Mailer\Bridge\Sendgrid\Header;

use Symfony\Component\Mime\Header\UnstructuredHeader;

/**
 * @author Kieran Cross
 */
final class SuppressionGroupHeader extends UnstructuredHeader
{
    /**
     * @param int[] $groupsToDisplay
     */
    public function __construct(
        private int $groupId,
        private array $groupsToDisplay = [],
    ) {
        $this->groupsToDisplay = array_values(array_map('intval', $groupsToDisplay));

        parent::__construct('X-Sendgrid-SuppressionGroup', json_encode([
            'group_id' => $groupId,
            'groups_to_display' => $this->groupsToDisplay,
        ], \JSON_THROW_ON_ERROR));
    }

    public function getGroupId(): int
    {
        return $this->groupId;
    }

    public function getGroupsToDisplay(): array
    {
        return $this->groupsToDisplay;
    }
}
Repository: symfony/symfony
File: src/Symfony/Component/Mailer/Bridge/Sendgrid/Header/SuppressionGroupHeader.php (PHP)

Code before:
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Mailer\Bridge\Sendgrid\Header;

use Symfony\Component\Mime\Header\UnstructuredHeader;

/**
 * @author Kieran Cross
 */
final class SuppressionGroupHeader extends UnstructuredHeader
{
    public function __construct(
        private int $groupId,
        private array $groupsToDisplay = [],
    ) {
        $this->groupsToDisplay = array_values(array_map('intval', $groupsToDisplay));

        parent::__construct('X-Sendgrid-SuppressionGroup', json_encode([
            'group_id' => $groupId,
            'groups_to_display' => $this->groupsToDisplay,
        ], \JSON_THROW_ON_ERROR));
    }

    public function getGroupId(): int
    {
        return $this->groupId;
    }

    public function getGroupsToDisplay(): array
    {
        return $this->groupsToDisplay;
    }
}


Review comment (suggestion):
```suggestion
    /**
     * @param int[] $groupsToDisplay
     */
    public function __construct(
        private int $groupId,
        private array $groupsToDisplay = [],
```

Code after:
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Mailer\Bridge\Sendgrid\Header;

use Symfony\Component\Mime\Header\UnstructuredHeader;

/**
 * @author Kieran Cross
 */
final class SuppressionGroupHeader extends UnstructuredHeader
{
    /**
     * @param int[] $groupsToDisplay
     */
    public function __construct(
        private int $groupId,
        private array $groupsToDisplay = [],
    ) {
        $this->groupsToDisplay = array_values(array_map('intval', $groupsToDisplay));

        parent::__construct('X-Sendgrid-SuppressionGroup', json_encode([
            'group_id' => $groupId,
            'groups_to_display' => $this->groupsToDisplay,
        ], \JSON_THROW_ON_ERROR));
    }

    public function getGroupId(): int
    {
        return $this->groupId;
    }

    public function getGroupsToDisplay(): array
    {
        return $this->groupsToDisplay;
    }
}
Repository: symfony/symfony
File: src/Symfony/Component/ObjectMapper/Metadata/ReflectionObjectMapperMetadataFactory.php (PHP)

Code before:

/**
 * @internal
 *
 * @author Antoine Bluchet <soyuka@gmail.com>
 */
final class ReflectionObjectMapperMetadataFactory implements ObjectMapperMetadataFactoryInterface
{
    private ?\SplObjectStorage $reflectionClassCache = null;
    private array $attributesCache = [];

    public function __construct()
    {
        $this->reflectionClassCache = new \SplObjectStorage();
    }

    public function create(object $object, ?string $property = null, array $context = []): array
    {
        try {
            $key = $object::class.($property ?? '');

            if (isset($this->attributesCache[$key])) {
                return $this->attributesCache[$key];
            }

            $refl = $this->reflectionClassCache[$object] ??= new \ReflectionClass($object);
            $attributes = ($property ? $refl->getProperty($property) : $refl)->getAttributes(Map::class, \ReflectionAttribute::IS_INSTANCEOF);
            $mappings = [];
            foreach ($attributes as $attribute) {
                $map = $attribute->newInstance();
                $mappings[] = new Mapping($map->target, $map->source, $map->if, $map->transform);
            }

            return $this->attributesCache[$key] = $mappings;
        } catch (\ReflectionException $e) {
            throw new MappingException($e->getMessage(), $e->getCode(), $e);
        }
    }
}


Review comment (performance):
The `SplObjectStorage` will hold a reference to the objects used as key. Can we use a simple array using the class name as the key?

```suggestion
            $refl = $this->reflectionClassCache[$object::class] ??= new \ReflectionClass($object);
```

Code after:

/**
 * @internal
 *
 * @author Antoine Bluchet <soyuka@gmail.com>
 */
final class ReflectionObjectMapperMetadataFactory implements ObjectMapperMetadataFactoryInterface
{
    private array $reflectionClassCache = [];
    private array $attributesCache = [];

    public function create(object $object, ?string $property = null, array $context = []): array
    {
        try {
            $key = $object::class.($property ?? '');

            if (isset($this->attributesCache[$key])) {
                return $this->attributesCache[$key];
            }

            $refl = $this->reflectionClassCache[$object::class] ??= new \ReflectionClass($object);
            $attributes = ($property ? $refl->getProperty($property) : $refl)->getAttributes(Map::class, \ReflectionAttribute::IS_INSTANCEOF);
            $mappings = [];
            foreach ($attributes as $attribute) {
                $map = $attribute->newInstance();
                $mappings[] = new Mapping($map->target, $map->source, $map->if, $map->transform);
            }

            return $this->attributesCache[$key] = $mappings;
        } catch (\ReflectionException $e) {
            throw new MappingException($e->getMessage(), $e->getCode(), $e);
        }
    }
}
Repository: symfony/symfony
File: src/Symfony/Bundle/FrameworkBundle/Tests/Routing/Fixtures/InvokableController.php (PHP)

Code before:
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Bundle\FrameworkBundle\Tests\Routing\Fixtures;

use Symfony\Component\Routing\Attribute\Route;

#[Route(path: '/here', name: 'lol', methods: ["GET", "POST"], schemes: ['https'])]
class InvokableController
{
    public function __invoke()
    {
    }
}


Review comment (suggestion):
```suggestion
#[Route(path: '/here', name: 'lol', methods: ['GET', 'POST'], schemes: ['https'])]
```

Code after:
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Bundle\FrameworkBundle\Tests\Routing\Fixtures;

use Symfony\Component\Routing\Attribute\Route;

#[Route(path: '/here', name: 'lol', methods: ['GET', 'POST'], schemes: ['https'])]
class InvokableController
{
    public function __invoke()
    {
    }
}
Repository: symfony/symfony
File: src/Symfony/Component/Form/Extension/Validator/Constraints/Form.php (PHP)

Code before:
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Form\Extension\Validator\Constraints;

use Symfony\Component\Validator\Attribute\HasNamedArguments;
use Symfony\Component\Validator\Constraint;

/**
 * @author Bernhard Schussek <bschussek@gmail.com>
 */
#[\Attribute(\Attribute::TARGET_CLASS)]
class Form extends Constraint
{
    public const NOT_SYNCHRONIZED_ERROR = '1dafa156-89e1-4736-b832-419c2e501fca';
    public const NO_SUCH_FIELD_ERROR = '6e5212ed-a197-4339-99aa-5654798a4854';

    protected const ERROR_NAMES = [
        self::NOT_SYNCHRONIZED_ERROR => 'NOT_SYNCHRONIZED_ERROR',
        self::NO_SUCH_FIELD_ERROR => 'NO_SUCH_FIELD_ERROR',
    ];

    #[HasNamedArguments()]
    public function __construct(mixed $options = null, ?array $groups = null, mixed $payload = null)
    {
        parent::__construct($options, $groups, $payload);
    }

    public function getTargets(): string|array
    {
        return self::CLASS_CONSTRAINT;
    }
}


Review comment (suggestion):
I'm not sure about our CS, but parenthesis are optional.

```suggestion
    #[HasNamedArguments]
```

Code after:
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Form\Extension\Validator\Constraints;

use Symfony\Component\Validator\Attribute\HasNamedArguments;
use Symfony\Component\Validator\Constraint;

/**
 * @author Bernhard Schussek <bschussek@gmail.com>
 */
#[\Attribute(\Attribute::TARGET_CLASS)]
class Form extends Constraint
{
    public const NOT_SYNCHRONIZED_ERROR = '1dafa156-89e1-4736-b832-419c2e501fca';
    public const NO_SUCH_FIELD_ERROR = '6e5212ed-a197-4339-99aa-5654798a4854';

    protected const ERROR_NAMES = [
        self::NOT_SYNCHRONIZED_ERROR => 'NOT_SYNCHRONIZED_ERROR',
        self::NO_SUCH_FIELD_ERROR => 'NO_SUCH_FIELD_ERROR',
    ];

    #[HasNamedArguments]
    public function __construct(mixed $options = null, ?array $groups = null, mixed $payload = null)
    {
        parent::__construct($options, $groups, $payload);
    }

    public function getTargets(): string|array
    {
        return self::CLASS_CONSTRAINT;
    }
}