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

OAuthController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 46
rs 10
c 1
b 0
f 0
ccs 0
cts 26
cp 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 20 1
A pingAction() 0 5 1
A sendResponse() 0 6 1
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