ClientController::viewAction()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 30
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 20
nc 4
nop 1
dl 0
loc 30
ccs 0
cts 22
cp 0
crap 12
rs 9.6
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\CoreBundle\Controller;
12
13
use LoginCidadao\CoreBundle\Entity\Authorization;
14
use LoginCidadao\RemoteClaimsBundle\Model\RemoteClaimManagerInterface;
15
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
16
use Symfony\Component\Routing\Annotation\Route;
17
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
18
19
class ClientController extends Controller
20
{
21
22
    /**
23
     * @Route("/client/view/{clientId}", name="lc_app_details")
24
     * @Template()
25
     */
26
    public function viewAction($clientId)
27
    {
28
        $em = $this->getDoctrine()->getManager();
29
30
        $clients = $em->getRepository('LoginCidadaoOAuthBundle:Client');
31
        $client = $clients->find($clientId);
32
        $user = $this->getUser();
33
34
        /** @var Authorization|null $authorization */
35
        $authorization = $this->getDoctrine()
36
            ->getRepository('LoginCidadaoCoreBundle:Authorization')
37
            ->findOneBy(['person' => $user, 'client' => $client]);
38
39
        /** @var RemoteClaimManagerInterface $remoteClaimManager */
40
        $remoteClaimManager = $this->get('lc.remote_claims.manager');
41
        $remoteClaims = $authorization ? $remoteClaimManager->getRemoteClaimsFromAuthorization($authorization) : [];
42
43
        $scopes = empty($authorization) ? [] : $authorization->getScope();
44
45
        $form = $this->createForm(
46
            'LoginCidadao\CoreBundle\Form\Type\RevokeAuthorizationFormType',
47
            ['client_id' => $clientId]
48
        )->createView();
49
50
        return [
51
            'user' => $user,
52
            'client' => $client,
53
            'scopes' => $remoteClaimManager->filterRemoteClaims($scopes),
54
            'remoteClaims' => $remoteClaims,
55
            'form' => $form,
56
        ];
57
    }
58
}
59