Skip to content

[ErrorHandler] [DebugClassLoader] Fix some new return types support #48618

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/Symfony/Component/ErrorHandler/DebugClassLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class DebugClassLoader
'null' => 'null',
'resource' => 'resource',
'boolean' => 'bool',
'true' => 'bool',
'true' => 'true',
'false' => 'false',
'integer' => 'int',
'array' => 'array',
Expand All @@ -74,6 +74,7 @@ class DebugClassLoader
'$this' => 'static',
'list' => 'array',
'class-string' => 'string',
'never' => 'never',
];

private const BUILTIN_RETURN_TYPES = [
Expand All @@ -91,6 +92,9 @@ class DebugClassLoader
'parent' => true,
'mixed' => true,
'static' => true,
'null' => true,
'true' => true,
'never' => true,
];

private const MAGIC_METHODS = [
Expand Down Expand Up @@ -762,6 +766,12 @@ private function setReturnType(string $types, string $class, string $method, str
return;
}

if ('null' === $types) {
self::$returnTypes[$class][$method] = ['null', 'null', $class, $filename];

return;
}

if ($nullable = 0 === strpos($types, 'null|')) {
$types = substr($types, 5);
} elseif ($nullable = '|null' === substr($types, -5)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,10 @@ class_exists('Test\\'.ReturnType::class, true);
'Method "Symfony\Component\ErrorHandler\Tests\Fixtures\ReturnTypeParent::mixed()" might add "mixed" as a native return type declaration in the future. Do the same in child class "Test\Symfony\Component\ErrorHandler\Tests\ReturnType" now to avoid errors or add an explicit @return annotation to suppress this message.',
'Method "Symfony\Component\ErrorHandler\Tests\Fixtures\ReturnTypeParent::nullableMixed()" might add "mixed" as a native return type declaration in the future. Do the same in child class "Test\Symfony\Component\ErrorHandler\Tests\ReturnType" now to avoid errors or add an explicit @return annotation to suppress this message.',
'Method "Symfony\Component\ErrorHandler\Tests\Fixtures\ReturnTypeParent::static()" might add "static" as a native return type declaration in the future. Do the same in child class "Test\Symfony\Component\ErrorHandler\Tests\ReturnType" now to avoid errors or add an explicit @return annotation to suppress this message.',
'Method "Symfony\Component\ErrorHandler\Tests\Fixtures\ReturnTypeParent::false()" might add "false" as a native return type declaration in the future. Do the same in child class "Test\Symfony\Component\ErrorHandler\Tests\ReturnType" now to avoid errors or add an explicit @return annotation to suppress this message.',
'Method "Symfony\Component\ErrorHandler\Tests\Fixtures\ReturnTypeParent::true()" might add "true" as a native return type declaration in the future. Do the same in child class "Test\Symfony\Component\ErrorHandler\Tests\ReturnType" now to avoid errors or add an explicit @return annotation to suppress this message.',
'Method "Symfony\Component\ErrorHandler\Tests\Fixtures\ReturnTypeParent::never()" might add "never" as a native return type declaration in the future. Do the same in child class "Test\Symfony\Component\ErrorHandler\Tests\ReturnType" now to avoid errors or add an explicit @return annotation to suppress this message.',
'Method "Symfony\Component\ErrorHandler\Tests\Fixtures\ReturnTypeParent::null()" might add "null" as a native return type declaration in the future. Do the same in child class "Test\Symfony\Component\ErrorHandler\Tests\ReturnType" now to avoid errors or add an explicit @return annotation to suppress this message.',
]), $deprecations);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,9 @@ public function this() { }
public function mixed() { }
public function nullableMixed() { }
public function static() { }
public function false() { }
public function true() { }
public function never() { }
public function null() { }
public function outsideMethod() { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,34 @@ public function static()
{
}

/**
* @return false
*/
public function false()
{
}

/**
* @return true
*/
public function true()
{
}

/**
* @return never
*/
public function never()
{
}

/**
* @return null
*/
public function null()
{
}

/**
* @return int
*/
Expand Down