8000 use proper return types in ErrorHandler and ArgumentResolver · symfony/symfony@2f9121b · GitHub
[go: up one dir, main page]

Skip to content

Commit 2f9121b

Browse files
committed
use proper return types in ErrorHandler and ArgumentResolver
1 parent aa4385d commit 2f9121b

File tree

6 files changed

+23
-34
lines changed
  • Controller
  • Tests/Controller
  • 6 files changed

    +23
    -34
    lines changed

    src/Symfony/Component/Debug/ErrorHandler.php

    Lines changed: 2 additions & 7 deletions
    Original file line numberDiff line numberDiff line change
    @@ -369,18 +369,13 @@ private function reRegister($prev)
    369369
    /**
    370370
    * Handles errors by filtering then logging them according to the configured bit fields.
    371371
    *
    372-
    * @param int $type One of the E_* constants
    373-
    * @param string $message
    374-
    * @param string $file
    375-
    * @param int $line
    376-
    *
    377372
    * @return bool Returns false when no handling happens so that the PHP engine can handle the error itself
    378373
    *
    379374
    * @throws \ErrorException When $this->thrownErrors requests so
    380375
    *
    381376
    * @internal
    382377
    */
    383-
    public function handleError($type, $message, $file, $line)
    378+
    public function handleError(int $type, string $message, string $file, int $line): bool
    384379
    {
    385380
    // @deprecated to be removed in Symfony 5.0
    386381
    if (\PHP_VERSION_ID >= 70300 && $message && '"' === $message[0] && 0 === strpos($message, '"continue') && preg_match('/^"continue(?: \d++)?" targeting switch is equivalent to "break(?: \d++)?"\. Did you mean to use "continue(?: \d++)?"\?$/', $message)) {
    @@ -443,7 +438,7 @@ public function handleError($type, $message, $file, $line)
    443438
    self::$silencedError 8000 Cache[$id][$message] = $errorAsException;
    444439
    }
    445440
    if (null === $lightTrace) {
    446-
    return;
    441+
    return true;
    447442
    }
    448443
    } else {
    449444
    $errorAsException = new \ErrorException($logMessage, 0, $type, $file, $line);

    src/Symfony/Component/HttpKernel/Controller/ArgumentResolver.php

    Lines changed: 6 additions & 4 deletions
    Original file line numberDiff line numberDiff line change
    @@ -55,14 +55,16 @@ public function getArguments(Request $request, $controller)
    5555

    5656
    $resolved = $resolver->resolve($request, $metadata);
    5757

    58-
    if (!$resolved instanceof \Generator) {
    59-
    throw new \InvalidArgumentException(sprintf('%s::resolve() must yield at least one value.', \get_class($resolver)));
    60-
    }
    61-
    58+
    $atLeastOne = false;
    6259
    foreach ($resolved as $append) {
    60+
    $atLeastOne = true;
    6361
    $arguments[] = $append;
    6462
    }
    6563

    64+
    if (!$atLeastOne) {
    65+
    throw new \InvalidArgumentException(sprintf('%s::resolve() must yield at least one value.', \get_class($resolver)));
    66+
    }
    67+
    6668
    // continue to the next controller argument
    6769
    continue 2;
    6870
    }

    src/Symfony/Component/HttpKernel/Controller/ArgumentResolver/VariadicValueResolver.php

    Lines changed: 1 addition & 3 deletions
    Original file line numberDiff line numberDiff line change
    @@ -41,8 +41,6 @@ public function resolve(Request $request, ArgumentMetadata $argument)
    4141
    throw new \InvalidArgumentException(sprintf('The action argument "...$%1$s" is required to be an array, the request attribute "%1$s" contains a type of "%2$s" instead.', $argument->getName(), \gettype($values)));
    4242
    }
    4343

    44-
    foreach ($values as $value) {
    45-
    yield $value;
    46-
    }
    44+
    yield from $values;
    4745
    }
    4846
    }

    src/Symfony/Component/HttpKernel/Controller/ArgumentValueResolverInterface.php

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -37,7 +37,7 @@ public function supports(Request $request, ArgumentMetadata $argument);
    3737
    * @param Request $request
    3838
    * @param ArgumentMetadata $argument
    3939
    *
    40-
    * @return \Generator
    40+
    * @return iterable
    4141
    */
    4242
    public function resolve(Request $request, ArgumentMetadata $argument);
    4343
    }

    src/Symfony/Component/HttpKernel/ControllerMetadata/ArgumentMetadataFactory.php

    Lines changed: 12 additions & 18 deletions
    Original file line numberDiff line numberDiff line change
    @@ -42,30 +42,24 @@ public function createArgumentMetadata($controller)
    4242

    4343
    /**
    4444
    * Returns an associated type to the given parameter if available.
    45-
    *
    46-
    * @param \ReflectionParameter $parameter
    47-
    *
    48-
    * @return string|null
    4945
    */
    50-
    private function getType(\ReflectionParameter $parameter, \ReflectionFunctionAbstract $function)
    46+
    private function getType(\ReflectionParameter $parameter, \ReflectionFunctionAbstract $function): ?string
    5147
    {
    5248
    if (!$type = $parameter->getType()) {
    53-
    return;
    49+
    return null;
    5450
    }
    5551
    $name = $type->getName();
    56-
    $lcName = strtolower($name);
    5752

    58-
    if ('self' !== $lcName && 'parent' !== $lcName) {
    59-
    return $name;
    60-
    }
    61-
    if (!$function instanceof \ReflectionMethod) {
    62-
    return;
    63-
    }
    64-
    if ('self' === $lcName) {
    65-
    return $function->getDeclaringClass()->name;
    66-
    }
    67-
    if ($parent = $function->getDeclaringClass()->getParentClass()) {
    68-
    return $parent->name;
    53+
    if ($function instanceof \ReflectionMethod) {
    54+
    $lcName = strtolower($name);
    55+
    switch ($lcName) {
    56+
    case 'self':
    57+
    return $function->getDeclaringClass()->name;
    58+
    case 'parent':
    59+
    return ($parent = $function->getDeclaringClass()->getParentClass()) ? $parent->name : null;
    60+
    }
    6961
    }
    62+
    63+
    return $name;
    7064
    }
    7165
    }

    src/Symfony/Component/HttpKernel/Tests/Controller/ArgumentResolverTest.php

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -185,7 +185,7 @@ public function testGetArgumentWithoutArray()
    185185
    $resolver = new ArgumentResolver($factory, [$valueResolver]);
    186186

    187187
    $valueResolver->expects($this->any())->method('supports')->willReturn(true);
    188-
    $valueResolver->expects($this->any())->method('resolve')->willReturn('foo');
    188+
    $valueResolver->expects($this->any())->method('resolve')->willReturn([]);
    189189

    190190
    $request = Request::create('/');
    191191
    $request->attributes->set('foo', 'foo');

    0 commit comments

    Comments
     (0)
    0