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

OAuthEventSubscriber::getSubscribedEvents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
ccs 2
cts 2
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
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