Failed Conditions
Pull Request — master (#790)
by Guilherme
10:36 queued 05:09
created

OAuthEventSubscriber   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 29
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A onUpdateAuthorization() 0 9 2
A onNewAuthorization() 0 8 1
A getSubscribedEvents() 0 5 1
1
<?php
2
/**
3
 * This file is part of the login-cidadao project or it's bundles.
4
 *
5
 * (c) Guilherme Donato <guilhermednt on github>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace LoginCidadao\OpenIDBundle\EventListener;
12
13
use Doctrine\ORM\EntityManager;
14
use Doctrine\ORM\EntityManagerInterface;
15
use LoginCidadao\CoreBundle\Entity\Authorization;
16
use LoginCidadao\CoreBundle\Event\GetClientEvent;
17
use LoginCidadao\CoreBundle\Event\LoginCidadaoCoreEvents;
18
use LoginCidadao\OpenIDBundle\Entity\ClientMetadata;
19
use LoginCidadao\OpenIDBundle\Event\AuthorizationEvent;
20
use LoginCidadao\OpenIDBundle\LoginCidadaoOpenIDEvents;
21
use LoginCidadao\OpenIDBundle\Validator\SectorIdentifierUriChecker;
22
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
23
24
class OAuthEventSubscriber implements EventSubscriberInterface
25
{
26 1
    public static function getSubscribedEvents()
27
    {
28
        return [
29 1
            LoginCidadaoOpenIDEvents::NEW_AUTHORIZATION => ['onNewAuthorization', 10],
30
            LoginCidadaoOpenIDEvents::UPDATE_AUTHORIZATION => ['onUpdateAuthorization', 10],
31
        ];
32
    }
33
34 1
    public function onNewAuthorization(AuthorizationEvent $event)
35
    {
36 1
        $authorization = new Authorization();
37 1
        $authorization->setPerson($event->getPerson());
38 1
        $authorization->setClient($event->getClient());
39 1
        $authorization->setScope($event->getScope());
40
41 1
        $event->setAuthorization($authorization);
42 1
    }
43
44 2
    public function onUpdateAuthorization(AuthorizationEvent $event)
45
    {
46 2
        $authorization = $event->getAuthorization();
47 2
        if (!$authorization instanceof Authorization) {
0 ignored issues
show
introduced by
$authorization is always a sub-type of LoginCidadao\CoreBundle\Entity\Authorization.
Loading history...
48
            // A pre-existing Authorization is expected. There is nothing we can do here.
49 1
            return;
50
        }
51 1
        $merged = array_merge($authorization->getScope(), $event->getScope());
52 1
        $authorization->setScope($merged);
53 1
    }
54
}
55