Skip to content

Commit

Permalink
Fix hasSession specifier
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet authored and ondrejmirtes committed Jul 1, 2021
1 parent 45e2ae2 commit 61f1d20
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Type/Symfony/RequestTypeSpecifyingExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,15 @@ public function specifyTypes(MethodReflection $methodReflection, MethodCall $nod
{
$classReflection = $this->broker->getClass(self::REQUEST_CLASS);
$methodVariants = $classReflection->getNativeMethod(self::GET_METHOD_NAME)->getVariants();
$returnType = ParametersAcceptorSelector::selectSingle($methodVariants)->getReturnType();

if (!TypeCombinator::containsNull($returnType)) {
return new SpecifiedTypes();
}

return $this->typeSpecifier->create(
new MethodCall($node->var, self::GET_METHOD_NAME),
TypeCombinator::removeNull(ParametersAcceptorSelector::selectSingle($methodVariants)->getReturnType()),
TypeCombinator::removeNull($returnType),
$context
);
}
Expand Down
32 changes: 32 additions & 0 deletions tests/Type/Symfony/ImpossibleCheckTypeMethodCallRuleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php declare(strict_types = 1);

namespace PHPStan\Type\Symfony;

use PHPStan\Rules\Comparison\ImpossibleCheckTypeMethodCallRule;
use PHPStan\Rules\Rule;

/**
* @extends \PHPStan\Testing\RuleTestCase<ImpossibleCheckTypeMethodCallRule>
*/
class ImpossibleCheckTypeMethodCallRuleTest extends \PHPStan\Testing\RuleTestCase
{

protected function getRule(): Rule
{
return self::getContainer()->getByType(ImpossibleCheckTypeMethodCallRule::class);
}

public function testExtension(): void
{
$this->analyse([__DIR__ . '/data/request_get_session.php'], []);
}

public static function getAdditionalConfigFiles(): array
{
return [
__DIR__ . '/../../../extension.neon',
__DIR__ . '/../../../vendor/phpstan/phpstan-strict-rules/rules.neon',
];
}

}

0 comments on commit 61f1d20

Please sign in to comment.