ronantakizawa/codereview-bench huggingface dataset:
Repository: symfony/symfony
File: src/Symfony/Component/ObjectMapper/Tests/ObjectMapperTest.php (PHP)

Code before:

    public function testMultipleTargetMapProperty()
    {
        $u = new MultipleTargetPropertyA();

        $mapper = new ObjectMapper();
        $b = $mapper->map($u, MultipleTargetPropertyB::class);
        $this->assertInstanceOf(MultipleTargetPropertyB::class, $b);
        $this->assertEquals('TEST', $b->foo);
        $c = $mapper->map($u, MultipleTargetPropertyC::class);
        $this->assertInstanceOf(MultipleTargetPropertyC::class, $c);
        $this->assertEquals('test', $c->bar);
        $this->assertEquals('donotmap', $c->foo);
        $this->assertEquals('foo', $c->doesNotExistInTargetB);
    }

    public function testDefaultValueStdClass()
    {
        $this->expectException(NoSuchPropertyException::class);
        $u = new \stdClass();
        $u->id = 'abc';
        $mapper = new ObjectMapper();
        $b = $mapper->map($u, TargetDto::class);
        $this->assertInstanceOf(TargetDto::class, $b);
        $this->assertEquals('abc', $b->id);
        $this->assertEquals(null, $b->optional);
    }

    public function testDefaultValueStdClassWithPropertyInfo()
    {
        $u = new \stdClass();
        $u->id = 'abc';
        $mapper = new ObjectMapper(propertyAccessor: PropertyAccess::createPropertyAccessorBuilder()->disableExceptionOnInvalidPropertyPath()->getPropertyAccessor());
        $b = $mapper->map($u, TargetDto::class);
        $this->assertInstanceOf(TargetDto::class, $b);
        $this->assertEquals('abc', $b->id);
        $this->assertEquals(null, $b->optional);
    }
}


Review comment (suggestion):
```suggestion
        $this->assertSame('abc', $b->id);
        $this->assertNull($b->optional);
```

Code after:
    }

    public function testMultipleTargetMapProperty()
    {
        $u = new MultipleTargetPropertyA();

        $mapper = new ObjectMapper();
        $b = $mapper->map($u, MultipleTargetPropertyB::class);
        $this->assertInstanceOf(MultipleTargetPropertyB::class, $b);
        $this->assertEquals('TEST', $b->foo);
        $c = $mapper->map($u, MultipleTargetPropertyC::class);
        $this->assertInstanceOf(MultipleTargetPropertyC::class, $c);
        $this->assertEquals('test', $c->bar);
        $this->assertEquals('donotmap', $c->foo);
        $this->assertEquals('foo', $c->doesNotExistInTargetB);
    }

    public function testDefaultValueStdClass()
    {
        $this->expectException(NoSuchPropertyException::class);
        $u = new \stdClass();
        $u->id = 'abc';
        $mapper = new ObjectMapper();
        $b = $mapper->map($u, TargetDto::class);
    }

    public function testDefaultValueStdClassWithPropertyInfo()
    {
        $u = new \stdClass();
        $u->id = 'abc';
        $mapper = new ObjectMapper(propertyAccessor: PropertyAccess::createPropertyAccessorBuilder()->disableExceptionOnInvalidPropertyPath()->getPropertyAccessor());
        $b = $mapper->map($u, TargetDto::class);
        $this->assertInstanceOf(TargetDto::class, $b);
        $this->assertSame('abc', $b->id);
        $this->assertNull($b->optional);
    }
}
Repository: symfony/symfony
File: src/Symfony/Bundle/FrameworkBundle/Resources/config/web.php (PHP)

