OAuthController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 3
c 1
b 1
f 0
lcom 1
cbo 3
dl 0
loc 37
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A indexAction() 0 6 1
B codeAction() 0 27 2
1
<?php
2
3
namespace Mailxpert\APIBundle\Controller;
4
5
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6
7
class OAuthController extends Controller
8
{
9
    public function indexAction()
10
    {
11
        $url = $this->get('mailxpert_api.manager')->getLoginUrl();
12
13
        return $this->render('@MailxpertAPI/OAuth/index.html.twig', array('url' => $url));
14
    }
15
16
    public function codeAction()
17
    {
18
        $accessToken = $this->get('mailxpert_api.manager')->retrieveAccessToken();
19
20
        $localAccessToken = $this->get('mailxpert_api.access_token_manager')->findByAccessToken($accessToken->getAccessToken());
21
22
        if (!$localAccessToken) {
23
            $localAccessToken = $this->get('mailxpert_api.access_token_manager')->createAccessToken();
24
            $localAccessToken->setAccessToken($accessToken->getAccessToken());
25
            $localAccessToken->setExpireAt($accessToken->getExpiresAt());
26
27
            $this->getDoctrine()->getManager()->persist($localAccessToken);
28
        }
29
30
        $localAccessToken->setRefreshToken($accessToken->getRefreshToken());
31
        $localAccessToken->setRefreshTokenExpireAt($accessToken->getRefreshTokenExpiresAt());
32
        $localAccessToken->setScope($accessToken->getScope());
33
34
        $this->getDoctrine()->getManager()->flush();
35
36
        $this->get('mailxpert_api.access_token_manager')->setAccessToken($localAccessToken);
37
38
        $expireAt = new \DateTime();
39
        $expireAt->setTimestamp($accessToken->getExpiresAt());
40
41
        return $this->render('@MailxpertAPI/OAuth/oauth.html.twig', array('expireAt' => $expireAt));
42
    }
43
}