Skip to content

Commit f2eea7a

Browse files
Merge pull request #5 from loevgaard/cs
Add coding standard, types, and Psalm
2 parents 6c20d47 + 5c0451d commit f2eea7a

23 files changed

+188
-145
lines changed

.github/workflows/build.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ jobs:
5757
- "8.1"
5858

5959
dependencies:
60+
- "lowest"
6061
- "highest"
6162

6263
steps:
@@ -94,6 +95,7 @@ jobs:
9495
- "8.1"
9596

9697
dependencies:
98+
- "lowest"
9799
- "highest"
98100

99101
steps:
@@ -113,4 +115,4 @@ jobs:
113115
dependency-versions: "${{ matrix.dependencies }}"
114116

115117
- name: "Static analysis"
116-
run: "composer phpstan"
118+
run: "composer analyse"

composer.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@
2323
},
2424
"require-dev": {
2525
"ergebnis/composer-normalize": "^2.28",
26-
"phpstan/phpstan": "^0.12.64",
2726
"phpunit/phpunit": "^9.4.3",
27+
"sylius-labs/coding-standard": "^4.2",
2828
"symfony/cache": "^6.0",
29-
"symfony/http-client": "^6.0"
29+
"symfony/http-client": "^6.0",
30+
"vimeo/psalm": "^4.26"
3031
},
3132
"provide": {
3233
"symfony/http-client-implementation": "^2.3.1"
@@ -38,10 +39,13 @@
3839
},
3940
"config": {
4041
"allow-plugins": {
42+
"dealerdirect/phpcodesniffer-composer-installer": false,
4143
"ergebnis/composer-normalize": true
4244
}
4345
},
4446
"scripts": {
45-
"phpstan": "vendor/bin/phpstan analyse --level max src tests"
47+
"analyse": "psalm",
48+
"check-style": "ecs check",
49+
"fix-style": "ecs check --fix"
4650
}
4751
}

ecs.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Symplify\EasyCodingStandard\Config\ECSConfig;
6+
7+
return static function (ECSConfig $config): void {
8+
$config->import('vendor/sylius-labs/coding-standard/ecs.php');
9+
$config->paths([
10+
'src',
11+
]);
12+
};

psalm.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0"?>
2+
<psalm
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
errorLevel="1"
5+
xmlns="https://getpsalm.org/schema/config"
6+
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
7+
phpVersion="8.1"
8+
>
9+
<projectFiles>
10+
<directory name="src"/>
11+
<ignoreFiles>
12+
<directory name="vendor"/>
13+
</ignoreFiles>
14+
</projectFiles>
15+
</psalm>

src/Exception/OAuthException.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace BenjaminFavre\OAuthHttpClient\Exception;
46

57
use RuntimeException;
68

79
/**
810
* Represents errors during OAuth protocol.
9-
*
10-
* @author Benjamin Favre <[email protected]>
1111
*/
1212
class OAuthException extends RuntimeException implements OAuthExceptionInterface
1313
{
14-
}
14+
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace BenjaminFavre\OAuthHttpClient\Exception;
46

57
use Symfony\Contracts\HttpClient\Exception\ExceptionInterface;
68

79
/**
810
* Represents errors during OAuth protocol.
9-
*
10-
* @author Benjamin Favre <[email protected]>
1111
*/
1212
interface OAuthExceptionInterface extends ExceptionInterface
1313
{
14-
}
14+
}
Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace BenjaminFavre\OAuthHttpClient\GrantType;
46

57
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
68
use Symfony\Contracts\HttpClient\HttpClientInterface;
79

810
/**
911
* Implementation of the OAuth authorization grant type.
10-
*
11-
* @author Benjamin Favre <[email protected]>
1212
*/
1313
class AuthorizationCodeGrantType implements RefreshableGrantTypeInterface
1414
{
1515
use TokensExtractor;
1616

17-
/** @var HttpClientInterface */
18-
private $client;
19-
/** @var string */
20-
private $tokenUrl;
21-
/** @var string */
22-
private $code;
23-
/** @var string */
24-
private $clientId;
25-
/** @var string */
26-
private $clientSecret;
17+
private HttpClientInterface $client;
18+
19+
private string $tokenUrl;
20+
21+
private string $code;
22+
23+
private string $clientId;
24+
25+
private string $clientSecret;
2726

2827
/**
2928
* @param HttpClientInterface $client A HTTP client to be used to communicate with the OAuth server.
@@ -37,7 +36,7 @@ public function __construct(
3736
string $tokenUrl,
3837
string $code,
3938
string $clientId,
40-
string $clientSecret
39+
string $clientSecret,
4140
) {
4241
$this->client = $client;
4342
$this->tokenUrl = $tokenUrl;
@@ -47,9 +46,8 @@ public function __construct(
4746
}
4847

4948
/**
50-
* {@inheritDoc}
49+
* @inheritDoc
5150
*
52-
* @return Tokens
5351
* @throws TransportExceptionInterface
5452
*/
5553
public function getTokens(): Tokens
@@ -60,7 +58,7 @@ public function getTokens(): Tokens
6058
'client_id' => $this->clientId,
6159
'client_secret' => $this->clientSecret,
6260
'code' => $this->code,
63-
])
61+
]),
6462
]);
6563