Code before:

        ->set('disallow_search_engine_index_response_listener', DisallowRobotsIndexingListener::class)
            ->tag('kernel.event_subscriber')

        ->set('error_controller', ErrorController::class)
            ->public()
            ->args([
                service('http_kernel'),
                param('kernel.error_controller'),
                service('error_renderer'),
            ])

        ->set('exception_listener', ErrorListener::class)
            ->args([
                param('kernel.error_controller'),
                service('logger')->nullOnInvalid(),
                param('kernel.debug'),
                abstract_arg('an exceptions to log & status code mapping'),
                abstract_arg('list of loggers by log_channel'),
            ])
            ->tag('kernel.event_subscriber')
            ->tag('monolog.logger', ['channel' => 'request'])

        ->set('controller.cache_attribute_listener', CacheAttributeListener::class)
            ->tag('kernel.event_subscriber')
            ->tag('kernel.reset', ['method' => 'reset'])

        ->set('controller.helper', ControllerHelper::class)
            ->tag('container.service_subscriber')

        ->alias(ControllerHelper::class, 'controller.helper')

    ;
};


Review comment (suggestion):
```suggestion
            ->tag('kernel.reset', ['method' => '?reset'])
```

Code after:

        ->set('disallow_search_engine_index_response_listener', DisallowRobotsIndexingListener::class)
            ->tag('kernel.event_subscriber')

        ->set('error_controller', ErrorController::class)
            ->public()
            ->args([
                service('http_kernel'),
                param('kernel.error_controller'),
                service('error_renderer'),
            ])

        ->set('exception_listener', ErrorListener::class)
            ->args([
                param('kernel.error_controller'),
                service('logger')->nullOnInvalid(),
                param('kernel.debug'),
                abstract_arg('an exceptions to log & status code mapping'),
                abstract_arg('list of loggers by log_channel'),
            ])
            ->tag('kernel.event_subscriber')
            ->tag('monolog.logger', ['channel' => 'request'])

        ->set('controller.cache_attribute_listener', CacheAttributeListener::class)
            ->tag('kernel.event_subscriber')
            ->tag('kernel.reset', ['method' => '?reset'])

        ->set('controller.helper', ControllerHelper::class)
            ->tag('container.service_subscriber')

        ->alias(ControllerHelper::class, 'controller.helper')

    ;
};
Repository: symfony/symfony
File: src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/NumberToLocalizedStringTransformerTest.php (PHP)

Code before:
            ini_set('intl.use_exceptions', $initialUseExceptions);
            ini_set('intl.error_level', $initialErrorLevel);
        }
    }

    public static function eNotationProvider(): array
    {
        return [
            [0.001, '1E-3'],
            [0.001, '1.0E-3'],
            [0.001, '1e-3'],
            [0.001, '1.0e-03'],
            [1000.0, '1E3'],
            [1000.0, '1.0E3'],
            [1000.0, '1e3'],
            [1000.0, '1.0e3'],
            [1232.0, '1.232e3'],
        ];
    }

    public function testReverseTransformDoesNotCauseIntegerPrecisionLoss()
    {
        $transformer = new NumberToLocalizedStringTransformer();

        // Test a large integer that was causing precision loss in the round() method
        $largeInt = 7609342542501717757; // Use a number that actually loses precision when cast to float
        $result = $transformer->reverseTransform((string) $largeInt);

        $this->assertSame($largeInt, $result);
        $this->assertIsInt($result);
    }
}


Review comment (suggestion):
@OskarStark 
wouldn't it be more robust to use a largeInt calculated based on PHP_INT_MAX?
i.e.: $largeInt = PHP_INT_MAX - 1;


Code after:
            ini_set('intl.use_exceptions', $initialUseExceptions);
            ini_set('intl.error_level', $initialErrorLevel);
        }
    }

    public static function eNotationProvider(): array
    {
        return [
            [0.001, '1E-3'],
            [0.001, '1.0E-3'],
            [0.001, '1e-3'],
            [0.001, '1.0e-03'],
            [1000.0, '1E3'],
            [1000.0, '1.0E3'],
            [1000.0, '1e3'],
            [1000.0, '1.0e3'],
            [1232.0, '1.232e3'],
        ];
    }

    public function testReverseTransformDoesNotCauseIntegerPrecisionLoss()
    {
        $transformer = new NumberToLocalizedStringTransformer();

        // Test a large integer that causes actual precision loss when cast to float
        $largeInt = \PHP_INT_MAX - 1; // This value loses precision when cast to float
        $result = $transformer->reverseTransform((string) $largeInt);

        $this->assertSame($largeInt, $result);
        $this->assertIsInt($result);
    }

    public function testRoundMethodKeepsIntegersAsIntegers()
    {
        $transformer = new NumberToLocalizedStringTransformer(2); // scale=2 triggers rounding
        
        // Use reflection to test the private round() method directly
        $reflection = new \ReflectionClass($transformer);
        $roundMethod = $reflection->getMethod('round');
        $roundMethod->setAccessible(true);
        
        $int = \PHP_INT_MAX - 1;
        $result = $roundMethod->invoke($transformer, $int);
        
        // With the fix, integers should stay as integers, not be converted to floats
        $this->assertSame($int, $result);
        $this->assertIsInt($result);
    }
}
Repository: symfony/symfony
File: src/Symfony/Component/JsonStreamer/Tests/Fixtures/stream_writer/nullable_object_dict.php (PHP)

