Skip to content

Commit

Permalink
Merge pull request #848 from lookyman/static-analysis
Browse files Browse the repository at this point in the history
Static analysis with PHPStan
  • Loading branch information
alexbilbie committed Feb 11, 2018
2 parents ef06c29 + eca385a commit 97089ad
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ cache:
- vendor

php:
- 5.6
- 7.0
- 7.1
- 7.2
Expand All @@ -17,6 +16,7 @@ install:

script:
- vendor/bin/phpunit
- vendor/bin/phpstan analyse -l 6 src

branches:
only:
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"homepage": "https://oauth2.thephpleague.com/",
"license": "MIT",
"require": {
"php": ">=5.6.0",
"php": ">=7.0.0",
"ext-openssl": "*",
"league/event": "^2.1",
"lcobucci/jwt": "^3.1",
Expand All @@ -14,7 +14,8 @@
},
"require-dev": {
"phpunit/phpunit": "^4.8.38 || ^5.7.21",
"zendframework/zend-diactoros": "^1.0"
"zendframework/zend-diactoros": "^1.0",
"phpstan/phpstan": "^0.9.2"
},
"repositories": [
{
Expand Down
7 changes: 5 additions & 2 deletions src/AuthorizationServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use League\OAuth2\Server\Repositories\ClientRepositoryInterface;
use League\OAuth2\Server\Repositories\ScopeRepositoryInterface;
use League\OAuth2\Server\RequestTypes\AuthorizationRequest;
use League\OAuth2\Server\ResponseTypes\AbstractResponseType;
use League\OAuth2\Server\ResponseTypes\BearerTokenResponse;
use League\OAuth2\Server\ResponseTypes\ResponseTypeInterface;
use Psr\Http\Message\ResponseInterface;
Expand Down Expand Up @@ -190,7 +191,7 @@ public function respondToAccessTokenRequest(ServerRequestInterface $request, Res
if ($tokenResponse instanceof ResponseTypeInterface) {
return $tokenResponse->generateHttpResponse($response);
}

}

throw OAuthServerException::unsupportedGrantType();
Expand All @@ -207,7 +208,9 @@ protected function getResponseType()
$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);

return $this->responseType;
Expand Down
3 changes: 2 additions & 1 deletion src/Entities/AccessTokenEntityInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace League\OAuth2\Server\Entities;

use Lcobucci\JWT\Token;
use League\OAuth2\Server\CryptKey;

interface AccessTokenEntityInterface extends TokenInterface
Expand All @@ -18,7 +19,7 @@ interface AccessTokenEntityInterface extends TokenInterface
*
* @param CryptKey $privateKey
*
* @return string
* @return Token
*/
public function convertToJWT(CryptKey $privateKey);
}
2 changes: 1 addition & 1 deletion src/Entities/RefreshTokenEntityInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function getIdentifier();
/**
* Set the token's identifier.
*
* @param $identifier
* @param mixed $identifier
*/
public function setIdentifier($identifier);

Expand Down
6 changes: 3 additions & 3 deletions src/Entities/TokenInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function getIdentifier();
/**
* Set the token's identifier.
*
* @param $identifier
* @param mixed $identifier
*/
public function setIdentifier($identifier);

Expand All @@ -42,14 +42,14 @@ public function setExpiryDateTime(\DateTime $dateTime);
/**
* 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);

/**
* Get the token user's identifier.
*
* @return string|int
* @return string|int|null
*/
public function getUserIdentifier();

Expand Down
3 changes: 2 additions & 1 deletion src/Entities/Traits/AccessTokenTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Lcobucci\JWT\Builder;
use Lcobucci\JWT\Signer\Key;
use Lcobucci\JWT\Signer\Rsa\Sha256;
use Lcobucci\JWT\Token;
use League\OAuth2\Server\CryptKey;
use League\OAuth2\Server\Entities\ClientEntityInterface;
use League\OAuth2\Server\Entities\ScopeEntityInterface;
Expand All @@ -23,7 +24,7 @@ trait AccessTokenTrait
*
* @param CryptKey $privateKey
*
* @return string
* @return Token
*/
public function convertToJWT(CryptKey $privateKey)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Entities/Traits/TokenEntityTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ trait TokenEntityTrait
protected $expiryDateTime;

/**
* @var string|int
* @var string|int|null
*/
protected $userIdentifier;

Expand Down Expand Up @@ -77,7 +77,7 @@ public function setExpiryDateTime(\DateTime $dateTime)
/**
* 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)
{
Expand All @@ -87,7 +87,7 @@ public function setUserIdentifier($identifier)
/**
* Get the token user's identifier.
*
* @return string|int
* @return string|int|null
*/
public function getUserIdentifier()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/OAuthServerException.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public static function invalidCredentials()
/**
* Server error.
*
* @param $hint
* @param string $hint
*
* @return static
*
Expand Down
2 changes: 1 addition & 1 deletion src/Grant/AbstractGrant.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ protected function getServerParameter($parameter, ServerRequestInterface $reques
*
* @param \DateInterval $accessTokenTTL
* @param ClientEntityInterface $client
* @param string $userIdentifier
* @param string|null $userIdentifier
* @param ScopeEntityInterface[] $scopes
*
* @throws OAuthServerException
Expand Down
6 changes: 3 additions & 3 deletions src/RequestTypes/AuthorizationRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class AuthorizationRequest
/**
* The redirect URI used in the request
*
* @var string
* @var string|null
*/
protected $redirectUri;

Expand Down Expand Up @@ -159,15 +159,15 @@ public function setAuthorizationApproved($authorizationApproved)
}

/**
* @return string
* @return string|null
*/
public function getRedirectUri()
{
return $this->redirectUri;
}

/**
* @param string $redirectUri
* @param string|null $redirectUri
*/
public function setRedirectUri($redirectUri)
{
Expand Down
4 changes: 3 additions & 1 deletion src/ResourceServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ protected function getAuthorizationValidator()
$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;
}
Expand Down

0 comments on commit 97089ad

Please sign in to comment.