Static analysis with PHPStan

This commit is contained in:
Lukáš Unger 2018-02-11 21:51:47 +01:00
parent 4c548dbd78
commit eca385ab08
No known key found for this signature in database
GPG Key ID: 48E84B8B7A223C26
12 changed files with 28 additions and 20 deletions

View File

@ -7,7 +7,6 @@ cache:
- vendor - vendor
php: php:
- 5.6
- 7.0 - 7.0
- 7.1 - 7.1
- 7.2 - 7.2
@ -17,6 +16,7 @@ install:
script: script:
- vendor/bin/phpunit - vendor/bin/phpunit
- vendor/bin/phpstan analyse -l 6 src
branches: branches:
only: only:

View File

@ -4,7 +4,7 @@
"homepage": "https://oauth2.thephpleague.com/", "homepage": "https://oauth2.thephpleague.com/",
"license": "MIT", "license": "MIT",
"require": { "require": {
"php": ">=5.6.0", "php": ">=7.0.0",
"ext-openssl": "*", "ext-openssl": "*",
"league/event": "^2.1", "league/event": "^2.1",
"lcobucci/jwt": "^3.1", "lcobucci/jwt": "^3.1",
@ -14,7 +14,8 @@
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "^4.8.38 || ^5.7.21", "phpunit/phpunit": "^4.8.38 || ^5.7.21",
"zendframework/zend-diactoros": "^1.0" "zendframework/zend-diactoros": "^1.0",
"phpstan/phpstan": "^0.9.2"
}, },
"repositories": [ "repositories": [
{ {

View File

@ -17,6 +17,7 @@ use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface;
use League\OAuth2\Server\Repositories\ClientRepositoryInterface; use League\OAuth2\Server\Repositories\ClientRepositoryInterface;
use League\OAuth2\Server\Repositories\ScopeRepositoryInterface; use League\OAuth2\Server\Repositories\ScopeRepositoryInterface;
use League\OAuth2\Server\RequestTypes\AuthorizationRequest; use League\OAuth2\Server\RequestTypes\AuthorizationRequest;
use League\OAuth2\Server\ResponseTypes\AbstractResponseType;
use League\OAuth2\Server\ResponseTypes\BearerTokenResponse; use League\OAuth2\Server\ResponseTypes\BearerTokenResponse;
use League\OAuth2\Server\ResponseTypes\ResponseTypeInterface; use League\OAuth2\Server\ResponseTypes\ResponseTypeInterface;
use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ResponseInterface;
@ -190,7 +191,7 @@ class AuthorizationServer implements EmitterAwareInterface
if ($tokenResponse instanceof ResponseTypeInterface) { if ($tokenResponse instanceof ResponseTypeInterface) {
return $tokenResponse->generateHttpResponse($response); return $tokenResponse->generateHttpResponse($response);
} }
} }
throw OAuthServerException::unsupportedGrantType(); throw OAuthServerException::unsupportedGrantType();
@ -207,7 +208,9 @@ class AuthorizationServer implements EmitterAwareInterface
$this->responseType = new BearerTokenResponse(); $this->responseType = new BearerTokenResponse();
} }
$this->responseType->setPrivateKey($this->privateKey); if ($this->responseType instanceof AbstractResponseType === true) {
$this->responseType->setPrivateKey($this->privateKey);
}
$this->responseType->setEncryptionKey($this->encryptionKey); $this->responseType->setEncryptionKey($this->encryptionKey);
return $this->responseType; return $this->responseType;

View File

@ -9,6 +9,7 @@
namespace League\OAuth2\Server\Entities; namespace League\OAuth2\Server\Entities;
use Lcobucci\JWT\Token;
use League\OAuth2\Server\CryptKey; use League\OAuth2\Server\CryptKey;
interface AccessTokenEntityInterface extends TokenInterface interface AccessTokenEntityInterface extends TokenInterface
@ -18,7 +19,7 @@ interface AccessTokenEntityInterface extends TokenInterface
* *
* @param CryptKey $privateKey * @param CryptKey $privateKey
* *
* @return string * @return Token
*/ */
public function convertToJWT(CryptKey $privateKey); public function convertToJWT(CryptKey $privateKey);
} }

View File

@ -21,7 +21,7 @@ interface RefreshTokenEntityInterface
/** /**
* Set the token's identifier. * Set the token's identifier.
* *
* @param $identifier * @param mixed $identifier
*/ */
public function setIdentifier($identifier); public function setIdentifier($identifier);