Code before:
<?php

return static function (mixed $data, \Psr\Container\ContainerInterface $valueTransformers, array $options): \Traversable {
    try {
        if (\is_array($data)) {
            yield '{';
            $prefix = '';
            foreach ($data as $key => $value1) {
                $key = \substr(\json_encode($key), 1, -1);
                yield "{$prefix}\"{$key}\":";
                yield '{"@id":';
                yield \json_encode($value1->id, \JSON_THROW_ON_ERROR, 510);
                yield ',"name":';
                yield \json_encode($value1->name, \JSON_THROW_ON_ERROR, 510);
                yield '}';
                $prefix = ',';
            }
            yield '}';
        } elseif (null === $data) {
            yield 'null';
        } else {
            throw new \Symfony\Component\JsonStreamer\Exception\UnexpectedValueException(\sprintf('Unexpected "%s" value.', \get_debug_type($data)));
        }
    } catch (\JsonException $e) {
        throw new \Symfony\Component\JsonStreamer\Exception\NotEncodableValueException($e->getMessage(), 0, $e);
    }
};


Review comment (bug):
In principle, nested loops with a key will have the same issue of the nested key variable having the same name as the outer one(s). However, as the key will be printed first/before a nested loop is entered and is not be used anymore after a nested loop is completed, this same name causes no issue as for the value name.

May-be if others see it as an issue, a new bug issue can be opened for it to keep this PR with the original issue fixing the reported bug.

Code after:
<?php

return static function (mixed $data, \Psr\Container\ContainerInterface $valueTransformers, array $options): \Traversable {
    try {
        if (\is_array($data)) {
            yield '{';
            $prefix = '';
            foreach ($data as $key1 => $value1) {
                $key1 = \substr(\json_encode($key1), 1, -1);
                yield "{$prefix}\"{$key1}\":";
                yield '{"@id":';
                yield \json_encode($value1->id, \JSON_THROW_ON_ERROR, 510);
                yield ',"name":';
                yield \json_encode($value1->name, \JSON_THROW_ON_ERROR, 510);
                yield '}';
                $prefix = ',';
            }
            yield '}';
        } elseif (null === $data) {
            yield 'null';
        } else {
            throw new \Symfony\Component\JsonStreamer\Exception\UnexpectedValueException(\sprintf('Unexpected "%s" value.', \get_debug_type($data)));
        }
    } catch (\JsonException $e) {
        throw new \Symfony\Component\JsonStreamer\Exception\NotEncodableValueException($e->getMessage(), 0, $e);
    }
};
Repository: symfony/symfony
File: src/Symfony/Component/Security/Core/Authentication/Token/RememberMeToken.php (PHP)

Code before:
 * 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\Security\Core\Authentication\Token;

use Symfony\Component\Security\Core\Exception\InvalidArgumentException;
use Symfony\Component\Security\Core\User\UserInterface;

/**
 * Authentication Token for "Remember-Me".
 *
 * @author Johannes M. Schmitt <schmittjoh@gmail.com>
 */
class RememberMeToken extends AbstractToken
{
    /**
     * @throws \InvalidArgumentException
     */
    public function __construct(
        UserInterface $user,
        private string $firewallName
    ) {
        parent::__construct($user->getRoles());

        if (!$firewallName) {
            throw new InvalidArgumentException('$firewallName must not be empty.');
        }

        $this->setUser($user);
    }

    public function getFirewallName(): string
    {
        return $this->firewallName;
    }

