Skip to content

Commit b5a84eb

Browse files
committed
Fix ClosureTypeFactory
1 parent 94b6012 commit b5a84eb

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

build/baseline-8.0.neon

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,37 @@
11
parameters:
22
ignoreErrors:
33
-
4-
message: "#^Strict comparison using \\=\\=\\= between list<callable\\(string\\): void> and false will always evaluate to false\\.$#"
4+
message: '#^Strict comparison using \=\=\= between list\<callable\(string\)\: void\> and false will always evaluate to false\.$#'
5+
identifier: identical.alwaysFalse
56
count: 1
67
path: ../src/Reflection/BetterReflection/SourceLocator/AutoloadSourceLocator.php
78

89
-
9-
message: "#^Strict comparison using \\=\\=\\= between list\\<non\\-falsy\\-string\\> and false will always evaluate to false\\.$#"
10+
message: '#^Call to function method_exists\(\) with ReflectionFunction and ''getClosureCalledCla…'' will always evaluate to true\.$#'
11+
identifier: function.alreadyNarrowedType
12+
count: 1
13+
path: ../src/Type/ClosureTypeFactory.php
14+
15+
-
16+
message: '#^Strict comparison using \=\=\= between list\<non\-falsy\-string\> and false will always evaluate to false\.$#'
17+
identifier: identical.alwaysFalse
1018
count: 1
1119
path: ../src/Type/Php/MbFunctionsReturnTypeExtension.php
1220

1321
-
14-
message: "#^Strict comparison using \\=\\=\\= between int<0, max> and false will always evaluate to false\\.$#"
22+
message: '#^Strict comparison using \=\=\= between int\<0, max\> and false will always evaluate to false\.$#'
23+
identifier: identical.alwaysFalse
1524
count: 1
1625
path: ../src/Type/Php/MbStrlenFunctionReturnTypeExtension.php
1726

1827
-
19-
message: "#^Strict comparison using \\=\\=\\= between list\\<non\\-falsy\\-string\\> and false will always evaluate to false\\.$#"
28+
message: '#^Strict comparison using \=\=\= between list\<non\-falsy\-string\> and false will always evaluate to false\.$#'
29+
identifier: identical.alwaysFalse
2030
count: 1
2131
path: ../src/Type/Php/MbStrlenFunctionReturnTypeExtension.php
2232

2333
-
24-
message: "#^Strict comparison using \\=\\=\\= between list\\<non\\-falsy\\-string\\> and false will always evaluate to false\\.$#"
34+
message: '#^Strict comparison using \=\=\= between list\<non\-falsy\-string\> and false will always evaluate to false\.$#'
35+
identifier: identical.alwaysFalse
2536
count: 1
2637
path: ../src/Type/Php/StrSplitFunctionReturnTypeExtension.php

src/Type/ClosureTypeFactory.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use ReflectionFunction;
2525
use function array_map;
2626
use function count;
27+
use function method_exists;
2728
use function str_replace;
2829

2930
/**
@@ -121,12 +122,18 @@ public function getDefaultValue(): ?Type
121122
}, $betterReflectionFunction->getParameters());
122123

123124
$selfClass = null;
124-
if ($closureReflectionFunction->getClosureCalledClass() !== null) {
125+
if (method_exists($closureReflectionFunction, 'getClosureCalledClass') && $closureReflectionFunction->getClosureCalledClass() !== null) {
125126
$potentialSelfClassName = $closureReflectionFunction->getClosureCalledClass()->getName();
126127
$reflectionProvider = $this->reflectionProviderProvider->getReflectionProvider();
127128
if ($reflectionProvider->hasClass($potentialSelfClassName)) {
128129
$selfClass = $reflectionProvider->getClass($potentialSelfClassName);
129130
}
131+
} elseif ($closureReflectionFunction->getClosureScopeClass() !== null) {
132+
$potentialSelfClassName = $closureReflectionFunction->getClosureScopeClass()->getName();
133+
$reflectionProvider = $this->reflectionProviderProvider->getReflectionProvider();
134+
if ($reflectionProvider->hasClass($potentialSelfClassName)) {
135+
$selfClass = $reflectionProvider->getClass($potentialSelfClassName);
136+
}
130137
}
131138

132139
return new ClosureType($parameters, TypehintHelper::decideTypeFromReflection(ReflectionType::fromTypeOrNull($betterReflectionFunction->getReturnType()), selfClass: $selfClass), $betterReflectionFunction->isVariadic());

0 commit comments

Comments
 (0)