Skip to content

Commit e6f6191

Browse files
authored
Merge pull request #512 from mglaman/508
2 parents fcf8d0f + e095bb8 commit e6f6191

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

src/Type/EntityQuery/AccessCheckTypeSpecifyingExtension.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,13 @@ 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 new SpecifiedTypes([]);
4747
}
48-
return $this->typeSpecifier->create($expr, $returnType->withAccessCheck(), TypeSpecifierContext::createTruthy());
48+
return $this->typeSpecifier->create(
49+
$expr,
50+
$returnType->withAccessCheck(),
51+
TypeSpecifierContext::createTruthy(),
52+
true
53+
);
4954
}
5055
}
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)