Completed
Push — master ( 1e2634...f226c3 )
by Derek Stephen
03:10
created

OAuthController   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 57.14%

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 30
ccs 8
cts 14
cp 0.5714
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A sendResponse() 0 5 1
A init() 0 15 1
1
<?php
2
3
namespace App\Controller;
4
5
use Bone\Mvc\Controller;
6
use Del\Common\ContainerService;
7
use League\OAuth2\Server\AuthorizationServer;
8
use Psr\Http\Message\ResponseInterface;
9
use Zend\Diactoros\Response\SapiEmitter;
10
11
class OAuthController extends BaseController
12
{
13
    /** @var AuthorizationServer $oauth2Server */
14
    protected $oauth2Server;
15
16 1
    public function init()
17
    {
18
19 1
        $container = ContainerService::getInstance()->getContainer();
20 1
        $clientRepository = $container['repository.Client'];
21 1
        $accessTokenRepository = $container['repository.AccessToken'];
22 1
        $scopeRepository = $container['repository.Scope'];
23
24
        // Setup the authorization server
25 1
        $server = new AuthorizationServer($clientRepository, $accessTokenRepository, $scopeRepository,
26 1
            'file://'.APPLICATION_PATH.'/data/keys/private.key',    // path to private key
27 1
            'file://'.APPLICATION_PATH.'/data/keys/public.key'      // path to public key
28
        );
29
30
        $this->oauth2Server = $server;
31
    }
32
33
    /**
34
     * @param ResponseInterface $response
35
     */
36
    protected function sendResponse(ResponseInterface $response)
37
    {
38
        $emitter = new SapiEmitter();
0 ignored issues
show
Deprecated Code introduced by
The class Zend\Diactoros\Response\SapiEmitter has been deprecated: since 1.8.0. The package zendframework/zend-httphandlerrunner now provides this functionality. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

38
        $emitter = /** @scrutinizer ignore-deprecated */ new SapiEmitter();
Loading history...
39
        $emitter->emit($response);
40
        exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
41
    }
42
}
43