Skip to content

Commit a6950a1

Browse files
authored
Fix ObjectType resolving inside bound Closure
1 parent fbdec4a commit a6950a1

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

src/Analyser/MutatingScope.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2316,7 +2316,7 @@ public function resolveTypeByName(Name $name): TypeWithClassName
23162316

23172317
$originalClass = $this->resolveName($name);
23182318
if ($this->isInClass()) {
2319-
if ($this->inClosureBindScopeClass !== null && $this->inClosureBindScopeClass !== 'static' && $originalClass === $this->getClassReflection()->getName()) {
2319+
if ($this->inClosureBindScopeClass === $originalClass) {
23202320
if ($this->reflectionProvider->hasClass($this->inClosureBindScopeClass)) {
23212321
return new ThisType($this->reflectionProvider->getClass($this->inClosureBindScopeClass));
23222322
}

tests/PHPStan/Rules/Classes/ClassConstantRuleTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,4 +276,10 @@ public function testRuleWithNullsafeVariant(): void
276276
$this->analyse([__DIR__ . '/data/class-constant-nullsafe.php'], []);
277277
}
278278

279+
public function testBug7675(): void
280+
{
281+
$this->phpVersion = PHP_VERSION_ID;
282+
$this->analyse([__DIR__ . '/data/bug-7675.php'], []);
283+
}
284+
279285
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug7675;
4+
5+
use Closure;
6+
use Throwable;
7+
8+
class Handler
9+
{
10+
}
11+
12+
class SpladeCore
13+
{
14+
const HEADER_SPLADE = 'x-splade';
15+
public static function exceptionHandler(Handler $exceptionHandler): Closure
16+
{
17+
return Closure::bind(function (Throwable $e, $request) {
18+
if (!$request->header(SpladeCore::HEADER_SPLADE)) {
19+
return null;
20+
}
21+
22+
return true;
23+
}, $exceptionHandler, get_class($exceptionHandler));
24+
}
25+
}

0 commit comments

Comments
 (0)