AccessTokenController::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 7
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 7
loc 7
ccs 0
cts 6
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace CodexShaper\OAuth2\Server\Http\Controllers;
4
5
use CodexShaper\OAuth2\Server\Http\Requests\ServerRequest;
6
use CodexShaper\OAuth2\Server\Http\Responses\ServerResponse;
7
use CodexShaper\OAuth2\Server\Manager;
8
9 View Code Duplication
class AccessTokenController
0 ignored issues
show
Duplication introduced by
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...
10
{
11
    /**
12
     * The server manager.
13
     *
14
     * @var \CodexShaper\OAuth2\Server\Manager
15
     */
16
    protected $manager;
17
18
    /**
19
     * The authorization server.
20
     *
21
     * @var \League\OAuth2\Server\AuthorizationServer
22
     */
23
    protected $server;
24
25
    /**
26
     * The psr7 server request.
27
     *
28
     * @var \CodexShaper\OAuth2\Server\Http\Requests\ServerRequest
29
     */
30
    protected $request;
31
32
    /**
33
     * The psr7 server response.
34
     *
35
     * @var \CodexShaper\OAuth2\Server\Http\Responses\ServerResponse
36
     */
37
    protected $response;
38
39
    /**
40
     * Create a new access token controller instance.
41
     *
42
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
43
     */
44
    public function __construct()
45
    {
46
        $this->manager = new Manager();
47
        $this->server = $this->manager->makeAuthorizationServer();
48
        $this->request = ServerRequest::getPsrServerRequest();
49
        $this->response = ServerResponse::getPsrServerResponse();
0 ignored issues
show
Documentation Bug introduced by
It seems like \CodexShaper\OAuth2\Serv...:getPsrServerResponse() of type object<Nyholm\Psr7\Response> is incompatible with the declared type object<CodexShaper\OAuth...sponses\ServerResponse> of property $response.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
50
    }
51
52
    /**
53
     * Make access token.
54
     *
55
     * @return \League\OAuth2\Server\ResponseTypes\ResponseTypeInterface
56
     */
57
    public function issueAccessToken()
58
    {
59
        try {
60
61
            // Try to respond to the request
62
            return $this->server->respondToAccessTokenRequest($this->request, $this->response)->getBody();
0 ignored issues
show
Documentation introduced by
$this->request is of type object<CodexShaper\OAuth...Requests\ServerRequest>, but the function expects a object<Psr\Http\Message\ServerRequestInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$this->response is of type object<CodexShaper\OAuth...sponses\ServerResponse>, but the function expects a object<Psr\Http\Message\ResponseInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
63
        } catch (OAuthServerException $exception) {
0 ignored issues
show
Bug introduced by
The class CodexShaper\OAuth2\Serve...rs\OAuthServerException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
64
65
            // All instances of OAuthServerException can be formatted into a HTTP response
66
            return $exception->generateHttpResponse($this->response);
67
        }
68
    }
69
}
70