[ErrorHandler][DebugClassLoader] Add mixed and static return types support

This commit is contained in:
Thomas Calvet 2020-07-15 16:12:42 +02:00
parent 0f92b9a584
commit 0533f1f63e
4 changed files with 55 additions and 18 deletions

View File

@ -49,12 +49,9 @@ use ProxyManager\Proxy\ProxyInterface;
class DebugClassLoader
{
private const SPECIAL_RETURN_TYPES = [
'mixed' => 'mixed',
'void' => 'void',
'null' => 'null',
'resource' => 'resource',
'static' => 'object',
'$this' => 'object',
'boolean' => 'bool',
'true' => 'bool',
'false' => 'bool',
@ -69,7 +66,13 @@ class DebugClassLoader
'string' => 'string',
'self' => 'self',
'parent' => 'parent',
];
] + (\PHP_VERSION_ID >= 80000 ? [
'$this' => 'static',
] : [
'mixed' => 'mixed',
'static' => 'object',
'$this' => 'object',
]);
private const BUILTIN_RETURN_TYPES = [
'void' => true,
@ -83,7 +86,10 @@ class DebugClassLoader
'string' => true,
'self' => true,
'parent' => true,
];
] + (\PHP_VERSION_ID >= 80000 ? [
'mixed' => true,
'static' => true,
] : []);
private const MAGIC_METHODS = [
'__set' => 'void',
@ -856,7 +862,7 @@ class DebugClassLoader
}
}
if ('void' === $normalizedType) {
if ('void' === $normalizedType || (\PHP_VERSION_ID >= 80000 && 'mixed' === $normalizedType)) {
$nullable = false;
} elseif (!isset(self::BUILTIN_RETURN_TYPES[$normalizedType]) && isset(self::SPECIAL_RETURN_TYPES[$normalizedType])) {
// ignore other special return types

View File

@ -370,7 +370,7 @@ class DebugClassLoaderTest extends TestCase
error_reporting($e);
restore_error_handler();
$this->assertSame([
$this->assertSame(array_merge([
'Method "Symfony\Component\ErrorHandler\Tests\Fixtures\ReturnTypeGrandParent::returnTypeGrandParent()" will return "string" as of its next major version. Doing the same in child class "Test\Symfony\Component\ErrorHandler\Tests\ReturnType" will be required when upgrading.',
'Method "Symfony\Component\ErrorHandler\Tests\Fixtures\ReturnTypeParentInterface::returnTypeParentInterface()" will return "string" as of its next major version. Doing the same in implementation "Test\Symfony\Component\ErrorHandler\Tests\ReturnType" will be required when upgrading.',
'Method "Symfony\Component\ErrorHandler\Tests\Fixtures\ReturnTypeInterface::returnTypeInterface()" will return "string" as of its next major version. Doing the same in implementation "Test\Symfony\Component\ErrorHandler\Tests\ReturnType" will be required when upgrading.',
@ -383,14 +383,21 @@ class DebugClassLoaderTest extends TestCase
'Method "Symfony\Component\ErrorHandler\Tests\Fixtures\ReturnTypeParent::manyIterables()" will return "array" as of its next major version. Doing the same in child class "Test\Symfony\Component\ErrorHandler\Tests\ReturnType" will be required when upgrading.',
'Method "Symfony\Component\ErrorHandler\Tests\Fixtures\ReturnTypeParent::nullableReturnableTypeNormalization()" will return "object" as of its next major version. Doing the same in child class "Test\Symfony\Component\ErrorHandler\Tests\ReturnType" will be required when upgrading.',
'Method "Symfony\Component\ErrorHandler\Tests\Fixtures\ReturnTypeParent::nonNullableReturnableTypeNormalization()" will return "void" as of its next major version. Doing the same in child class "Test\Symfony\Component\ErrorHandler\Tests\ReturnType" will be required when upgrading.',
'Method "Symfony\Component\ErrorHandler\Tests\Fixtures\ReturnTypeParent::commonNonObjectReturnedTypeNormalization()" will return "object" as of its next major version. Doing the same in child class "Test\Symfony\Component\ErrorHandler\Tests\ReturnType" will be required when upgrading.',
'Method "Symfony\Component\ErrorHandler\Tests\Fixtures\ReturnTypeParent::bracketsNormalization()" will return "array" as of its next major version. Doing the same in child class "Test\Symfony\Component\ErrorHandler\Tests\ReturnType" will be required when upgrading.',
'Method "Symfony\Component\ErrorHandler\Tests\Fixtures\ReturnTypeParent::booleanNormalization()" will return "bool" as of its next major version. Doing the same in child class "Test\Symfony\Component\ErrorHandler\Tests\ReturnType" will be required when upgrading.',
'Method "Symfony\Component\ErrorHandler\Tests\Fixtures\ReturnTypeParent::callableNormalization1()" will return "callable" as of its next major version. Doing the same in child class "Test\Symfony\Component\ErrorHandler\Tests\ReturnType" will be required when upgrading.',
'Method "Symfony\Component\ErrorHandler\Tests\Fixtures\ReturnTypeParent::callableNormalization2()" will return "callable" as of its next major version. Doing the same in child class "Test\Symfony\Component\ErrorHandler\Tests\ReturnType" will be required when upgrading.',
'Method "Symfony\Component\ErrorHandler\Tests\Fixtures\ReturnTypeParent::otherTypeNormalization()" will return "\ArrayIterator" as of its next major version. Doing the same in child class "Test\Symfony\Component\ErrorHandler\Tests\ReturnType" will be required when upgrading.',
'Method "Symfony\Component\ErrorHandler\Tests\Fixtures\ReturnTypeParent::arrayWithLessThanSignNormalization()" will return "array" as of its next major version. Doing the same in child class "Test\Symfony\Component\ErrorHandler\Tests\ReturnType" will be required when upgrading.',
], $deprecations);
], \PHP_VERSION_ID >= 80000 ? [
'Method "Symfony\Component\ErrorHandler\Tests\Fixtures\ReturnTypeParent::this()" will return "static" as of its next major version. Doing the same in child class "Test\Symfony\Component\ErrorHandler\Tests\ReturnType" will be required when upgrading.',
'Method "Symfony\Component\ErrorHandler\Tests\Fixtures\ReturnTypeParent::mixed()" will return "mixed" as of its next major version. Doing the same in child class "Test\Symfony\Component\ErrorHandler\Tests\ReturnType" will be required when upgrading.',
'Method "Symfony\Component\ErrorHandler\Tests\Fixtures\ReturnTypeParent::nullableMixed()" will return "mixed" as of its next major version. Doing the same in child class "Test\Symfony\Component\ErrorHandler\Tests\ReturnType" will be required when upgrading.',
'Method "Symfony\Component\ErrorHandler\Tests\Fixtures\ReturnTypeParent::static()" will return "static" as of its next major version. Doing the same in child class "Test\Symfony\Component\ErrorHandler\Tests\ReturnType" will be required when upgrading.',
] : [
'Method "Symfony\Component\ErrorHandler\Tests\Fixtures\ReturnTypeParent::this()" will return "object" as of its next major version. Doing the same in child class "Test\Symfony\Component\ErrorHandler\Tests\ReturnType" will be required when upgrading.',
'Method "Symfony\Component\ErrorHandler\Tests\Fixtures\ReturnTypeParent::static()" will return "object" as of its next major version. Doing the same in child class "Test\Symfony\Component\ErrorHandler\Tests\ReturnType" will be required when upgrading.',
]), $deprecations);
}
}