View File

@ -21,7 +21,7 @@ interface TokenInterface
/** /**
* Set the token's identifier. * Set the token's identifier.
* *
* @param $identifier * @param mixed $identifier
*/ */
public function setIdentifier($identifier); public function setIdentifier($identifier);
@ -42,14 +42,14 @@ interface TokenInterface
/** /**
* Set the identifier of the user associated with the token. * Set the identifier of the user associated with the token.
* *
* @param string|int $identifier The identifier of the user * @param string|int|null $identifier The identifier of the user
*/ */
public function setUserIdentifier($identifier); public function setUserIdentifier($identifier);
/** /**
* Get the token user's identifier. * Get the token user's identifier.
* *
* @return string|int * @return string|int|null
*/ */
public function getUserIdentifier(); public function getUserIdentifier();

View File

@ -12,6 +12,7 @@ namespace League\OAuth2\Server\Entities\Traits;
use Lcobucci\JWT\Builder; use Lcobucci\JWT\Builder;
use Lcobucci\JWT\Signer\Key; use Lcobucci\JWT\Signer\Key;
use Lcobucci\JWT\Signer\Rsa\Sha256; use Lcobucci\JWT\Signer\Rsa\Sha256;
use Lcobucci\JWT\Token;
use League\OAuth2\Server\CryptKey; use League\OAuth2\Server\CryptKey;
use League\OAuth2\Server\Entities\ClientEntityInterface; use League\OAuth2\Server\Entities\ClientEntityInterface;
use League\OAuth2\Server\Entities\ScopeEntityInterface; use League\OAuth2\Server\Entities\ScopeEntityInterface;
@ -23,7 +24,7 @@ trait AccessTokenTrait
* *
* @param CryptKey $privateKey * @param CryptKey $privateKey
* *
* @return string * @return Token
*/ */
public function convertToJWT(CryptKey $privateKey) public function convertToJWT(CryptKey $privateKey)
{ {

View File

@ -25,7 +25,7 @@ trait TokenEntityTrait
protected $expiryDateTime; protected $expiryDateTime;
/** /**
* @var string|int * @var string|int|null
*/ */
protected $userIdentifier; protected $userIdentifier;
@ -77,7 +77,7 @@ trait TokenEntityTrait
/** /**
* Set the identifier of the user associated with the token. * Set the identifier of the user associated with the token.
* *
* @param string|int $identifier The identifier of the user * @param string|int|null $identifier The identifier of the user
*/ */
public function setUserIdentifier($identifier) public function setUserIdentifier($identifier)
{ {
@ -87,7 +87,7 @@ trait TokenEntityTrait
/** /**
* Get the token user's identifier. * Get the token user's identifier.
* *
* @return string|int * @return string|int|null
*/ */
public function getUserIdentifier() public function getUserIdentifier()
{ {

View File

@ -131,7 +131,7 @@ class OAuthServerException extends \Exception
/** /**
* Server error. * Server error.
* *
* @param $hint * @param string $hint
* *
* @return static * @return static
* *

View File

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

View File

@ -53,7 +53,7 @@ class AuthorizationRequest
/** /**
* The redirect URI used in the request * The redirect URI used in the request
* *
* @var string * @var string|null
*/ */
protected $redirectUri; protected $redirectUri;
@ -159,7 +159,7 @@ class AuthorizationRequest
} }
/** /**
* @return string * @return string|null
*/ */
public function getRedirectUri() public function getRedirectUri()
{ {
@ -167,7 +167,7 @@ class AuthorizationRequest
} }
/** /**
* @param string $redirectUri * @param string|null $redirectUri
*/ */
public function setRedirectUri($redirectUri) public function setRedirectUri($redirectUri)
{ {

View File

@ -63,7 +63,9 @@ class ResourceServer
$this->authorizationValidator = new BearerTokenValidator($this->accessTokenRepository); $this->authorizationValidator = new BearerTokenValidator($this->accessTokenRepository);
} }
$this->authorizationValidator->setPublicKey($this->publicKey); if ($this->authorizationValidator instanceof BearerTokenValidator === true) {
$this->authorizationValidator->setPublicKey($this->publicKey);
}
return $this->authorizationValidator; return $this->authorizationValidator;
} }