Skip to content

Commit e39bd50

Browse files
felixuref3l1x
authored andcommitted
Fix: apply code style and add native type hints
1 parent 549079d commit e39bd50

File tree

4 files changed

+28
-31
lines changed

4 files changed

+28
-31
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ qa: phpstan cs
88
.PHONY: cs
99
cs:
1010
ifdef GITHUB_ACTION
11-
vendor/bin/codesniffer -q --report=checkstyle --extensions="php,phpt" src tests | cs2pr
11+
vendor/bin/phpcs -q --report=checkstyle --standard=./ruleset.xml --extensions="php,phpt" src tests | cs2pr
1212
else
13-
vendor/bin/codesniffer --extensions="php,phpt" src tests
13+
vendor/bin/phpcs --standard=./ruleset.xml --extensions="php,phpt" src tests
1414
endif
1515

1616
.PHONY: csf
1717
csf:
18-
vendor/bin/codefixer --extensions="php,phpt" src tests
18+
vendor/bin/phpcbf --standard=./ruleset.xml --extensions="php,phpt" src tests
1919

2020
.PHONY: phpstan
2121
phpstan:

src/DI/GitlabAuthExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function getConfigSchema(): Schema
2020
return Expect::structure([
2121
'clientId' => Expect::string()->required(),
2222
'clientSecret' => Expect::string()->required(),
23-
'domain' => Expect::string()->required(),
23+
'domain' => Expect::string()->required(),
2424
'options' => Expect::array(),
2525
]);
2626
}
@@ -42,7 +42,7 @@ public function loadConfiguration(): void
4242

4343
$builder->addDefinition($this->prefix('provider'))
4444
->setFactory(GitlabProvider::class, [$providerOptions]);
45-
45+
4646
$builder->addDefinition($this->prefix('authCodeFlow'))
4747
->setFactory(GitlabAuthCodeFlow::class, ['@' . $this->prefix('provider')]);
4848
}

src/Flow/AuthCodeFlow.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@ abstract class AuthCodeFlow
1616

1717
public const SESSION_NAMESPACE = 'contributte.oauth2client';
1818

19-
/** @var AbstractProvider */
20-
protected $provider;
19+
protected AbstractProvider $provider;
2120

22-
/** @var Session */
23-
protected $session;
21+
protected Session $session;
2422

2523
public function __construct(AbstractProvider $provider, Session $session)
2624
{
@@ -32,7 +30,7 @@ public function __construct(AbstractProvider $provider, Session $session)
3230
* @param string|mixed[]|null $redirectUriOrOptions
3331
* @param mixed[] $options
3432
*/
35-
public function getAuthorizationUrl($redirectUriOrOptions = null, array $options = []): string
33+
public function getAuthorizationUrl(string|array|null $redirectUriOrOptions = null, array $options = []): string
3634
{
3735
if (is_array($redirectUriOrOptions)) {
3836
$options = array_merge($options, $redirectUriOrOptions);
@@ -73,13 +71,14 @@ public function getAccessToken(array $parameters, ?string $redirectUri = null):
7371
if (isset($session['state']) && $parameters['state'] !== $session['state']) {
7472
unset($session['state']);
7573
unset($session['redirect_uri']);
74+
7675
throw new PossibleCsrfAttackException();
7776
}
7877

7978
$options = array_filter([
8079
'code' => $parameters['code'],
8180
'redirect_uri' => $redirectUri ?? $session['redirect_uri'] ?? null,
82-
]);
81+
], fn ($v) => $v !== null);
8382

8483
// Try to get an access token (using the authorization code grant)
8584
return $this->provider->getAccessToken('authorization_code', $options);

src/UI/Components/GenericAuthControl.php

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,17 @@
1313
class GenericAuthControl extends Control
1414
{
1515

16-
/** @var AuthCodeFlow */
17-
private $authCodeFlow;
16+
/** @var array<callable> */
17+
public array $onAuthenticated = [];
1818

19-
/** @var string|null */
20-
private $redirectUri = null;
19+
/** @var array<callable> */
20+
public array $onFailed = [];
2121

22-
/** @var string|null */
23-
private $templatePath = null;
22+
private AuthCodeFlow $authCodeFlow;
2423

25-
/** @var array<callable> */
26-
public $onAuthenticated = [];
24+
private ?string $redirectUri = null;
2725

28-
/** @var array<callable> */
29-
public $onFailed = [];
26+
private ?string $templatePath = null;
3027

3128
public function __construct(AuthCodeFlow $authCodeFlow, ?string $redirectUri = null)
3229
{
@@ -61,6 +58,7 @@ public function authorize(): ?ResourceOwnerInterface
6158

6259
$user = $this->authCodeFlow->getProvider()->getResourceOwner($accessToken);
6360
$this->authenticationSucceed($accessToken, $user);
61+
6462
return $user;
6563
} catch (IdentityProviderException $e) {
6664
$this->authenticationFailed();
@@ -69,16 +67,6 @@ public function authorize(): ?ResourceOwnerInterface
6967
return null;
7068
}
7169

72-
protected function authenticationFailed(): void
73-
{
74-
$this->onFailed();
75-
}
76-
77-
protected function authenticationSucceed(AccessToken $accessToken, ResourceOwnerInterface $user): void
78-
{
79-
$this->onAuthenticated($accessToken, $user);
80-
}
81-
8270
public function render(): void
8371
{
8472
$template = $this->getTemplate();
@@ -89,4 +77,14 @@ public function render(): void
8977
$template->render($this->templatePath ?? __DIR__ . '/GenericAuthControl.latte');
9078
}
9179

80+
protected function authenticationFailed(): void
81+
{
82+
$this->onFailed();
83+
}
84+
85+
protected function authenticationSucceed(AccessToken $accessToken, ResourceOwnerInterface $user): void
86+
{
87+
$this->onAuthenticated($accessToken, $user);
88+
}
89+
9290
}

0 commit comments

Comments
 (0)