6664
return $this->extractTokens($response);
@@ -70,4 +68,4 @@ public function getRefreshTokenGrant(string $refreshToken): GrantTypeInterface
7068
{
7169
return new RefreshTokenGrantType($this->client, $this->tokenUrl, $refreshToken, $this->clientId, $this->clientSecret);
7270
}
73-
}
71+
}
Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace BenjaminFavre\OAuthHttpClient\GrantType;
46

57
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
68
use Symfony\Contracts\HttpClient\HttpClientInterface;
79

810
/**
911
* Implementation of the OAuth client credentials grant type.
10-
*
11-
* @author Benjamin Favre <[email protected]>
1212
*/
1313
class ClientCredentialsGrantType implements GrantTypeInterface
1414
{
1515
use TokensExtractor;
1616

17-
/** @var HttpClientInterface */
18-
private $client;
19-
/** @var string */
20-
private $tokenUrl;
21-
/** @var string */
22-
private $clientId;
23-
/** @var string */
24-
private $clientSecret;
17+
private HttpClientInterface $client;
18+
19+
private string $tokenUrl;
20+
21+
private string $clientId;
22+
23+
private string $clientSecret;
2524

2625
/**
2726
* @param HttpClientInterface $client A HTTP client to be used to communicate with the OAuth server.
@@ -33,7 +32,7 @@ public function __construct(
3332
HttpClientInterface $client,
3433
string $tokenUrl,
3534
string $clientId,
36-
string $clientSecret
35+
string $clientSecret,
3736
) {
3837
$this->client = $client;
3938
$this->tokenUrl = $tokenUrl;
@@ -42,9 +41,8 @@ public function __construct(
4241
}
4342

4443
/**
45-
* {@inheritDoc}
44+
* @inheritDoc
4645
*
47-
* @return Tokens
4846
* @throws TransportExceptionInterface
4947
*/
5048
public function getTokens(): Tokens
@@ -56,4 +54,4 @@ public function getTokens(): Tokens
5654

5755
return $this->extractTokens($response);
5856
}
59-
}
57+
}

src/GrantType/GrantTypeInterface.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace BenjaminFavre\OAuthHttpClient\GrantType;
46

57
use BenjaminFavre\OAuthHttpClient\Exception\OAuthException;
68

79
/**
810
* Implementation of one OAuth grant type.
9-
*
10-
* @author Benjamin Favre <[email protected]>
1111
*/
1212
interface GrantTypeInterface
1313
{
1414
/**
1515
* Retrieves tokens from an OAuth server.
1616
*
1717
* @return Tokens The tokens retrieved from the OAuth server.
18+
*
1819
* @throws OAuthException When the tokens could not be retrieved.
1920
*/
2021
public function getTokens(): Tokens;
21-
}
22+
}

src/GrantType/PasswordGrantType.php

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,46 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace BenjaminFavre\OAuthHttpClient\GrantType;
46

57
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
68
use Symfony\Contracts\HttpClient\HttpClientInterface;
79

810
/**
911
* Implementation of the OAuth password grant type.
10-
*
11-
* @author Benjamin Favre <[email protected]>
1212
*/
1313
class PasswordGrantType implements GrantTypeInterface
1414
{
1515
use TokensExtractor;
1616

17-
/** @var HttpClientInterface */
18-
private $client;
19-
/** @var string */
20-
private $tokenUrl;
21-
/** @var string */
22-
private $username;
23-
/** @var string */
24-
private $password;
25-
/** @var ?string */
26-
private $clientId;
27-
/** @var ?string */
28-
private $clientSecret;
17+
private HttpClientInterface $client;
18+
19+
private string $tokenUrl;
20+
21+
private string $username;
22+
23+
private string $password;
24+
25+
private ?string $clientId;
26+
27+
private ?string $clientSecret;
2928

3029
/**
3130
* @param HttpClientInterface $client A HTTP client to be used to communicate with the OAuth server.
3231
* @param string $tokenUrl The full URL of the token endpoint of the OAuth server.
3332
* @param string $username The OAuth user username.
3433
* @param string $password The OAuth user password.
35-
* @param ?string $clientId The OAuth client ID.
36-
* @param ?string $clientSecret The OAuth client secret.
34+
* @param string|null $clientId The OAuth client ID.
35+
* @param string|null $clientSecret The OAuth client secret.
3736
*/
3837
public function __construct(
3938
HttpClientInterface $client,
4039
string $tokenUrl,
4140
string $username,
4241
string $password,
43-
?string $clientId = null,
44-
?string $clientSecret = null
42+
string $clientId = null,
43+
string $clientSecret = null,
4544
) {
4645
$this->client = $client;
4746
$this->tokenUrl = $tokenUrl;
@@ -52,9 +51,8 @@ public function __construct(
5251
}
5352

5453
/**
55-
* {@inheritDoc}
54+
* @inheritDoc
5655
*
57-
* @return Tokens
5856
* @throws TransportExceptionInterface
5957
*/
6058
public function getTokens(): Tokens
@@ -64,7 +62,7 @@ public function getTokens(): Tokens
6462
'username' => $this->username,
6563
'password' => $this->password,
6664
];
67-
65+
6866
if ($this->clientId !== null && $this->clientSecret !== null) {
6967
$parameters = array_merge($parameters, [
7068
'client_id' => $this->clientId,
@@ -78,4 +76,4 @@ public function getTokens(): Tokens
7876

7977
return $this->extractTokens($response);
8078
}
81-
}
79+
}

0 commit comments

Comments
 (0)