Skip to content

Commit 7305720

Browse files
committed
[ErrorHandler][DebugClassLoader] Fix some new return types support
1 parent 539cf14 commit 7305720

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed

DebugClassLoader.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class DebugClassLoader
5656
'null' => 'null',
5757
'resource' => 'resource',
5858
'boolean' => 'bool',
59-
'true' => 'bool',
59+
'true' => 'true',
6060
'false' => 'false',
6161
'integer' => 'int',
6262
'array' => 'array',
@@ -74,6 +74,7 @@ class DebugClassLoader
7474
'$this' => 'static',
7575
'list' => 'array',
7676
'class-string' => 'string',
77+
'never' => 'never',
7778
];
7879

7980
private const BUILTIN_RETURN_TYPES = [
@@ -91,6 +92,9 @@ class DebugClassLoader
9192
'parent' => true,
9293
'mixed' => true,
9394
'static' => true,
95+
'null' => true,
96+
'true' => true,
97+
'never' => true,
9498
];
9599

96100
private const MAGIC_METHODS = [
@@ -762,6 +766,12 @@ private function setReturnType(string $types, string $class, string $method, str
762766
return;
763767
}
764768

769+
if ('null' === $types) {
770+
self::$returnTypes[$class][$method] = ['null', 'null', $class, $filename];
771+
772+
return;
773+
}
774+
765775
if ($nullable = 0 === strpos($types, 'null|')) {
766776
$types = substr($types, 5);
767777
} elseif ($nullable = '|null' === substr($types, -5)) {

Tests/DebugClassLoaderTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,10 @@ class_exists('Test\\'.ReturnType::class, true);
402402
'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.',
403403
'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.',
404404
'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.',
405+
'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.',
406+
'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.',
407+
'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.',
408+
'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.',
405409
]), $deprecations);
406410
}
407411
}

Tests/Fixtures/ReturnType.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,9 @@ public function this() { }
4646
public function mixed() { }
4747
public function nullableMixed() { }
4848
public function static() { }
49+
public function false() { }
50+
public function true() { }
51+
public function never() { }
52+
public function null() { }
4953
public function outsideMethod() { }
5054
}

Tests/Fixtures/ReturnTypeParent.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,34 @@ public function static()
220220
{
221221
}
222222

223+
/**
224+
* @return false
225+
*/
226+
public function false()
227+
{
228+
}
229+
230+
/**
231+
* @return true
232+
*/
233+
public function true()
234+
{
235+
}
236+
237+
/**
238+
* @return never
239+
*/
240+
public function never()
241+
{
242+
}
243+
244+
/**
245+
* @return null
246+
*/
247+
public function null()
248+
{
249+
}
250+
223251
/**
224252
* @return int
225253
*/

0 commit comments

Comments
 (0)