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

Code before:
            'policy' => 'token_bucket',
            'limit' => 10,
            'rate' => ['interval' => '1 second'],
        ]);
        $limiter = $factory->create('127.0.0.1');

        $this->assertInstanceOf(TokenBucketLimiter::class, $limiter);
    }

    public function testFixedWindow()
    {
        $factory = $this->createFactory([
            'id' => 'test',
            'policy' => 'fixed_window',
            'limit' => 10,
            'interval' => '1 minute',
        ]);
        $limiter = $factory->create();

        $this->assertInstanceOf(FixedWindowLimiter::class, $limiter);
    }

    public function testWrongInterval()
    {
        $this->expectException(\LogicException::class);
        $this->expectExceptionMessage('Cannot parse interval "1 minut", please use a valid unit as described on https://www.php.net/manual/en/datetime.formats.php#datetime.formats.relative');

        $this->createFactory([
            'id' => 'test',
            'policy' => 'fixed_window',
            'limit' => 10,
            'interval' => '1 minut',
        ]);
    }

    private function createFactory(array $options)
    {
        return new RateLimiterFactory($options, $this->createMock(StorageInterface::class), $this->createMock(LockFactory::class));
    }
}


Review comment (suggestion):
```suggestion
        $this->expectExceptionMessage('Cannot parse interval "1 minut", please use a valid unit as described on https://www.php.net/datetime.formats#datetime.formats.relative');
```

Code after:
            'policy' => 'token_bucket',
            'limit' => 10,
            'rate' => ['interval' => '1 second'],
        ]);
        $limiter = $factory->create('127.0.0.1');

        $this->assertInstanceOf(TokenBucketLimiter::class, $limiter);
    }

    public function testFixedWindow()
    {
        $factory = $this->createFactory([
            'id' => 'test',
            'policy' => 'fixed_window',
            'limit' => 10,
            'interval' => '1 minute',
        ]);
        $limiter = $factory->create();

        $this->assertInstanceOf(FixedWindowLimiter::class, $limiter);
    }

    public function testWrongInterval()
    {
        $this->expectException(\LogicException::class);
        $this->expectExceptionMessage('Cannot parse interval "1 minut", please use a valid unit as described on https://php.net/datetime.formats#datetime.formats.relative');

        $this->createFactory([
            'id' => 'test',
            'policy' => 'fixed_window',
            'limit' => 10,
            'interval' => '1 minut',
        ]);
    }

    private function createFactory(array $options)
    {
        return new RateLimiterFactory($options, $this->createMock(StorageInterface::class), $this->createMock(LockFactory::class));
    }
}
Repository: symfony/symfony
File: src/Symfony/Component/Console/Question/Question.php (PHP)

Code before:

/**
 * Represents a Question.
 *
 * @author Fabien Potencier <fabien@symfony.com>
 */
class Question
{
    private ?int $attempts = null;
    private bool $hidden = false;
    private bool $hiddenFallback = true;
    /**
     * @var (\Closure(string):string[])|null
     */
    private ?\Closure $autocompleterCallback = null;
    /**
     * @var (\Closure(mixed):mixed)|null
     */
    private ?\Closure $validator = null;
    /**
     * @var (\Closure(mixed):mixed)|null
     */
    private ?\Closure $normalizer = null;
    private bool $trimmable = true;
    private bool $multiline = false;
    private ?int $timoutSeconds = null;

    /**
     * @param string                     $question The question to ask to the user
     * @param string|bool|int|float|null $default  The default answer to return if the user enters nothing
     */
    public function __construct(
        private string $question,
        private string|bool|int|float|null $default = null,
    ) {
    }

    /**
     * Returns the question.
     */
    public function getQuestion(): string
    {
        return $this->question;
    }

