Passed
Push — master ( 1d30f9...202808 )
by Peter
04:48
created

AccessToken   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 20
dl 0
loc 63
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 15 2
A __construct() 0 16 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Admin\Http\Controllers\Api;
6
7
use AbterPhp\Framework\Http\Controllers\ControllerAbstract;
8
use AbterPhp\Framework\Psr7\RequestConverter;
0 ignored issues
show
Bug introduced by
The type AbterPhp\Framework\Psr7\RequestConverter was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use AbterPhp\Framework\Psr7\ResponseConverter;
0 ignored issues
show
Bug introduced by
The type AbterPhp\Framework\Psr7\ResponseConverter was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use AbterPhp\Framework\Psr7\ResponseFactory;
0 ignored issues
show
Bug introduced by
The type AbterPhp\Framework\Psr7\ResponseFactory was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use AbterPhp\Framework\Session\FlashService;
12
use League\OAuth2\Server\AuthorizationServer;
0 ignored issues
show
Bug introduced by
The type League\OAuth2\Server\AuthorizationServer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use League\OAuth2\Server\Exception\OAuthServerException;
0 ignored issues
show
Bug introduced by
The type League\OAuth2\Server\Exc...on\OAuthServerException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use Opulence\Http\Responses\Response;
15
use Psr\Log\LoggerInterface;
16
17
class AccessToken extends ControllerAbstract
18
{
19
    /** @var AuthorizationServer */
20
    protected $authorizationServer;
21
22
    /** @var RequestConverter */
23
    protected $requestConverter;
24
25
    /** @var ResponseFactory */
26
    protected $responseFactory;
27
28
    /** @var ResponseConverter */
29
    protected $responseConverter;
30
31
    /** @var LoggerInterface */
32
    protected $logger;
33
34
    /**
35
     * AccessToken constructor.
36
     *
37
     * @param FlashService        $flashService
38
     * @param AuthorizationServer $authorizationServer
39
     * @param RequestConverter    $requestConverter
40
     * @param ResponseFactory     $responseFactory
41
     * @param ResponseConverter   $responseConverter
42
     * @param LoggerInterface     $logger
43
     */
44
    public function __construct(
45
        FlashService $flashService,
46
        AuthorizationServer $authorizationServer,
47
        RequestConverter $requestConverter,
48
        ResponseFactory $responseFactory,
49
        ResponseConverter $responseConverter,
50
        LoggerInterface $logger
51
    ) {
52
        parent::__construct($flashService);
53
54
        $this->authorizationServer = $authorizationServer;
55
56
        $this->requestConverter  = $requestConverter;
57
        $this->responseFactory   = $responseFactory;
58
        $this->responseConverter = $responseConverter;
59
        $this->logger            = $logger;
60
    }
61
62
    /**
63
     * @return Response
64
     */
65
    public function create(): Response
66
    {
67
        $psr7Request  = $this->requestConverter->toPsr($this->request);
68
        $prs7Response = $this->responseFactory->create();
69
70
        try {
71
            $prs7Response = $this->authorizationServer->respondToAccessTokenRequest($psr7Request, $prs7Response);
72
        } catch (OAuthServerException $e) {
73
            // TODO: error in response...
74
            $this->logger->info($e->getMessage());
75
        }
76
77
        $response = $this->responseConverter->fromPsr($prs7Response);
78
79
        return $response;
80
    }
81
}
82