Completed
Push — master ( 9628d6...a206dc )
by Derek Stephen
09:38
created

OAuthController::init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 20
rs 9.4285
c 1
b 0
f 0
ccs 0
cts 14
cp 0
cc 1
eloc 14
nc 1
nop 0
crap 2
1
<?php
2
3
namespace App\Controller;
4
5
use Bone\Mvc\Controller;
6
use DateInterval;
7
use DateTime;
8
use Del\Common\ContainerService;
9
use Exception;
10
use OAuth2\Server;
11
use Psr\Http\Message\ResponseInterface;
12
use Zend\Diactoros\Response;
13
use Zend\Diactoros\Response\SapiEmitter;
14
15
class OAuthController extends Controller
16
{
17
    /** @var Server $oauth2Server */
18
    protected $oauth2Server;
19
20
    public function init()
21
    {
22
        $container = ContainerService::getInstance()->getContainer();
23
        $clientRepository = $container['repository.Client'];
24
        $accessTokenRepository = $container['repository.AccessToken'];
25
        $scopeRepository = $container['repository.Scope'];
0 ignored issues
show
Unused Code introduced by
$scopeRepository is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
26
        $userRepository = $container['repository.User'];
27
        $refreshTokenRepository = $container['repository.RefreshToken'];
0 ignored issues
show
Unused Code introduced by
$refreshTokenRepository is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
28
29
30
        $server = new Server([
31
            'client_credentials' => $clientRepository,
32
            'user_credentials'   => $userRepository,
33
            'access_token'       => $accessTokenRepository,
34
        ], [
35
            'auth_code_lifetime' => 30,
36
            'refresh_token_lifetime' => 30,
37
        ]);
38
        $this->oauth2Server = $server;
39
    }
40
41
42
    /**
43
     * Sends a response with the time
44
     */
45
    public function pingAction()
46
    {
47
        $date = new DateTime();
48
        $this->sendJsonResponse(['pong' => $date->format('Y-m-d H:i:s')]);
49
    }
50
51
    /**
52
     * @param ResponseInterface $response
53
     */
54
    public function sendResponse(ResponseInterface $response)
55
    {
56
        $emitter = new SapiEmitter();
57
        $emitter->emit($response);
58
        exit();
0 ignored issues
show
Coding Style Compatibility introduced by
The method sendResponse() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
59
    }
60
}
61