Test Failed
Push — master ( 7b50a6...1c581a )
by Ger
02:55
created

CredentialFactory::build()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 9.488
c 0
b 0
f 0
cc 1
nc 1
nop 11

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
declare(strict_types = 1);
4
5
namespace Gertoska\OAuth2Request\Credential;
6
7
final class CredentialFactory
8
{
9
    public function buildFromArray(array $params): Credential
10
    {
11
        return $this->build(
12
            $params['uri'],
13
            $params['authorization'],
14
            $params['grantType'],
15
            $params['username'],
16
            $params['password'],
17
            isset($params['accessToken']) ? $params['accessToken'] : null,
18
            isset($params['tokenType']) ? $params['tokenType'] : null,
19
            isset($params['refreshToken']) ? $params['refreshToken'] : null,
20
            isset($params['expiresIn']) ? $params['expiresIn'] : null,
21
            isset($params['scope']) ? $params['scope'] : null,
22
            isset($params['obtainedIn']) ? $params['obtainedIn'] : null
23
        );
24
    }
25
26
    private function build(
27
        string $uri,
28
        string $authorization,
29
        string $grantType,
30
        string $username,
31
        string $password,
32
        string $accessToken = null,
33
        string $tokenType = null,
34
        string $refreshToken = null,
35
        int $expiresIn = null,
36
        string $scope = null,
37
        int $obtainedIn = null
38
    ): Credential {
39
        return new Credential(
40
            $uri,
41
            $authorization,
42
            $grantType,
43
            $username,
44
            $password,
45
            $accessToken,
46
            $tokenType,
47
            $refreshToken,
48
            $expiresIn,
49
            $scope,
50
            $obtainedIn
51
        );
52
    }
53
}
54