8000 bug #37586 [ErrorHandler][DebugClassLoader] Add mixed and static retu… · symfony/symfony@d6b9936 · GitHub
[go: up one dir, main page]

Skip to content

Commit d6b9936

Browse files
committed
bug #37586 [ErrorHandler][DebugClassLoader] Add mixed and static return types support (fancyweb)
This PR was merged into the 4.4 branch. Discussion ---------- [ErrorHandler][DebugClassLoader] Add mixed and static return types support | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Commits ------- 0533f1f [ErrorHandler][DebugClassLoader] Add mixed and static return types support
2 parents 803a257 + 0533f1f commit d6b9936

File tree

4 files changed

+55
-18
lines changed

4 files changed

+55
-18
lines changed

src/Symfony/Component/ErrorHandler/DebugClassLoader.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
4949
class DebugClassLoader
5050
{
5151
private const SPECIAL_RETURN_TYPES = [
52-
'mixed' => 'mixed',
5352
'void' => 'void',
5453
'null' => 'null',
5554
'resource' => 'resource',
56-
'static' => 'object',
57-
'$this' => 'object',
5855
'boolean' => 'bool',
5956
'true' => 'bool',
6057
'false' => 'bool',
@@ -69,7 +66,13 @@ class DebugClassLoader
6966
'string' => 'string',
7067
'self' => 'self',
7168
'parent' => 'parent',
72-
];
69+
] + (\PHP_VERSION_ID >= 80000 ? [
70+
'$this' => 'static',
71+
] : [
72+
'mixed' => 'mixed',
73+
'static' => 'object',
74+
'$this' => 'object',
75+
]);
7376

7477
private const BUILTIN_RETURN_TYPES = [
7578
'void' => true,
@@ -83,7 +86,10 @@ class DebugClassLoader
8386
'string' => true,
8487
'self' => true,
8588
'parent' => true,
86-
];
89+
] + (\PHP_VERSION_ID >= 80000 ? [
90+
'mixed' => true,
91+
'static' => true,
92+
] : []);
8793

8894
private 8000 const MAGIC_METHODS = [
8995
'__set' => 'void',
@@ -856,7 +862,7 @@ private function setReturnType(string $types, \ReflectionMethod $method, ?string
856862
}
857863
}
858864

859-
if ('void' === $normalizedType) {
865+
if ('void' === $normalizedType || (\PHP_VERSION_ID >= 80000 && 'mixed' === $normalizedType)) {
860866
$nullable = false;
861867
} elseif (!isset(self::BUILTIN_RETURN_TYPES[$normalizedType]) && isset(self::SPECIAL_RETURN_TYPES[$normalizedType])) {
862868
// ignore other special return types

src/Symfony/Component/ErrorHandler/Tests/DebugClassLoaderTest.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ class_exists('Test\\'.ReturnType::class, true);
370370
error_reporting($e);
371371
restore_error_handler();
372372

373-
$this->assertSame([
373+
$this->assertSame(array_merge([
374374
'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.',
375375
'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.',
376376
'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_exists('Test\\'.ReturnType::class, true);
383383
'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.',
384384
'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.',
385385
'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.',
386-
'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.',
387386
'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.',
388387
'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.',
389388
'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.',
390389
'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.',
391390
'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.',
392391
'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.',
393-
], $deprecations);
392+
], \PHP_VERSION_ID >= 80000 ? [
393+
'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.',
394+
'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.',
395+
'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.',
396+
'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.',
397+
] : [
398+
'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.',
399+
'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.',
400+
]), $deprecations);
394401
}
395402
}
396403

src/Symfony/Component/ErrorHandler/Tests/Fixtures/ReturnType.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,15 @@ public function optOutThroughDoc() { }
3535
public function manyIterables() { }
3636
public function nullableReturnableTypeNormalization() { }
3737
public function nonNullableReturnableTypeNormalization() { }
38-
public function commonNonObjectReturnedTypeNormalization() { }
3938
public function bracketsNormalization() { }
4039
public function booleanNormalization() { }
4140
public function callableNormalization1() { }
4241
public function callableNormalization2() { }
4342
public function otherTypeNormalization() { }
4443
public function arrayWithLessThanSignNormalization() { }
44+
public function this() { }
45+
public function mixed() { }
46+
public function nullableMixed() { }
47+
public function static() { }
4548
public function outsideMethod() { }
4649
}

src/Symfony/Component/ErrorHandler/Tests/Fixtures/ReturnTypeParent.php

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function realReturnTypeIsAlreadyThere()
2929
abstract public function realReturnTypeIsAlreadyThereWithNull();
3030

3131
/**
32-
* @return mixed
32+
* @return resource
3333
*/
3434
public function oneCommonNonObjectReturnedType()
3535
{
@@ -143,13 +143,6 @@ public function nonNullableReturnableTypeNormalization()
143143
{
144144
}
145145

146-
/**
147-
* @return $this
148-
*/
149-
public function commonNonObjectReturnedTypeNormalization()
150-
{
151-
}
152-
153146
/**
154147
* @return \ArrayIterator[]
155148
*/
@@ -192,6 +185,34 @@ public function arrayWithLessThanSignNormalization()
192185
{
193186
}
194187

188+
/**
189+
* @return $this
190+
*/
191+
public function this()
192+
{
193+
}
194+
195+
/**
196+
* @return mixed
197+
*/
198+
public function mixed()
199+
{
200+
}
201+
202+
/**
203+
* @return mixed|null
204+
*/
205+
public function nullableMixed()
206+
{
207+
}
208+
209+
/**
210+
* @return static
211+
*/
212+
public function static()
213+
{
214+
}
215+
195216
/**
196217
* @return int
197218
*/

0 commit comments

Comments
 (0)
0