    /**
     * Returns the default answer.
     */
    public function getDefault(): string|bool|int|float|null
    {
        return $this->default;

Review comment (suggestion):
```suggestion
    private ?int $timeoutSeconds = null;
```

Code after:

/**
 * Represents a Question.
 *
 * @author Fabien Potencier <fabien@symfony.com>
 */
class Question
{
    private ?int $attempts = null;
    private bool $hidden = false;
    private bool $hiddenFallback = true;
    /**
     * @var (\Closure(string):string[])|null
     */
    private ?\Closure $autocompleterCallback = null;
    /**
     * @var (\Closure(mixed):mixed)|null
     */
    private ?\Closure $validator = null;
    /**
     * @var (\Closure(mixed):mixed)|null
     */
    private ?\Closure $normalizer = null;
    private bool $trimmable = true;
    private bool $multiline = false;
    private ?int $timeout = null;

    /**
     * @param string                     $question The question to ask to the user
     * @param string|bool|int|float|null $default  The default answer to return if the user enters nothing
     */
    public function __construct(
        private string $question,
        private string|bool|int|float|null $default = null,
    ) {
    }

    /**
     * Returns the question.
     */
    public function getQuestion(): string
    {
        return $this->question;
    }

    /**
     * Returns the default answer.
     */
    public function getDefault(): string|bool|int|float|null
    {
        return $this->default;
Repository: symfony/symfony
File: src/Symfony/Component/Console/Question/Question.php (PHP)

Code before:
        return $this->multiline;
    }

    /**
     * Sets whether the user response should accept newline characters.
     *
     * @return $this
     */
    public function setMultiline(bool $multiline): static
    {
        $this->multiline = $multiline;

        return $this;
    }

    /**
     * Returns the timeout in seconds.
     */
    public function getTimeoutSeconds(): ?int
    {
        return $this->timeoutSeconds;
    }

    /**
     * The timeout is the maximum time the user has to answer the question.
     * If the user does not answer within this time, an exception will be thrown.
     *
     * @return $this
     */
    public function setTimeout(?int $seconds): static
    {
        $this->timeoutSeconds = $seconds;

        return $this;
    }

    /**
     * Returns whether the user response must be hidden.
     */
    public function isHidden(): bool
    {
        return $this->hidden;
    }

    /**
     * Sets whether the user response must be hidden or not.
     *
     * @return $this
     *
     * @throws LogicException In case the autocompleter is also used
     */

Review comment (refactor):
```suggestion
```
this logic is part of the questionHelper, not the setter.

Code after:
        return $this->multiline;
    }

    /**
     * Sets whether the user response should accept newline characters.
     *
     * @return $this
     */
    public function setMultiline(bool $multiline): static
    {
        $this->multiline = $multiline;

        return $this;
    }

    /**
     * Returns the timeout in seconds.
     */
    public function getTimeout(): ?int
    {
        return $this->timeout;
    }

    /**
     * Sets the maximum time the user has to answer the question.
     * If the user does not answer within this time, an exception will be thrown.
     *
     * @return $this
     */
    public function setTimeout(?int $seconds): static
    {
        $this->timeout = $seconds;

        return $this;
    }

    /**
     * Returns whether the user response must be hidden.
     */
    public function isHidden(): bool
    {
        return $this->hidden;
    }

    /**
     * Sets whether the user response must be hidden or not.
     *
     * @return $this
     *
     * @throws LogicException In case the autocompleter is also used
     */
Repository: symfony/symfony
File: src/Symfony/Component/Console/Question/Question.php (PHP)

Code before:
     * Sets whether the user response should accept newline characters.
     *
     * @return $this
     */
    public function setMultiline(bool $multiline): static
    {
        $this->multiline = $multiline;

        return $this;
    }

    /**
     * Returns the timeout in seconds.
     */
    public function getTimeoutSeconds(): ?int
    {
        return $this->timeoutSeconds;
    }

    /**
     * The timeout is the maximum time the user has to answer the question.
     * If the user does not answer within this time, an exception will be thrown.
     *
     * @return $this
     */
    public function setTimeout(?int $seconds): static
    {
        $this->timeoutSeconds = $seconds;

        return $this;
    }

    /**
     * Returns whether the user response must be hidden.
     */
    public function isHidden(): bool
    {
        return $this->hidden;
    }

    /**
     * Sets whether the user response must be hidden or not.
     *
     * @return $this
     *
     * @throws LogicException In case the autocompleter is also used
     */
    public function setHidden(bool $hidden): static
    {
        if ($this->autocompleterCallback) {
            throw new LogicException('A hidden question cannot use the autocompleter.');

Review comment (suggestion):
The method name is inconsistent with the getter. I would recommend to use `getTimeout()` and `setTimeout()` as method names to be consistent with othe places in the framework (and so also rename the property to `timeout`).

Code after:
     * Sets whether the user response should accept newline characters.
     *
     * @return $this
     */
    public function setMultiline(bool $multiline): static
    {
        $this->multiline = $multiline;

        return $this;
    }

    /**
     * Returns the timeout in seconds.
     */
    public function getTimeout(): ?int
    {
        return $this->timeout;
    }

    /**
     * Sets the maximum time the user has to answer the question.
     * If the user does not answer within this time, an exception will be thrown.
     *
     * @return $this
     */
    public function setTimeout(?int $seconds): static
    {
        $this->timeout = $seconds;

        return $this;
    }

    /**
     * Returns whether the user response must be hidden.
     */
    public function isHidden(): bool
    {
        return $this->hidden;
    }

    /**
     * Sets whether the user response must be hidden or not.
     *
     * @return $this
     *
     * @throws LogicException In case the autocompleter is also used
     */
    public function setHidden(bool $hidden): static
    {
        if ($this->autocompleterCallback) {
            throw new LogicException('A hidden question cannot use the autocompleter.');
Repository: symfony/symfony
File: src/Symfony/Component/Console/Question/Question.php (PHP)

Code before:
    {
        return $this->multiline;
    }

    /**
     * Sets whether the user response should accept newline characters.
     *
     * @return $this
     */
    public function setMultiline(bool $multiline): static
    {
        $this->multiline = $multiline;

        return $this;
    }

    /**
     * Returns the timeout in seconds.
     */
    public function getTimeout(): ?int
    {
        return $this->timeout;
    }

    /**
     * The timeout is the maximum time the user has to answer the question.
     * If the user does not answer within this time, an exception will be thrown.
     *
     * @return $this
     */
    public function setTimeout(?int $seconds): static
    {
        $this->timeout = $seconds;

        return $this;
    }

    /**
     * Returns whether the user response must be hidden.
     */
    public function isHidden(): bool
    {
        return $this->hidden;
    }

    /**
     * Sets whether the user response must be hidden or not.
     *
     * @return $this
     *
     * @throws LogicException In case the autocompleter is also used

Review comment (suggestion):
```suggestion
     * Sets the maximum time the user has to answer the question.
```

Code after:
    {
        return $this->multiline;
    }

    /**
     * Sets whether the user response should accept newline characters.
     *
     * @return $this
     */
    public function setMultiline(bool $multiline): static
    {
        $this->multiline = $multiline;

        return $this;
    }

    /**
     * Returns the timeout in seconds.
     */
    public function getTimeout(): ?int
    {
        return $this->timeout;
    }

    /**
     * Sets the maximum time the user has to answer the question.
     * If the user does not answer within this time, an exception will be thrown.
     *
     * @return $this
     */
    public function setTimeout(?int $seconds): static
    {
        $this->timeout = $seconds;

        return $this;
    }

    /**
     * Returns whether the user response must be hidden.
     */
    public function isHidden(): bool
    {
        return $this->hidden;
    }

    /**
     * Sets whether the user response must be hidden or not.
     *
     * @return $this
     *
     * @throws LogicException In case the autocompleter is also used
Repository: symfony/symfony
File: src/Symfony/Component/HttpClient/CurlHttpClient.php (PHP)

Code before:
            \CURLOPT_REDIR_PROTOCOLS,
            \CURLOPT_COOKIEFILE,
            \CURLINFO_REDIRECT_COUNT,
        ];

        if (\defined('CURLOPT_HTTP09_ALLOWED')) {
            $curloptsToCheck[] = \CURLOPT_HTTP09_ALLOWED;
        }

        if (\defined('CURLOPT_HEADEROPT')) {
            $curloptsToCheck[] = \CURLOPT_HEADEROPT;
        }

        foreach ($options as $opt => $optValue) {
            if (isset($curloptsToConfig[$opt])) {
                $constName = $this->findConstantName($opt) ?? $opt;
                throw new InvalidArgumentException(\sprintf('Cannot set "%s" with "extra.curl", use option "%s" instead.', $constName, $curloptsToConfig[$opt]));
            }

            if (\in_array($opt, [
                \CURLOPT_POST,
                \CURLOPT_PUT,
                \CURLOPT_CUSTOMREQUEST,
                \CURLOPT_HTTPGET,
                \CURLOPT_NOBODY,
            ], true)) {
                throw new InvalidArgumentException('The HTTP method cannot be overridden using "extra.curl".');
            }

            if (\in_array($opt, $curloptsToCheck, true)) {
                $constName = $this->findConstantName($opt) ?? $opt;
                throw new InvalidArgumentException(\sprintf('Cannot set "%s" with "extra.curl".', $constName));
            }
        }
    }
}


Review comment (suggestion):
```suggestion
            if (\in_array($opt, [\CURLOPT_POST, \CURLOPT_PUT, \CURLOPT_CUSTOMREQUEST, \CURLOPT_HTTPGET, \CURLOPT_NOBODY], true)) {
```

Code after:
            \CURLOPT_REDIR_PROTOCOLS,
            \CURLOPT_COOKIEFILE,
            \CURLINFO_REDIRECT_COUNT,
        ];

        if (\defined('CURLOPT_HTTP09_ALLOWED')) {
            $curloptsToCheck[] = \CURLOPT_HTTP09_ALLOWED;
        }

        if (\defined('CURLOPT_HEADEROPT')) {
            $curloptsToCheck[] = \CURLOPT_HEADEROPT;
        }

        foreach ($options as $opt => $optValue) {
            if (isset($curloptsToConfig[$opt])) {
                $constName = $this->findConstantName($opt) ?? $opt;
                throw new InvalidArgumentException(\sprintf('Cannot set "%s" with "extra.curl", use option "%s" instead.', $constName, $curloptsToConfig[$opt]));
            }

            if (\in_array($opt, [\CURLOPT_POST, \CURLOPT_PUT, \CURLOPT_CUSTOMREQUEST, \CURLOPT_HTTPGET, \CURLOPT_NOBODY], true)) {
                throw new InvalidArgumentException('The HTTP method cannot be overridden using "extra.curl".');
            }

            if (\in_array($opt, $curloptsToCheck, true)) {
                $constName = $this->findConstantName($opt) ?? $opt;
                throw new InvalidArgumentException(\sprintf('Cannot set "%s" with "extra.curl".', $constName));
            }
        }
    }
}
Repository: symfony/symfony
File: src/Symfony/Component/Notifier/Bridge/Ntfy/NtfyOptions.php (PHP)

Code before:

        return $this;
    }

    public function setTitle(string $title): self
    {
        $this->options['title'] = $title;

        return $this;
    }

    public function setStringPriority(string $priority): self
    {
        return match ($priority) {
            Notification::IMPORTANCE_URGENT => $this->setPriority(self::PRIORITY_URGENT),
            Notification::IMPORTANCE_HIGH => $this->setPriority(self::PRIORITY_HIGH),
            Notification::IMPORTANCE_LOW => $this->setPriority(self::PRIORITY_LOW),
            default => $this->setPriority(self::PRIORITY_DEFAULT),
        };
    }

    public function setPriority(int $priority): self
    {
        if (\in_array($priority, [
            self::PRIORITY_MIN, self::PRIORITY_LOW, self::PRIORITY_DEFAULT, self::PRIORITY_HIGH, self::PRIORITY_URGENT,
        ], true)) {
            $this->options['priority'] = $priority;
        }

        return $this;
    }

    public function addTag(string $tag): self
    {
        $this->options['tags'][] = $tag;

        return $this;
    }

    public function setTags(array $tags): self
    {
        $this->options['tags'] = $tags;

        return $this;
    }

    public function setDelay(\DateTimeInterface $dateTime): self
    {
        if ($dateTime > $this->clock->now()) {
            $this->options['delay'] = (string) $dateTime->getTimestamp();
        } else {

Review comment (suggestion):
```suggestion
        if (\in_array($priority, [self::PRIORITY_MIN, self::PRIORITY_LOW, self::PRIORITY_DEFAULT, self::PRIORITY_HIGH, self::PRIORITY_URGENT], true)) {
```

Code after:

        return $this;
    }

    public function setTitle(string $title): self
    {
        $this->options['title'] = $title;

        return $this;
    }

    public function setStringPriority(string $priority): self
    {
        return match ($priority) {
            Notification::IMPORTANCE_URGENT => $this->setPriority(self::PRIORITY_URGENT),
            Notification::IMPORTANCE_HIGH => $this->setPriority(self::PRIORITY_HIGH),
            Notification::IMPORTANCE_LOW => $this->setPriority(self::PRIORITY_LOW),
            default => $this->setPriority(self::PRIORITY_DEFAULT),
        };
    }

    public function setPriority(int $priority): self
    {
        if (\in_array($priority, [self::PRIORITY_MIN, self::PRIORITY_LOW, self::PRIORITY_DEFAULT, self::PRIORITY_HIGH, self::PRIORITY_URGENT], true)) {
            $this->options['priority'] = $priority;
        }

        return $this;
    }

    public function addTag(string $tag): self
    {
        $this->options['tags'][] = $tag;

        return $this;
    }

    public function setTags(array $tags): self
    {
        $this->options['tags'] = $tags;

        return $this;
    }

    public function setDelay(\DateTimeInterface $dateTime): self
    {
        if ($dateTime > $this->clock->now()) {
            $this->options['delay'] = (string) $dateTime->getTimestamp();
        } else {
            throw new LogicException('Delayed date must be defined in the future.');
        }
Repository: symfony/symfony
File: src/Symfony/Component/Translation/TranslatableMessage.php (PHP)

Code before:
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Translation;

use Symfony\Contracts\Translation\TranslatableInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

/**
 * @author Nate Wiebe <nate@northern.co>
 */
class TranslatableMessage implements TranslatableInterface
{
    public function __construct(
        private string $message,
        private array $parameters = [],
        private ?string $domain = null,
    ) {
    }

    public function __toString(): string
    {
        trigger_deprecation('symfony/translation', '7.4', 'Calling "%s()" is deprecated.', __METHOD__);

        return $this->getMessage();
    }

    public function getMessage(): string
    {
        return $this->message;
    }

    public function getParameters(): array
    {
        return $this->parameters;
    }

    public function getDomain(): ?string
    {
        return $this->domain;
    }

    public function trans(TranslatorInterface $translator, ?string $locale = null): string
    {
        return $translator->trans($this->getMessage(), array_map(
            static fn ($parameter) => $parameter instanceof TranslatableInterface ? $parameter->trans($translator, $locale) : $parameter,
            $this->getParameters()
        ), $this->getDomain(), $locale);
    }

Review comment (suggestion):
```suggestion
    /**
     * @deprecated since symfony/constracts 3.6
     */
    public function __toString(): string
```

Code after:
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Translation;

use Symfony\Contracts\Translation\TranslatableInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

/**
 * @author Nate Wiebe <nate@northern.co>
 */
class TranslatableMessage implements TranslatableInterface
{
    public function __construct(
        private string $message,
        private array $parameters = [],
        private ?string $domain = null,
    ) {
    }

    /**
     * @deprecated since Symfony 7.4
     */
    public function __toString(): string
    {
        trigger_deprecation('symfony/translation', '7.4', 'Method "%s()" is deprecated.', __METHOD__);

        return $this->getMessage();
    }

    public function getMessage(): string
    {
        return $this->message;
    }

    public function getParameters(): array
    {
        return $this->parameters;
    }

    public function getDomain(): ?string
    {
        return $this->domain;
    }

    public function trans(TranslatorInterface $translator, ?string $locale = null): string
    {
        $parameters = $this->getParameters();
        foreach ($parameters as $k => $v) {