    public function __serialize(): array
    {
        // Newly serialized data removes the secret deprecated since Symfony 7.2 and removed in Symfony 8.0
        return [$this->firewallName, parent::__serialize()];
    }

    public function __unserialize(array $data): void
    {
        // BC Layer with payloads generated before Symfony 8.0
        if (count($data) === 3) {

Review comment (suggestion):
```suggestion
        private string $firewallName,
```

Code after:
 * 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\Security\Core\Authentication\Token;

use Symfony\Component\Security\Core\Exception\InvalidArgumentException;
use Symfony\Component\Security\Core\User\UserInterface;

/**
 * Authentication Token for "Remember-Me".
 *
 * @author Johannes M. Schmitt <schmittjoh@gmail.com>
 */
class RememberMeToken extends AbstractToken
{
    /**
     * @throws \InvalidArgumentException
     */
    public function __construct(
        UserInterface $user,
        private string $firewallName,
    ) {
        parent::__construct($user->getRoles());

        if (!$firewallName) {
            throw new InvalidArgumentException('$firewallName must not be empty.');
        }

        $this->setUser($user);
    }

    public function getFirewallName(): string
    {
        return $this->firewallName;
    }

    public function __serialize(): array
    {
        return [null, $this->firewallName, parent::__serialize()];
    }

    public function __unserialize(array $data): void
    {
        [, $this->firewallName, $parentData] = $data;
        $parentData = \is_array($parentData) ? $parentData : unserialize($parentData);
        parent::__unserialize($parentData);
Repository: symfony/symfony
File: src/Symfony/Component/Security/Core/Authentication/Token/RememberMeToken.php (PHP)

Code before:
    public function __construct(
        UserInterface $user,
        private string $firewallName,
    ) {
        parent::__construct($user->getRoles());

        if (!$firewallName) {
            throw new InvalidArgumentException('$firewallName must not be empty.');
        }

        $this->setUser($user);
    }

    public function getFirewallName(): string
    {
        return $this->firewallName;
    }

    public function __serialize(): array
    {
        // Newly serialized data removes the secret deprecated since Symfony 7.2 and removed in Symfony 8.0
        return [$this->firewallName, parent::__serialize()];
    }

    public function __unserialize(array $data): void
    {
        // BC Layer with payloads generated before Symfony 8.0
        if (count($data) === 3) {
            [, $this->firewallName, $parentData] = $data;
        } else {
            [$this->firewallName, $parentData] = $data;
        }
        $parentData = \is_array($parentData) ? $parentData : unserialize($parentData);
        parent::__unserialize($parentData);
    }
}


Review comment (suggestion):
```suggestion
        // BC Layer with payloads generated before Symfony 8.0, to be removed in Symfony 9.0
```

Is it ok to keep such a BC Layer here? @OskarStark @stof 

Code after:
    public function __construct(
        UserInterface $user,
        private string $firewallName,
    ) {
        parent::__construct($user->getRoles());

        if (!$firewallName) {
            throw new InvalidArgumentException('$firewallName must not be empty.');
        }

        $this->setUser($user);
    }

    public function getFirewallName(): string
    {
        return $this->firewallName;
    }

    public function __serialize(): array
    {
        return [null, $this->firewallName, parent::__serialize()];
    }

    public function __unserialize(array $data): void
    {
        [, $this->firewallName, $parentData] = $data;
        $parentData = \is_array($parentData) ? $parentData : unserialize($parentData);
        parent::__unserialize($parentData);
    }
}
Repository: symfony/symfony
File: src/Symfony/Component/Security/Core/Authentication/Token/RememberMeToken.php (PHP)

Code before:
        UserInterface $user,
        private string $firewallName,
    ) {
        parent::__construct($user->getRoles());

        if (!$firewallName) {
            throw new InvalidArgumentException('$firewallName must not be empty.');
        }

        $this->setUser($user);
    }

    public function getFirewallName(): string
    {
        return $this->firewallName;
    }

    public function __serialize(): array
    {
        return [$this->firewallName, parent::__serialize()];
    }

    public function __unserialize(array $data): void
    {
        // BC Layer with payloads generated before Symfony 8.0
        if (count($data) === 3) {
            [, $this->firewallName, $parentData] = $data;
        } else {
            [$this->firewallName, $parentData] = $data;
        }
        $parentData = \is_array($parentData) ? $parentData : unserialize($parentData);
        parent::__unserialize($parentData);
    }
}


Review comment (suggestion):
```suggestion
        if (3 === count($data)) {
```

Code after:
        UserInterface $user,
        private string $firewallName,
    ) {
        parent::__construct($user->getRoles());

        if (!$firewallName) {
            throw new InvalidArgumentException('$firewallName must not be empty.');
        }

        $this->setUser($user);
    }

    public function getFirewallName(): string
    {
        return $this->firewallName;
    }

    public function __serialize(): array
    {
        return [null, $this->firewallName, parent::__serialize()];
    }

    public function __unserialize(array $data): void
    {
        [, $this->firewallName, $parentData] = $data;
        $parentData = \is_array($parentData) ? $parentData : unserialize($parentData);
        parent::__unserialize($parentData);
    }
}
Repository: symfony/symfony
File: src/Symfony/Bundle/SecurityBundle/Tests/Command/SecurityRoleHierarchyDumpCommandTest.php (PHP)

