PHPStan level 7

This commit is contained in:
Lukáš Unger 2018-02-18 21:17:32 +01:00
parent 456c6cfdd2
commit 143afc9561
No known key found for this signature in database
GPG Key ID: 48E84B8B7A223C26
8 changed files with 54 additions and 10 deletions

View File

@ -21,7 +21,7 @@ install:
script:
- vendor/bin/phpunit --coverage-clover=coverage.clover
- vendor/bin/phpstan analyse -l 6 -c phpstan.neon src tests
- vendor/bin/phpstan analyse -l 7 -c phpstan.neon src tests
after_script:
- wget https://scrutinizer-ci.com/ocular.phar

View File

@ -54,7 +54,7 @@ The library uses [PHPUnit](https://phpunit.de/) for unit tests and [PHPStan](htt
```
vendor/bin/phpunit
vendor/bin/phpstan analyse -l 6 -c phpstan.neon src tests
vendor/bin/phpstan analyse -l 7 -c phpstan.neon src tests
```
## Continous Integration

View File

@ -3,3 +3,8 @@ includes:
- vendor/phpstan/phpstan-phpunit/rules.neon
- vendor/phpstan/phpstan-phpunit/strictRules.neon
- vendor/phpstan/phpstan-strict-rules/rules.neon
services:
-
class: LeagueTests\PHPStan\AbstractGrantExtension
tags:
- phpstan.broker.dynamicMethodReturnTypeExtension

View File

@ -12,12 +12,12 @@ namespace League\OAuth2\Server\Entities;
interface AuthCodeEntityInterface extends TokenInterface
{
/**
* @return string
* @return string|null
*/
public function getRedirectUri();
/**
* @param string $uri
* @param string|null $uri
*/
public function setRedirectUri($uri);
}

View File

@ -17,7 +17,7 @@ trait AuthCodeTrait
protected $redirectUri;
/**
* @return string
* @return string|null
*/
public function getRedirectUri()
{
@ -25,7 +25,7 @@ trait AuthCodeTrait
}
/**
* @param string $uri
* @param string|null $uri
*/
public function setRedirectUri($uri)
{

View File

@ -386,7 +386,7 @@ abstract class AbstractGrant implements GrantTypeInterface
* @param \DateInterval $authCodeTTL
* @param ClientEntityInterface $client
* @param string $userIdentifier
* @param string $redirectUri
* @param string|null $redirectUri
* @param ScopeEntityInterface[] $scopes
*
* @throws OAuthServerException

View File

@ -60,7 +60,7 @@ class AuthorizationRequest
/**
* The state parameter on the authorization request
*
* @var string
* @var string|null
*/
protected $state;
@ -175,7 +175,7 @@ class AuthorizationRequest
}
/**
* @return string
* @return string|null
*/
public function getState()
{
@ -183,7 +183,7 @@ class AuthorizationRequest
}
/**
* @param string $state
* @param string|null $state
*/
public function setState($state)
{

View 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(),
]);
}
}