Server::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 8
dl 0
loc 18
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
namespace roaresearch\yii2\oauth2server;
4
5
use OAuth2\{
6
    ClientAssertionType\ClientAssertionTypeInterface,
7
    RequestInterface,
8
    ResponseInterface,
9
    ScopeInterface,
10
    Server as BaseServer,
11
    TokenType\TokenTypeInterface
12
};
13
14
class Server extends BaseServer
15
{
16 9
    public function __construct(
17
        protected Module $module,
18
        $storage = [],
19
        array $config = [],
20
        array $grantTypes = [],
21
        array $responseTypes = [],
22
        TokenTypeInterface $tokenType = null,
23
        ScopeInterface $scopeUtil = null,
24
        ClientAssertionTypeInterface $clientAssertionType = null
25
    ) {
26 9
        parent::__construct(
27
            $storage,
28
            $config,
29
            $grantTypes,
30
            $responseTypes,
31
            $tokenType,
32
            $scopeUtil,
33
            $clientAssertionType
34
        );
35
    }
36
37
    public function createAccessToken(
38
        $clientId,
39
        $userId,
40
        $scope = null,
41
        $includeRefreshToken = true
42
    ) {
43
        return $this->getAccessTokenResponseType()->createAccessToken(
44
            $clientId,
45
            $userId,
46
            $scope,
47
            $includeRefreshToken
48
        );
49
    }
50
51
    /**
52
     * @inheritdoc
53
     */
54 4
    public function verifyResourceRequest(
55
        RequestInterface $request = null,
56
        ResponseInterface $response = null,
57
        $scope = null
58
    ) {
59 4
        parent::verifyResourceRequest(
60 4
            $request ?: $this->module->getRequest(),
61 4
            $response ?: $this->module->getResponse(),
62
            $scope
63
        );
64
    }
65
66
    /**
67
     * @inheritdoc
68
     */
69 5
    public function handleTokenRequest(
70
        RequestInterface $request = null,
71
        ResponseInterface $response = null
72
    ) {
73 5
        return parent::handleTokenRequest(
74 5
            $request ?: $this->module->getRequest(),
75 5
            $response ?: $this->module->getResponse()
76
        );
77
    }
78
}
79