Skip to content

Commit 515c942

Browse files
committed
fix: lint and static analysis
1 parent aff8bfb commit 515c942

18 files changed

+39
-89
lines changed

config/services.php

+6-10
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22

33
declare(strict_types=1);
44

5-
use League\Bundle\OAuth2ServerBundle\Controller\DeviceCodeController;
6-
use League\Bundle\OAuth2ServerBundle\Manager\DeviceCodeManagerInterface;
7-
use League\Bundle\OAuth2ServerBundle\Repository\DeviceCodeRepository;
8-
use League\OAuth2\Server\Grant\DeviceCodeGrant;
9-
use League\OAuth2\Server\Repositories\DeviceCodeRepositoryInterface;
105
use function Symfony\Component\DependencyInjection\Loader\Configurator\abstract_arg;
116
use function Symfony\Component\DependencyInjection\Loader\Configurator\param;
127
use function Symfony\Component\DependencyInjection\Loader\Configurator\service;
@@ -20,6 +15,7 @@
2015
use League\Bundle\OAuth2ServerBundle\Command\ListClientsCommand;
2116
use League\Bundle\OAuth2ServerBundle\Command\UpdateClientCommand;
2217
use League\Bundle\OAuth2ServerBundle\Controller\AuthorizationController;
18+
use League\Bundle\OAuth2ServerBundle\Controller\DeviceCodeController;
2319
use League\Bundle\OAuth2ServerBundle\Controller\TokenController;
2420
use League\Bundle\OAuth2ServerBundle\Converter\ScopeConverter;
2521
use League\Bundle\OAuth2ServerBundle\Converter\ScopeConverterInterface;
@@ -30,12 +26,14 @@
3026
use League\Bundle\OAuth2ServerBundle\Manager\AccessTokenManagerInterface;
3127
use League\Bundle\OAuth2ServerBundle\Manager\AuthorizationCodeManagerInterface;
3228
use League\Bundle\OAuth2ServerBundle\Manager\ClientManagerInterface;
29+
use League\Bundle\OAuth2ServerBundle\Manager\DeviceCodeManagerInterface;
3330
use League\Bundle\OAuth2ServerBundle\Manager\InMemory\ScopeManager;
3431
use League\Bundle\OAuth2ServerBundle\Manager\RefreshTokenManagerInterface;
3532
use League\Bundle\OAuth2ServerBundle\Manager\ScopeManagerInterface;
3633
use League\Bundle\OAuth2ServerBundle\OAuth2Events;
3734
use League\Bundle\OAuth2ServerBundle\Repository\AuthCodeRepository;
3835
use League\Bundle\OAuth2ServerBundle\Repository\ClientRepository;
36+
use League\Bundle\OAuth2ServerBundle\Repository\DeviceCodeRepository;
3937
use League\Bundle\OAuth2ServerBundle\Repository\RefreshTokenRepository;
4038
use League\Bundle\OAuth2ServerBundle\Repository\ScopeRepository;
4139
use League\Bundle\OAuth2ServerBundle\Repository\UserRepository;
@@ -47,12 +45,14 @@
4745
use League\OAuth2\Server\EventEmitting\EventEmitter;
4846
use League\OAuth2\Server\Grant\AuthCodeGrant;
4947
use League\OAuth2\Server\Grant\ClientCredentialsGrant;
48+
use League\OAuth2\Server\Grant\DeviceCodeGrant;
5049
use League\OAuth2\Server\Grant\ImplicitGrant;
5150
use League\OAuth2\Server\Grant\PasswordGrant;
5251
use League\OAuth2\Server\Grant\RefreshTokenGrant;
5352
use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface;
5453
use League\OAuth2\Server\Repositories\AuthCodeRepositoryInterface;
5554
use League\OAuth2\Server\Repositories\ClientRepositoryInterface;
55+
use League\OAuth2\Server\Repositories\DeviceCodeRepositoryInterface;
5656
use League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface;
5757
use League\OAuth2\Server\Repositories\ScopeRepositoryInterface;
5858
use League\OAuth2\Server\Repositories\UserRepositoryInterface;
@@ -216,7 +216,7 @@
216216
service(RefreshTokenRepositoryInterface::class),
217217
null,
218218
null,
219-
null
219+
null,
220220
])
221221
->alias(DeviceCodeGrant::class, 'league.oauth2_server.grant.device_code')
222222

