Skip to content

Commit b988ea0

Browse files
committed
Merge branch '7.0' into 7.1
* 7.0: replace wurstmeister Docker images for Kafka and Zookeeper [PasswordHasher] Make bcrypt nul byte hash test tolerant to PHP related failures [HttpClient] Revert fixing curl default options [VarExporter] fix proxy helper when a method returns null [Validator] Update Dutch (nl) translation Fix exception thrown during `LDAP_MODIFY_BATCH_REMOVE_ALL` batch operations Fix various warnings across components test suite
2 parents be16ed8 + 3a31f50 commit b988ea0

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

Caster/ReflectionCaster.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ public static function castFunctionAbstract(\ReflectionFunctionAbstract $c, arra
210210
if (isset($a[$prefix.'returnType'])) {
211211
$v = $a[$prefix.'returnType'];
212212
$v = $v instanceof \ReflectionNamedType ? $v->getName() : (string) $v;
213-
$a[$prefix.'returnType'] = new ClassStub($a[$prefix.'returnType'] instanceof \ReflectionNamedType && $a[$prefix.'returnType']->allowsNull() && 'mixed' !== $v ? '?'.$v : $v, [class_exists($v, false) || interface_exists($v, false) || trait_exists($v, false) ? $v : '', '']);
213+
$a[$prefix.'returnType'] = new ClassStub($a[$prefix.'returnType'] instanceof \ReflectionNamedType && $a[$prefix.'returnType']->allowsNull() && !\in_array($v, ['mixed', 'null'], true) ? '?'.$v : $v, [class_exists($v, false) || interface_exists($v, false) || trait_exists($v, false) ? $v : '', '']);
214214
}
215215
if (isset($a[$prefix.'class'])) {
216216
$a[$prefix.'class'] = new ClassStub($a[$prefix.'class']);
@@ -368,7 +368,7 @@ public static function getSignature(array $a): string
368368
if (!$type instanceof \ReflectionNamedType) {
369369
$signature .= $type.' ';
370370
} else {
371-
if ($param->allowsNull() && 'mixed' !== $type->getName()) {
371+
if ($param->allowsNull() && !\in_array($type->getName(), ['mixed', 'null'], true)) {
372372
$signature .= '?';
373373
}
374374
$signature .= substr(strrchr('\\'.$type->getName(), '\\'), 1).' ';

Tests/Caster/ReflectionCasterTest.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo;
1919
use Symfony\Component\VarDumper\Tests\Fixtures\LotsOfAttributes;
2020
use Symfony\Component\VarDumper\Tests\Fixtures\NotLoadableClass;
21+
use Symfony\Component\VarDumper\Tests\Fixtures\Php82NullStandaloneReturnType;
2122
use Symfony\Component\VarDumper\Tests\Fixtures\ReflectionIntersectionTypeFixture;
2223
use Symfony\Component\VarDumper\Tests\Fixtures\ReflectionNamedTypeFixture;
2324
use Symfony\Component\VarDumper\Tests\Fixtures\ReflectionUnionTypeFixture;
@@ -95,7 +96,7 @@ public function testClosureCaster()
9596
$b: & 123
9697
}
9798
file: "%sReflectionCasterTest.php"
98-
line: "88 to 88"
99+
line: "%s"
99100
}
100101
EOTXT
101102
, $var
@@ -403,6 +404,26 @@ class: "Symfony\Component\VarDumper\Tests\Caster\ReflectionCasterTest"
403404
);
404405
}
405406

407+
/**
408+
* @requires PHP 8.2
409+
*/
410+
public function testNullReturnType()
411+
{
412+
$className = Php82NullStandaloneReturnType::class;
413+
414+
$this->assertDumpMatchesFormat(
415+
<<<EOTXT
416+
{$className}::foo(null \$bar): null {
417+
returnType: "null"
418+
this: {$className} { …}
419+
file: "%s"
420+
line: "%s"
421+
}
422+
EOTXT
423+
, (new Php82NullStandaloneReturnType())->foo(...)
424+
);
425+
}
426+
406427
public function testUnionReturnType()
407428
{
408429
$f = function (): int|float {};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\VarDumper\Tests\Fixtures;
13+
14+
class Php82NullStandaloneReturnType
15+
{
16+
public function foo(null $bar): null
17+
{
18+
return null;
19+
}
20+
}

0 commit comments

Comments
 (0)