Skip to content

Commit 3f2f39b

Browse files
committed
Overwrite specified types for accessCheck type specifier
1 parent fcf8d0f commit 3f2f39b

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

src/Type/EntityQuery/AccessCheckTypeSpecifyingExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ public function specifyTypes(
4343
$returnType = ParametersAcceptorSelector::selectSingle($methodReflection->getVariants())->getReturnType();
4444
$expr = $node->var;
4545
if (!$returnType instanceof EntityQueryType) {
46-
return $this->typeSpecifier->create($expr, $returnType, TypeSpecifierContext::createTruthy());
46+
return $this->typeSpecifier->create($expr, $returnType, $context, false, $scope);
4747
}
48-
return $this->typeSpecifier->create($expr, $returnType->withAccessCheck(), TypeSpecifierContext::createTruthy());
48+
return $this->typeSpecifier->create($expr, $returnType->withAccessCheck(), $context, true, $scope);
4949
}
5050
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace mglaman\PHPStanDrupal\Tests\Rules;
6+
7+
use mglaman\PHPStanDrupal\Tests\DrupalRuleTestCase;
8+
use PHPStan\Rules\Comparison\ImpossibleCheckTypeHelper;
9+
use PHPStan\Rules\Comparison\ImpossibleCheckTypeMethodCallRule;
10+
use PHPStan\Rules\Rule;
11+
12+
final class AccessCheckImpossibleTypeCallRuleTest extends DrupalRuleTestCase
13+
{
14+
15+
protected function getRule(): Rule
16+
{
17+
// @phpstan-ignore-next-line
18+
return new ImpossibleCheckTypeMethodCallRule(
19+
// @phpstan-ignore-next-line
20+
new ImpossibleCheckTypeHelper(
21+
$this->createReflectionProvider(),
22+
$this->getTypeSpecifier(),
23+
[],
24+
false,
25+
true,
26+
),
27+
true,
28+
false,
29+
);
30+
}
31+
32+
public function testRule(): void
33+
{
34+
$this->analyse(
35+
[__DIR__ . '/data/bug-496.php'],
36+
[]
37+
);
38+
}
39+
}

0 commit comments

Comments
 (0)