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

MarkAuthorizationCodeAsRevokedHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 26
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A handle() 0 14 2
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\AuthorizationCodeGrant\Command;
15
16
use OAuth2Framework\Component\AuthorizationCodeGrant\AuthorizationCodeRepository;
17
use OAuth2Framework\Component\AuthorizationCodeGrant\Event\AuthorizationCodeMarkedAsRevokedEvent;
18
use SimpleBus\SymfonyBridge\Bus\EventBus;
19
20
class MarkAuthorizationCodeAsRevokedHandler
21
{
22
    private $authorizationCodeRepository;
23
    private $eventBus;
24
25
    public function __construct(AuthorizationCodeRepository $authorizationCodeRepository, EventBus $eventBus)
26
    {
27
        $this->authorizationCodeRepository = $authorizationCodeRepository;
28
        $this->eventBus = $eventBus;
29
    }
30
31
    public function handle(MarkAuthorizationCodeAsRevoked $command): void
32
    {
33
        $authorizationCode = $this->authorizationCodeRepository->find($command->getAuthorizationCodeId());
34
        if (!$authorizationCode) {
35
            throw new \InvalidArgumentException(\sprintf('The authorization code with ID "%s" does not exist.', $command->getAuthorizationCodeId()->getValue()));
36
        }
37
38
        $authorizationCode->markAsRevoked();
39
        $this->authorizationCodeRepository->save($authorizationCode);
40
        $event = new AuthorizationCodeMarkedAsRevokedEvent(
41
            $command->getAuthorizationCodeId()
42
        );
43
        $this->eventBus->handle($event);
44
    }
45
}
46