@@ -244,10 +244,6 @@
244244
->set('league.oauth2_server.controller.device_code', DeviceCodeController::class)
245245
->args([
246246
service(AuthorizationServer::class),
247-
service(EventDispatcherInterface::class),
248-
service(AuthorizationRequestResolveEventFactory::class),
249-
service(UserConverterInterface::class),
250-
service(ClientManagerInterface::class),
251247
service('league.oauth2_server.factory.psr_http'),
252248
service('league.oauth2_server.factory.http_foundation'),
253249
service('league.oauth2_server.factory.psr17'),

config/storage/doctrine.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
declare(strict_types=1);
44

5-
use League\Bundle\OAuth2ServerBundle\Manager\DeviceCodeManagerInterface;
6-
use League\Bundle\OAuth2ServerBundle\Manager\Doctrine\DeviceCodeManager;
75
use function Symfony\Component\DependencyInjection\Loader\Configurator\service;
86

97
use League\Bundle\OAuth2ServerBundle\Manager\AccessTokenManagerInterface;
108
use League\Bundle\OAuth2ServerBundle\Manager\AuthorizationCodeManagerInterface;
119
use League\Bundle\OAuth2ServerBundle\Manager\ClientManagerInterface;
10+
use League\Bundle\OAuth2ServerBundle\Manager\DeviceCodeManagerInterface;
1211
use League\Bundle\OAuth2ServerBundle\Manager\Doctrine\AccessTokenManager;
1312
use League\Bundle\OAuth2ServerBundle\Manager\Doctrine\AuthorizationCodeManager;
1413
use League\Bundle\OAuth2ServerBundle\Manager\Doctrine\ClientManager;
14+
use League\Bundle\OAuth2ServerBundle\Manager\Doctrine\DeviceCodeManager;
1515
use League\Bundle\OAuth2ServerBundle\Manager\Doctrine\RefreshTokenManager;
1616
use League\Bundle\OAuth2ServerBundle\Manager\RefreshTokenManagerInterface;
1717
use League\Bundle\OAuth2ServerBundle\Persistence\Mapping\Driver;

config/storage/in_memory.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
declare(strict_types=1);
44

5-
use League\Bundle\OAuth2ServerBundle\Manager\DeviceCodeManagerInterface;
6-
use League\Bundle\OAuth2ServerBundle\Manager\InMemory\DeviceCodeManager;
75
use function Symfony\Component\DependencyInjection\Loader\Configurator\service;
86

97
use League\Bundle\OAuth2ServerBundle\Manager\AccessTokenManagerInterface;
108
use League\Bundle\OAuth2ServerBundle\Manager\AuthorizationCodeManagerInterface;
119
use League\Bundle\OAuth2ServerBundle\Manager\ClientManagerInterface;
10+
use League\Bundle\OAuth2ServerBundle\Manager\DeviceCodeManagerInterface;
1211
use League\Bundle\OAuth2ServerBundle\Manager\InMemory\AccessTokenManager;
1312
use League\Bundle\OAuth2ServerBundle\Manager\InMemory\AuthorizationCodeManager;
1413
use League\Bundle\OAuth2ServerBundle\Manager\InMemory\ClientManager;
14+
use League\Bundle\OAuth2ServerBundle\Manager\InMemory\DeviceCodeManager;
1515
use League\Bundle\OAuth2ServerBundle\Manager\InMemory\RefreshTokenManager;
1616
use League\Bundle\OAuth2ServerBundle\Manager\RefreshTokenManagerInterface;
1717
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

src/Controller/DeviceCodeController.php

-34
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,13 @@
44

55
namespace League\Bundle\OAuth2ServerBundle\Controller;
66

7-
use League\Bundle\OAuth2ServerBundle\Converter\UserConverterInterface;
8-
use League\Bundle\OAuth2ServerBundle\Event\AuthorizationRequestResolveEventFactory;
9-
use League\Bundle\OAuth2ServerBundle\Manager\ClientManagerInterface;
10-
use League\Bundle\OAuth2ServerBundle\Model\AbstractClient;
11-
use League\Bundle\OAuth2ServerBundle\OAuth2Events;
127
use League\OAuth2\Server\AuthorizationServer;
138
use League\OAuth2\Server\Exception\OAuthServerException;
149
use Psr\Http\Message\ResponseFactoryInterface;
1510
use Symfony\Bridge\PsrHttpMessage\HttpFoundationFactoryInterface;
1611
use Symfony\Bridge\PsrHttpMessage\HttpMessageFactoryInterface;
1712
use Symfony\Component\HttpFoundation\Request;
1813
use Symfony\Component\HttpFoundation\Response;
19-
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
2014

2115
final class DeviceCodeController
2216
{
@@ -25,26 +19,6 @@ final class DeviceCodeController
2519
*/
2620
private $server;
2721

28-
/**
29-
* @var EventDispatcherInterface
30-
*/
31-
private $eventDispatcher;
32-
33-
/**
34-
* @var AuthorizationRequestResolveEventFactory
35-
*/
36-
private $eventFactory;
37-
38-
/**
39-
* @var UserConverterInterface
40-
*/
41-
private $userConverter;
42-
43-
/**
44-
* @var ClientManagerInterface
45-
*/
46-
private $clientManager;
47-
4822
/**
4923
* @var HttpMessageFactoryInterface
5024
*/
@@ -62,19 +36,11 @@ final class DeviceCodeController
6236

6337
public function __construct(
6438
AuthorizationServer $server,
65-
EventDispatcherInterface $eventDispatcher,
66-
AuthorizationRequestResolveEventFactory $eventFactory,
67-
UserConverterInterface $userConverter,
68-
ClientManagerInterface $clientManager,
6939
HttpMessageFactoryInterface $httpMessageFactory,
7040
HttpFoundationFactoryInterface $httpFoundationFactory,
7141
ResponseFactoryInterface $responseFactory,
7242
) {
7343
$this->server = $server;
74-
$this->eventDispatcher = $eventDispatcher;
75-
$this->eventFactory = $eventFactory;
76-
$this->userConverter = $userConverter;
77-
$this->clientManager = $clientManager;
7844
$this->httpMessageFactory = $httpMessageFactory;
7945
$this->httpFoundationFactory = $httpFoundationFactory;
8046
$this->responseFactory = $responseFactory;

src/Entity/DeviceCode.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace League\Bundle\OAuth2ServerBundle\Entity;
46

57
use League\OAuth2\Server\Entities\DeviceCodeEntityInterface;

src/Manager/Doctrine/DeviceCodeManager.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function find(string $identifier): ?DeviceCodeInterface
2828

2929
public function findByUserCode(string $code): ?DeviceCodeInterface
3030
{
31-
/** @var DeviceCodeInterface */
31+
/** @var ?DeviceCodeInterface */
3232
return $this->entityManager->createQueryBuilder()
3333
->select('dc')
3434
->from(DeviceCode::class, 'dc')
@@ -43,6 +43,7 @@ public function save(DeviceCodeInterface $deviceCode, bool $persist = true): voi
4343
if ($persist) {
4444
$this->entityManager->persist($deviceCode);
4545
}
46+
4647
$this->entityManager->flush();
4748
}
4849

@@ -56,5 +57,4 @@ public function clearExpired(): int
5657
->getQuery()
5758
->execute();
5859
}
59-
6060
}

src/Manager/InMemory/DeviceCodeManager.php

-1
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,4 @@ public function clearExpired(): int
4646

4747
return $count - \count($this->deviceCodes);
4848
}
49-
5049
}

