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

OAuthController::init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1.0013

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 0
loc 15
ccs 8
cts 9
cp 0.8889
crap 1.0013
rs 10
c 0
b 0
f 0
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