Skip to content

Commit e829db0

Browse files
committed
Add coding standard
1 parent 6c20d47 commit e829db0

21 files changed

+150
-130
lines changed

composer.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"ergebnis/composer-normalize": "^2.28",
2626
"phpstan/phpstan": "^0.12.64",
2727
"phpunit/phpunit": "^9.4.3",
28+
"sylius-labs/coding-standard": "^4.2",
2829
"symfony/cache": "^6.0",
2930
"symfony/http-client": "^6.0"
3031
},
@@ -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": {
47+
"check-style": "ecs check",
48+
"fix-style": "ecs check --fix",
4549
"phpstan": "vendor/bin/phpstan analyse --level max src tests"
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+
};

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: 19 additions & 21 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,
4342
?string $clientId = null,
44-
?string $clientSecret = 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)