src/Model/DeviceCode.php

+7-9
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
class DeviceCode implements DeviceCodeInterface
1010
{
1111
/**
12-
* @var string
12+
* @var non-empty-string
1313
*/
1414
private $identifier;
1515

1616
/**
17-
* @var \DateTimeInterface
17+
* @var \DateTimeImmutable
1818
*/
1919
private $expiry;
2020

@@ -51,15 +51,15 @@ class DeviceCode implements DeviceCodeInterface
5151
/**
5252
* @var bool
5353
*/
54-
private $includeVerificationUriComplete;
54+
private $includeVerificationUriComplete = false;
5555

5656
/**
5757
* @var string
5858
*/
5959
private $verificationUri;
6060

6161
/**
62-
* @var \DateTimeInterface|null
62+
* @var \DateTimeImmutable|null
6363
*/
6464
private $lastPolledAt;
6565

@@ -69,6 +69,7 @@ class DeviceCode implements DeviceCodeInterface
6969
private $interval;
7070

7171
/**
72+
* @param non-empty-string $identifier
7273
* @param list<Scope> $scopes
7374
*/
7475
public function __construct(
@@ -79,10 +80,9 @@ public function __construct(
7980
array $scopes,
8081
string $userCode,
8182
bool $userApproved,
82-
bool $includeVerificationUriComplete,
8383
string $verificationUri,
8484
?\DateTimeImmutable $lastPolledAt,
85-
int $interval
85+
int $interval,
8686
) {
8787
$this->identifier = $identifier;
8888
$this->expiry = $expiry;
@@ -91,7 +91,6 @@ public function __construct(
9191
$this->scopes = $scopes;
9292
$this->userCode = $userCode;
9393
$this->userApproved = $userApproved;
94-
$this->includeVerificationUriComplete = $includeVerificationUriComplete;
9594
$this->verificationUri = $verificationUri;
9695
$this->lastPolledAt = $lastPolledAt;
9796
$this->interval = $interval;
@@ -117,7 +116,7 @@ public function getUserIdentifier(): ?string
117116
return $this->userIdentifier;
118117
}
119118

120-
public function setUserIdentifier($userIdentifier): DeviceCodeInterface
119+
public function setUserIdentifier(?string $userIdentifier): DeviceCodeInterface
121120
{
122121
$this->userIdentifier = $userIdentifier;
123122

@@ -189,5 +188,4 @@ public function getInterval(): int
189188
{
190189
return $this->interval;
191190
}
192-
193191
}

src/Model/DeviceCodeInterface.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ interface DeviceCodeInterface
1010
{
1111
public function __toString(): string;
1212

13+
/**
14+
* @return non-empty-string
15+
*/
1316
public function getIdentifier(): string;
1417

1518
public function getExpiry(): \DateTimeImmutable;
@@ -44,5 +47,4 @@ public function getLastPolledAt(): ?\DateTimeImmutable;
4447
public function setLastPolledAt(\DateTimeImmutable $lastPolledAt): self;
4548

4649
public function getInterval(): int;
47-
4850
}

src/Repository/DeviceCodeRepository.php

+10-12
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ public function __construct(
4242
DeviceCodeManagerInterface $deviceCodeManager,
4343
ClientManagerInterface $clientManager,
4444
ScopeConverterInterface $scopeConverter,
45-
ClientRepositoryInterface $clientRepository
45+
ClientRepositoryInterface $clientRepository,
4646
) {
4747
$this->deviceCodeManager = $deviceCodeManager;
48-
$this->clientManager = $clientManager;
49-
$this->scopeConverter = $scopeConverter;
50-
$this->clientRepository = $clientRepository;
48+
$this->clientManager = $clientManager;
49+
$this->scopeConverter = $scopeConverter;
50+
$this->clientRepository = $clientRepository;
5151
}
5252

5353
public function getNewDeviceCode(): DeviceCodeEntityInterface
@@ -76,15 +76,15 @@ public function approveDeviceCode(string $userCode, string $userId): void
7676
{
7777
$deviceCode = $this->deviceCodeManager->findByUserCode($userCode);
7878

79-
if ($deviceCode instanceof DeviceCodeInterface === false) {
79+
if (false === $deviceCode instanceof DeviceCodeInterface) {
8080
throw OAuthServerException::invalidRequest('device_code', 'Device code does not exist');
8181
}
8282

8383
if ($deviceCode->isRevoked()) {
8484
throw OAuthServerException::invalidRequest('device_code', 'Device code has been revoked');
8585
}
8686

87-
if ($userId === '') {
87+
if ('' === $userId) {
8888
throw OAuthServerException::invalidRequest('user_id', 'User ID is required');
8989
}
9090

@@ -134,9 +134,10 @@ private function buildDeviceCodeEntity(DeviceCodeInterface $deviceCode): DeviceC
134134
$deviceCodeEntity = new DeviceCodeEntity();
135135
$deviceCodeEntity->setIdentifier($deviceCode->getIdentifier());
136136
$deviceCodeEntity->setExpiryDateTime($deviceCode->getExpiry());
137-
$deviceCodeEntity->setClient(
138-
$this->clientRepository->buildClientEntity($deviceCode->getClient())
139-
);
137+
$client = $this->clientRepository->getClientEntity($deviceCode->getClient()->getIdentifier());
138+
if ($client) {
139+
$deviceCodeEntity->setClient($client);
140+
}
140141
if ($deviceCode->getUserIdentifier()) {
141142
$deviceCodeEntity->setUserIdentifier($deviceCode->getUserIdentifier());
142143
}
@@ -156,7 +157,6 @@ private function buildDeviceCodeEntity(DeviceCodeInterface $deviceCode): DeviceC
156157
return $deviceCodeEntity;
157158
}
158159

159-
160160
private function buildDeviceCodeModel(DeviceCodeEntityInterface $deviceCodeEntity): DeviceCodeModel
161161
{
162162
/** @var AbstractClient $client */
@@ -172,11 +172,9 @@ private function buildDeviceCodeModel(DeviceCodeEntityInterface $deviceCodeEntit
172172
$this->scopeConverter->toDomainArray(array_values($deviceCodeEntity->getScopes())),
173173
$deviceCodeEntity->getUserCode(),
174174
$deviceCodeEntity->getUserApproved(),
175-
$deviceCodeEntity->getVerificationUriCompleteInAuthResponse(),
176175
$deviceCodeEntity->getVerificationUri(),
177176
$deviceCodeEntity->getLastPolledAt(),
178177
$deviceCodeEntity->getInterval()
179178
);
180179
}
181-
182180
}

tests/Acceptance/DeviceCodeEndpointTest.php

-1
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,4 @@ public function testFailedWithUnkownClientRequest(): void
6464
$this->assertNotEmpty($jsonResponse['error_description']);
6565
$this->assertSame('invalid_client', $jsonResponse['error']);
6666
}
67-
6867
}

tests/Acceptance/DoctrineCredentialsRevokerTest.php

-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ private function buildDeviceCode(string $identifier, string $modify, Client $cli
131131
[],
132132
'',
133133
false,
134-
false,
135134
'',
136135
null,
137136
5

0 commit comments

Comments
 (0)