Skip to content

Commit

Permalink
fixed errors from phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
Surfoo committed Aug 13, 2023
1 parent f78c1f7 commit d770bae
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 62 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
tools: "composer:v2"
- uses: "ramsey/composer-install@v2"
- name: "Check coding standards"
run: "./vendor/bin/phpcs src --standard=psr2 -sp --colors"
run: "./vendor/bin/phpcs src --standard=psr2 --exclude=Generic.Files.LineLength -sp --colors"

unit-tests:
name: "Unit Tests"
Expand Down
4 changes: 4 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
parameters:
level: 5
paths:
- src
17 changes: 4 additions & 13 deletions src/Provider/Exception/GeocachingIdentityProviderException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@

use Psr\Http\Message\ResponseInterface;

class GeocachingIdentityProviderException extends IdentityProviderException
final class GeocachingIdentityProviderException extends IdentityProviderException
{
/**
* Creates client exception from response.
*
* @param array $data Parsed response data
* @return IdentityProviderException
*/
public static function clientException(ResponseInterface $response, $data)
public static function clientException(ResponseInterface $response, array $data): IdentityProviderException
{
return static::fromResponse(
$response,
Expand All @@ -22,11 +19,8 @@ public static function clientException(ResponseInterface $response, $data)

/**
* Creates oauth exception from response.
*
* @param array $data Parsed response data
* @return IdentityProviderException
*/
public static function oauthException(ResponseInterface $response, $data)
public static function oauthException(ResponseInterface $response, array $data): IdentityProviderException
{
return static::fromResponse(
$response,
Expand All @@ -36,11 +30,8 @@ public static function oauthException(ResponseInterface $response, $data)

/**
* Creates identity exception from response.
*
* @param string $message
* @return IdentityProviderException
*/
protected static function fromResponse(ResponseInterface $response, $message = null)
protected static function fromResponse(ResponseInterface $response, ?string $message = null): IdentityProviderException
{
return new static($message, $response->getStatusCode(), (string) $response->getBody());
}
Expand Down
40 changes: 11 additions & 29 deletions src/Provider/Geocaching.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,38 +26,23 @@ class Geocaching extends AbstractProvider

protected string $environment = 'production';

/**
* Main domain
*
* @var string
*/
public $domain;
public string $domain;

/**
* Api domain
*
* @var string
*/
public $apiDomain;
public string $apiDomain;

/**
* OAuth domain
*
* @var string
*/
public $oAuthDomain;
public string $oAuthDomain;

public $clientId;

public $clientSecret;

public $redirectUri;

public $response_type = 'code';
public string $response_type = 'code';

public $scope = '*';
public string $scope = '*';

public $pkceMethod = 'S256';
public string $pkceMethod = 'S256';

private string $responseResourceOwnerId = 'referenceCode';

Expand Down Expand Up @@ -106,7 +91,7 @@ public function __construct(array $options = [], array $collaborators = [])
*
* @return array
*/
protected function getConfigurableOptions()
protected function getConfigurableOptions(): array
{
return array_merge($this->getRequiredOptions(), [
'clientId',
Expand Down Expand Up @@ -181,18 +166,15 @@ public function getResourceOwnerDetailsUrl(AccessToken $token): string
return $this->apiDomain . '/v1/users/me?' . http_build_query($query);
}

/**
* @return string
*/
public function getDefaultScopes()
public function getDefaultScopes(): array
{
return $this->scope;
return [$this->scope];
}

/**
* @inheritdoc
*/
protected function getPkceMethod()
protected function getPkceMethod(): string
{
return $this->pkceMethod;
}
Expand All @@ -201,7 +183,7 @@ protected function getPkceMethod()
* Check a provider response for errors.
*
* @link https://api.groundspeak.com/documentation#responses
* @throws IdentityProviderException
* @throws GeocachingIdentityProviderException
* @param ResponseInterface $response
* @param array|string $data Parsed response data
* @return void
Expand Down
21 changes: 3 additions & 18 deletions src/Provider/GeocachingResourceOwner.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,10 @@

class GeocachingResourceOwner implements ResourceOwnerInterface
{

/**
* @var array
*/
protected $response;

/**
* Domain
*/
protected string $domain;

/**
* @param string $resourceOwnerId
*/
public function __construct(array $response, protected $resourceOwnerId)
public function __construct(protected array $response, protected string $resourceOwnerId)
{
$this->response = $response;
}

/**
Expand Down Expand Up @@ -160,7 +147,7 @@ public function getHomeCoordinates()
*
* @return bool
*/
public function getOptedInFriendSharing()
public function getOptedInFriendSharing(): bool
{
return (bool) $this->response['optedInFriendSharing'];
}
Expand All @@ -177,10 +164,8 @@ public function getGeocacheLimits()

/**
* Return all of the owner details available as an array.
*
* @return array
*/
public function toArray()
public function toArray(): array
{
return $this->response;
}
Expand Down
2 changes: 1 addition & 1 deletion test/src/Provider/GeocachingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function testConfigurableOptions()
$this->assertEquals('http://localhost:8000/oauth/authorize.aspx', $provider->getBaseAuthorizationUrl());
$this->assertEquals('http://localhost:8000/token', $provider->getBaseAccessTokenUrl([]));
$this->assertEquals('http://localhost:8000/v1/users/me?fields=referenceCode%2CfindCount%2ChideCount%2CfavoritePoints%2Cusername%2CmembershipLevelId%2CjoinedDateUtc%2CavatarUrl%2CbannerUrl%2Curl%2ChomeCoordinates%2CgeocacheLimits%2CoptedInFriendSharing', $provider->getResourceOwnerDetailsUrl(new AccessToken(['access_token' => '1234'])));
$this->assertEquals('*', $provider->getDefaultScopes());
$this->assertEquals(['*'], $provider->getDefaultScopes());

$reflection = new ReflectionClass(get_class($provider));

Expand Down

0 comments on commit d770bae

Please sign in to comment.