Failed Conditions
Push — master ( c6baf0...a3629e )
by Florent
16:19
created

CreateRefreshTokenHandler::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 28
rs 9.472
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2018 Spomky-Labs
9
 *
10
 * This software may be modified and distributed under the terms
11
 * of the MIT license.  See the LICENSE file for details.
12
 */
13
14
namespace OAuth2Framework\Component\RefreshTokenGrant\Command;
15
16
use OAuth2Framework\Component\RefreshTokenGrant\Event\RefreshTokenCreatedEvent;
17
use OAuth2Framework\Component\RefreshTokenGrant\RefreshToken;
18
use OAuth2Framework\Component\RefreshTokenGrant\RefreshTokenRepository;
19
use SimpleBus\SymfonyBridge\Bus\EventBus;
20
21
class CreateRefreshTokenHandler
22
{
23
    private $refreshTokenRepository;
24
    private $eventBus;
25
26
    public function __construct(RefreshTokenRepository $refreshTokenRepository, EventBus $eventBus)
27
    {
28
        $this->refreshTokenRepository = $refreshTokenRepository;
29
        $this->eventBus = $eventBus;
30
    }
31
32
    public function handle(CreateRefreshToken $command): void
33
    {
34
        $refreshToken = $this->refreshTokenRepository->find($command->getRefreshTokenId());
35
        if ($refreshToken) {
36
            throw new \InvalidArgumentException(\sprintf('The refresh token with ID "%s" already exist.', $command->getRefreshTokenId()->getValue()));
37
        }
38
39
        $refreshToken = new RefreshToken(
40
            $command->getRefreshTokenId(),
41
            $command->getResourceOwnerId(),
0 ignored issues
show
Bug introduced by
The method getResourceOwnerId() does not seem to exist on object<OAuth2Framework\C...and\CreateRefreshToken>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
42
            $command->getClientId(),
43
            $command->getParameter(),
44
            $command->getMetadata(),
45
            $command->getExpiresAt(),
46
            $command->getResourceServerId()
47
        );
48
        $this->refreshTokenRepository->save($refreshToken);
49
        $event = new RefreshTokenCreatedEvent(
50
            $command->getRefreshTokenId(),
51
            $command->getResourceOwnerId(),
0 ignored issues
show
Bug introduced by
The method getResourceOwnerId() does not seem to exist on object<OAuth2Framework\C...and\CreateRefreshToken>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
52
            $command->getClientId(),
53
            $command->getParameter(),
54
            $command->getMetadata(),
55
            $command->getExpiresAt(),
56
            $command->getResourceServerId()
57
        );
58
        $this->eventBus->handle($event);
59
    }
60
}
61