Code before:
graph TB
    ROLE_ADMIN
    ROLE_USER
    ROLE_SUPER_ADMIN
    ROLE_ADMIN --> ROLE_USER
    ROLE_SUPER_ADMIN --> ROLE_ADMIN
    ROLE_SUPER_ADMIN --> ROLE_USER

EXPECTED;

        $this->assertEquals($expectedOutput, $output);
    }

    public function testExecuteWithCustomDirection()
    {
        $hierarchy = [
            'ROLE_ADMIN' => ['ROLE_USER'],
        ];

        $roleHierarchy = new RoleHierarchy($hierarchy);
        $command = new SecurityRoleHierarchyDumpCommand($roleHierarchy);
        $commandTester = new CommandTester($command);

        $exitCode = $commandTester->execute(['--direction' => 'BT']);

        $this->assertEquals(Command::SUCCESS, $exitCode);
        $output = $commandTester->getDisplay();
        $this->assertStringContainsString('graph BT', $output);
    }

    public function testExecuteWithInvalidDirection()
    {
        $hierarchy = [
            'ROLE_ADMIN' => ['ROLE_USER'],
        ];

        $roleHierarchy = new RoleHierarchy($hierarchy);
        $command = new SecurityRoleHierarchyDumpCommand($roleHierarchy);
        $commandTester = new CommandTester($command);

        $exitCode = $commandTester->execute(['--direction' => 'INVALID']);

        $this->assertEquals(Command::FAILURE, $exitCode);
        $this->assertStringContainsString('Invalid direction', $commandTester->getDisplay());
    }

    public function testExecuteWithInvalidFormat()
    {
        $hierarchy = [
            'ROLE_ADMIN' => ['ROLE_USER'],
        ];

Review comment (suggestion):
```suggestion
        $this->assertSame(Command::SUCCESS, $exitCode);
```

Code after:

    public function testExecuteWithCustomDirection()
    {
        $hierarchy = [
            'ROLE_ADMIN' => ['ROLE_USER'],
        ];

        $roleHierarchy = new RoleHierarchy($hierarchy);
        $command = new SecurityRoleHierarchyDumpCommand($roleHierarchy);
        $commandTester = new CommandTester($command);

        $exitCode = $commandTester->execute(['--direction' => 'BT']);

        $this->assertSame(Command::SUCCESS, $exitCode);
        $output = $commandTester->getDisplay();
        $this->assertStringContainsString('graph BT', $output);
    }

    public function testExecuteWithInvalidDirection()
    {
        $hierarchy = [
            'ROLE_ADMIN' => ['ROLE_USER'],
        ];

        $roleHierarchy = new RoleHierarchy($hierarchy);
        $command = new SecurityRoleHierarchyDumpCommand($roleHierarchy);
        $commandTester = new CommandTester($command);

        $exitCode = $commandTester->execute(['--direction' => 'INVALID']);

        $this->assertSame(Command::FAILURE, $exitCode);
        $this->assertStringContainsString('Invalid direction', $commandTester->getDisplay());
    }
}