View File

@ -35,12 +35,15 @@ class ReturnType extends ReturnTypeParent implements ReturnTypeInterface, Fixtur
public function manyIterables() { }
public function nullableReturnableTypeNormalization() { }
public function nonNullableReturnableTypeNormalization() { }
public function commonNonObjectReturnedTypeNormalization() { }
public function bracketsNormalization() { }
public function booleanNormalization() { }
public function callableNormalization1() { }
public function callableNormalization2() { }
public function otherTypeNormalization() { }
public function arrayWithLessThanSignNormalization() { }
public function this() { }
public function mixed() { }
public function nullableMixed() { }
public function static() { }
public function outsideMethod() { }
}

View File

@ -29,7 +29,7 @@ abstract class ReturnTypeParent extends ReturnTypeGrandParent implements ReturnT
abstract public function realReturnTypeIsAlreadyThereWithNull();
/**
* @return mixed
* @return resource
*/
public function oneCommonNonObjectReturnedType()
{
@ -143,13 +143,6 @@ abstract class ReturnTypeParent extends ReturnTypeGrandParent implements ReturnT
{
}
/**
* @return $this
*/
public function commonNonObjectReturnedTypeNormalization()
{
}
/**
* @return \ArrayIterator[]
*/
@ -192,6 +185,34 @@ abstract class ReturnTypeParent extends ReturnTypeGrandParent implements ReturnT
{
}
/**
* @return $this
*/
public function this()
{
}
/**
* @return mixed
*/
public function mixed()
{
}
/**
* @return mixed|null
*/
public function nullableMixed()
{
}
/**
* @return static
*/
public function static()
{
}
/**
* @return int
*/