TokenApiController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A postAction() 0 12 3
1
<?php
2
3
namespace Majora\Bundle\OAuthServerBundle\Controller;
4
5
use Majora\Bundle\FrameworkExtraBundle\Controller\RestApiControllerTrait;
6
use Majora\Component\OAuth\Exception\InvalidGrantException;
7
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
8
use Symfony\Component\HttpFoundation\JsonResponse;
9
use Symfony\Component\HttpFoundation\Request;
10
11
/**
12
 * Controller for oAuth tokens web cases.
13
 */
14
class TokenApiController extends Controller
15
{
16
    use RestApiControllerTrait;
17
18
    /**
19
     * Create a new access_token from given request throught oAuth server.
20
     *
21
     * @param Request $request
22
     *
23
     * @return Response
24
     */
25
    public function postAction(Request $request)
26
    {
27
        try {
28
            return $this->createJsonResponse($this->get('oauth.server')->grant(
29
                $this->getRequestData($request, 'snakelize')
30
            ));
31
        } catch (InvalidGrantException $e) {
32
            return new JsonResponse('Unavailable to create access token : bad credentials.', 401);
33
        } catch (\InvalidArgumentException $e) {
34
            return new JsonResponse('Invalid or missing fields for grant type.', 400);
35
        }
36
    }
37
}
38