Completed
Push — master ( 8696cf...c1ad79 )
by Julien
03:04
created

OAuth2JsonControllerProvider::connect()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 16
rs 9.4285
cc 2
eloc 9
nc 1
nop 1
1
<?php
2
3
namespace Eole\Sandstone\OAuth2\Silex;
4
5
use Symfony\Component\HttpFoundation\Request;
6
use Symfony\Component\HttpFoundation\JsonResponse;
7
use Symfony\Component\HttpKernel\Exception\HttpException;
8
use Silex\Api\ControllerProviderInterface;
9
use Silex\Application;
10
11
class OAuth2JsonControllerProvider implements ControllerProviderInterface
12
{
13
    /**
14
     * {@inheritDoc}
15
     */
16
    public function connect(Application $app)
17
    {
18
        $controllers = $app['controllers_factory'];
19
20
        $controllers->post('/access-token', function (Request $request) use ($app) {
21
            try {
22
                $token = $app['sandstone.oauth.controller']->postAccessToken($request);
23
24
                return new JsonResponse($token);
25
            } catch (OAuthException $e) {
0 ignored issues
show
Bug introduced by
The class Eole\Sandstone\OAuth2\Silex\OAuthException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
26
                throw new HttpException($e->httpStatusCode, $e->errorType.': '.$e->getMessage(), $e);
27
            }
28
        });
29
30
        return $controllers;
31
    }
32
}
33