mirror of
https://github.com/elyby/oauth2-server.git
synced 2025-05-31 14:12:07 +05:30
PHPStan level 7
This commit is contained in:
39
tests/PHPStan/AbstractGrantExtension.php
Normal file
39
tests/PHPStan/AbstractGrantExtension.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace LeagueTests\PHPStan;
|
||||
|
||||
use League\OAuth2\Server\Grant\AbstractGrant;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use PHPStan\Reflection\MethodReflection;
|
||||
use PHPStan\Type\DynamicMethodReturnTypeExtension;
|
||||
use PHPStan\Type\NullType;
|
||||
use PHPStan\Type\StringType;
|
||||
use PHPStan\Type\Type;
|
||||
use PHPStan\Type\TypeCombinator;
|
||||
|
||||
final class AbstractGrantExtension implements DynamicMethodReturnTypeExtension
|
||||
{
|
||||
public function getClass(): string
|
||||
{
|
||||
return AbstractGrant::class;
|
||||
}
|
||||
|
||||
public function isMethodSupported(MethodReflection $methodReflection): bool
|
||||
{
|
||||
return in_array($methodReflection->getName(), [
|
||||
'getRequestParameter',
|
||||
'getQueryStringParameter',
|
||||
'getCookieParameter',
|
||||
], true);
|
||||
}
|
||||
|
||||
public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): Type
|
||||
{
|
||||
return TypeCombinator::union(...[
|
||||
new StringType(),
|
||||
isset($methodCall->args[2]) ? $scope->getType($methodCall->args[2]->value) : new NullType(),
|
||||
]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user