Failed Conditions
Pull Request — master (#17)
by
unknown
03:19
created

src/Token.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Chadicus\Slim\OAuth2\Routes;
4
5
use Chadicus\Slim\OAuth2\Http\MessageBridge;
6
use OAuth2;
7
use Slim\Slim;
8
9
/**
10
 * Slim route for /token endpoint.
11
 */
12 View Code Duplication
class Token
0 ignored issues
show
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
13
{
14
    const ROUTE = '/token';
15
16
    /**
17
     * The slim framework application.
18
     *
19
     * @var Slim
20
     */
21
    private $slim;
22
23
    /**
24
     * The OAuth2 server instance.
25
     *
26
     * @var OAuth2\Server
27
     */
28
    private $server;
29
30
    /**
31
     * Create a new instance of the Token route.
32
     *
33
     * @param Slim          $slim   The slim framework application instance.
34
     * @param OAuth2\Server $server The oauth2 server imstance.
35
     */
36
    public function __construct(Slim $slim, OAuth2\Server $server)
37
    {
38
        $this->slim = $slim;
39
        $this->server = $server;
40
    }
41
42
    /**
43
     * Allows this class to be callable.
44
     *
45
     * @return void
46
     */
47
    public function __invoke()
48
    {
49
        $request = MessageBridge::newOAuth2Request($this->slim->request());
50
        MessageBridge::mapResponse(
51
            $this->server->handleTokenRequest($request),
52
            $this->slim->response()
53
        );
54
    }
55
56
    /**
57
     * Register this route with the given Slim application and OAuth2 server
58
     *
59
     * @param Slim          $slim   The slim framework application instance.
60
     * @param OAuth2\Server $server The oauth2 server imstance.
61
     *
62
     * @return void
63
     */
64
    public static function register(Slim $slim, OAuth2\Server $server)
65
    {
66
        $slim->post(self::ROUTE, new static($slim, $server))->name('token');
67
    }
68
}
69