Skip to content

Commit 61f1d20

Browse files
VincentLangletondrejmirtes
authored andcommitted
Fix hasSession specifier
1 parent 45e2ae2 commit 61f1d20

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

Diff for: src/Type/Symfony/RequestTypeSpecifyingExtension.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,15 @@ public function specifyTypes(MethodReflection $methodReflection, MethodCall $nod
4646
{
4747
$classReflection = $this->broker->getClass(self::REQUEST_CLASS);
4848
$methodVariants = $classReflection->getNativeMethod(self::GET_METHOD_NAME)->getVariants();
49+
$returnType = ParametersAcceptorSelector::selectSingle($methodVariants)->getReturnType();
50+
51+
if (!TypeCombinator::containsNull($returnType)) {
52+
return new SpecifiedTypes();
53+
}
4954

5055
return $this->typeSpecifier->create(
5156
new MethodCall($node->var, self::GET_METHOD_NAME),
52-
TypeCombinator::removeNull(ParametersAcceptorSelector::selectSingle($methodVariants)->getReturnType()),
57+
TypeCombinator::removeNull($returnType),
5358
$context
5459
);
5560
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Type\Symfony;
4+
5+
use PHPStan\Rules\Comparison\ImpossibleCheckTypeMethodCallRule;
6+
use PHPStan\Rules\Rule;
7+
8+
/**
9+
* @extends \PHPStan\Testing\RuleTestCase<ImpossibleCheckTypeMethodCallRule>
10+
*/
11+
class ImpossibleCheckTypeMethodCallRuleTest extends \PHPStan\Testing\RuleTestCase
12+
{
13+
14+
protected function getRule(): Rule
15+
{
16+
return self::getContainer()->getByType(ImpossibleCheckTypeMethodCallRule::class);
17+
}
18+
19+
public function testExtension(): void
20+
{
21+
$this->analyse([__DIR__ . '/data/request_get_session.php'], []);
22+
}
23+
24+
public static function getAdditionalConfigFiles(): array
25+
{
26+
return [
27+
__DIR__ . '/../../../extension.neon',
28+
__DIR__ . '/../../../vendor/phpstan/phpstan-strict-rules/rules.neon',
29+
];
30+
}
31+
32+
}

0 commit comments

Comments
 (0)