minor #33343 [ErrorHandler] make DebugClassLoader turn multi-types declarations to "object" (nicolas-grekas)
This PR was merged into the 4.4 branch.
Discussion
----------
[ErrorHandler] make DebugClassLoader turn multi-types declarations to "object"
| Q | A
| ------------- | ---
| Branch? | 4.4
| Bug fix? | no
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | -
When `@return Foo|Bar` is found, this makes DebugClassLoader generate an `object` return type.
When all classes in the combo type contain `Iterator`, it generates an `iterable` type instead.
Commits
-------
0abd2712e9
[ErrorHandler] make DebugClassLoader turn multi-types declarations to "object"
This commit is contained in:
commit
3debf910fb
@ -752,6 +752,14 @@ class DebugClassLoader
|
||||
unset($typesMap['array']);
|
||||
}
|
||||
|
||||
$iterable = $object = true;
|
||||
foreach ($typesMap as $n => $t) {
|
||||
if ('null' !== $n) {
|
||||
$iterable = $iterable && (\in_array($n, ['array', 'iterable']) || false !== strpos($n, 'Iterator'));
|
||||
$object = $object && (\in_array($n, ['callable', 'object', '$this', 'static']) || !isset(self::SPECIAL_RETURN_TYPES[$n]));
|
||||
}
|
||||
}
|
||||
|
||||
$normalizedType = key($typesMap);
|
||||
$returnType = current($typesMap);
|
||||
|
||||
@ -762,10 +770,16 @@ class DebugClassLoader
|
||||
$normalizedType = $t;
|
||||
$returnType = $t;
|
||||
} elseif ($n !== $normalizedType || !preg_match('/^\\\\?[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+(?:\\\\[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+)*+$/', $n)) {
|
||||
if ($iterable) {
|
||||
$normalizedType = $returnType = 'iterable';
|
||||
} elseif ($object) {
|
||||
$normalizedType = $returnType = 'object';
|
||||
} else {
|
||||
// ignore multi-types return declarations
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ('void' === $normalizedType) {
|
||||
$nullable = false;
|
||||
|
@ -13,7 +13,10 @@ namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler;
|
||||
|
||||
class RedisArraySessionHandlerTest extends AbstractRedisSessionHandlerTestCase
|
||||
{
|
||||
protected function createRedisClient(string $host): \RedisArray
|
||||
/**
|
||||
* @return \RedisArray|object
|
||||
*/
|
||||
protected function createRedisClient(string $host)
|
||||
{
|
||||
return new \RedisArray([$host]);
|
||||
}
|
||||
|
@ -24,7 +24,10 @@ class RedisClusterSessionHandlerTest extends AbstractRedisSessionHandlerTestCase
|
||||
}
|
||||
}
|
||||
|
||||
protected function createRedisClient(string $host): \RedisCluster
|
||||
/**
|
||||
* @return \RedisCluster|object
|
||||
*/
|
||||
protected function createRedisClient(string $host)
|
||||
{
|
||||
return new \RedisCluster(null, explode(' ', getenv('REDIS_CLUSTER_HOSTS')));
|
||||
}
|
||||
|
@ -13,7 +13,10 @@ namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler;
|
||||
|
||||
class RedisSessionHandlerTest extends AbstractRedisSessionHandlerTestCase
|
||||
{
|
||||
protected function createRedisClient(string $host): \Redis
|
||||
/**
|
||||
* @return \Redis|object
|
||||
*/
|
||||
protected function createRedisClient(string $host)
|
||||
{
|
||||
$client = new \Redis();
|
||||
$client->connect($host);
|
||||
|
Reference in New Issue
Block a user