Skip to content

Commit 388acd9

Browse files
committed
Add types to all the things!
1 parent 84e9a7c commit 388acd9

33 files changed

+183
-424
lines changed

src/Grant/AbstractGrant.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,21 @@ abstract class AbstractGrant
4040
/**
4141
* Returns the name of this grant, eg. 'grant_name', which is used as the
4242
* grant type when encoding URL query parameters.
43-
*
44-
* @return string
4543
*/
46-
abstract protected function getName();
44+
abstract protected function getName(): string;
4745

4846
/**
4947
* Returns a list of all required request parameters.
5048
*
5149
* @return list<string>
5250
*/
53-
abstract protected function getRequiredRequestParameters();
51+
abstract protected function getRequiredRequestParameters(): array;
5452

5553
/**
5654
* Returns this grant's name as its string representation. This allows for
5755
* string interpolation when building URL query parameters.
58-
*
59-
* @return string
6056
*/
61-
public function __toString()
57+
public function __toString(): string
6258
{
6359
return $this->getName();
6460
}
@@ -72,7 +68,7 @@ public function __toString()
7268
*
7369
* @return array<string, mixed>
7470
*/
75-
public function prepareRequestParameters(array $defaults, array $options)
71+
public function prepareRequestParameters(array $defaults, array $options): array
7672
{
7773
$defaults['grant_type'] = $this->getName();
7874

src/Grant/AuthorizationCode.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,15 @@
2424
*/
2525
class AuthorizationCode extends AbstractGrant
2626
{
27-
/**
28-
* @inheritdoc
29-
*/
30-
protected function getName()
27+
protected function getName(): string
3128
{
3229
return 'authorization_code';
3330
}
3431

3532
/**
3633
* @inheritdoc
3734
*/
38-
protected function getRequiredRequestParameters()
35+
protected function getRequiredRequestParameters(): array
3936
{
4037
return [
4138
'code',

src/Grant/ClientCredentials.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,15 @@
2424
*/
2525
class ClientCredentials extends AbstractGrant
2626
{
27-
/**
28-
* @inheritdoc
29-
*/
30-
protected function getName()
27+
protected function getName(): string
3128
{
3229
return 'client_credentials';
3330
}
3431

3532
/**
3633
* @inheritdoc
3734
*/
38-
protected function getRequiredRequestParameters()
35+
protected function getRequiredRequestParameters(): array
3936
{
4037
return [];
4138
}

src/Grant/GrantFactory.php

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,8 @@ class GrantFactory
4141

4242
/**
4343
* Defines a grant singleton in the registry.
44-
*
45-
* @return self
4644
*/
47-
public function setGrant(string $name, AbstractGrant $grant)
45+
public function setGrant(string $name, AbstractGrant $grant): static
4846
{
4947
$this->registry[$name] = $grant;
5048

@@ -55,10 +53,8 @@ public function setGrant(string $name, AbstractGrant $grant)
5553
* Returns a grant singleton by name.
5654
*
5755
* If the grant has not be registered, a default grant will be loaded.
58-
*
59-
* @return AbstractGrant
6056
*/
61-
public function getGrant(string $name)
57+
public function getGrant(string $name): AbstractGrant
6258
{
6359
if (!isset($this->registry[$name])) {
6460
$this->registerDefaultGrant($name);
@@ -70,10 +66,8 @@ public function getGrant(string $name)
7066

7167
/**
7268
* Registers a default grant singleton by name.
73-
*
74-
* @return self
7569
*/
76-
protected function registerDefaultGrant(string $name)
70+
protected function registerDefaultGrant(string $name): static
7771
{
7872
// PascalCase the grant. E.g: 'authorization_code' becomes 'AuthorizationCode'
7973
$class = str_replace(' ', '', ucwords(str_replace(['-', '_'], ' ', $name)));
@@ -87,11 +81,9 @@ protected function registerDefaultGrant(string $name)
8781
/**
8882
* Determines if a variable is a valid grant.
8983
*
90-
* @return bool
91-
*
9284
* @phpstan-assert-if-true class-string<AbstractGrant> | AbstractGrant $class
9385
*/
94-
public function isGrant(mixed $class)
86+
public function isGrant(mixed $class): bool
9587
{
9688
if (!is_string($class) && !is_object($class)) {
9789
return false;
@@ -103,22 +95,18 @@ public function isGrant(mixed $class)
10395
/**
10496
* Checks if a variable is a valid grant.
10597
*
106-
* @return void
107-
*
10898
* @throws InvalidGrantException
10999
*
110100
* @phpstan-assert class-string<AbstractGrant> | AbstractGrant $class
111101
*/
112-
public function checkGrant(mixed $class)
102+
public function checkGrant(mixed $class): void
113103
{
114104
if (!$this->isGrant($class)) {
115-
if (is_object($class)) {
116-
$type = $class::class;
117-
} elseif (is_scalar($class)) {
118-
$type = $class;
119-
} else {
120-
$type = gettype($class);
121-
}
105+
$type = match (true) {
106+
is_object($class) => $class::class,
107+
is_scalar($class) => $class,
108+
default => gettype($class),
109+
};
122110

123111
throw new InvalidGrantException(sprintf('Grant "%s" must extend AbstractGrant', $type));
124112
}

src/Grant/Password.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,15 @@
2424
*/
2525
class Password extends AbstractGrant
2626
{
27-
/**
28-
* @inheritdoc
29-
*/
30-
protected function getName()
27+
protected function getName(): string
3128
{
3229
return 'password';
3330
}
3431

3532
/**
3633
* @inheritdoc
3734
*/
38-
protected function getRequiredRequestParameters()
35+
protected function getRequiredRequestParameters(): array
3936
{
4037
return [
4138
'username',

src/Grant/RefreshToken.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,15 @@
2424
*/
2525
class RefreshToken extends AbstractGrant
2626
{
27-
/**
28-
* @inheritdoc
29-
*/
30-
protected function getName()
27+
protected function getName(): string
3128
{
3229
return 'refresh_token';
3330
}
3431

3532
/**
3633
* @inheritdoc
3734
*/
38-
protected function getRequiredRequestParameters()
35+
protected function getRequiredRequestParameters(): array
3936
{
4037
return [
4138
'refresh_token',

src/OptionProvider/OptionProviderInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ interface OptionProviderInterface
2929
*
3030
* @return array<string, mixed>
3131
*/
32-
public function getAccessTokenOptions(string $method, array $params);
32+
public function getAccessTokenOptions(string $method, array $params): array;
3333
}

src/OptionProvider/PostAuthOptionProvider.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,8 @@ public function getAccessTokenOptions(string $method, array $params): array
4747
* Returns the request body for requesting an access token.
4848
*
4949
* @param array<string, mixed> $params
50-
*
51-
* @return string
5250
*/
53-
protected function getAccessTokenBody(array $params)
51+
protected function getAccessTokenBody(array $params): string
5452
{
5553
return $this->buildQueryString($params);
5654
}

0 commit comments

Comments
 (0)