CredentialFactory::build()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 27
ccs 13
cts 13
cp 1
rs 9.488
c 0
b 0
f 0
cc 1
nc 1
nop 11
crap 1

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 2
    public function buildFromArray(array $params): Credential
10
    {
11 2
        return $this->build(
12 2
            $params['uri'],
13 2
            $params['authorization'],
14 2
            $params['grantType'],
15 2
            $params['username'],
16 2
            $params['password'],
17 2
            isset($params['accessToken']) ? $params['accessToken'] : null,
18 2
            isset($params['tokenType']) ? $params['tokenType'] : null,
19 2
            isset($params['refreshToken']) ? $params['refreshToken'] : null,
20 2
            isset($params['expiresIn']) ? $params['expiresIn'] : null,
21 2
            isset($params['scope']) ? $params['scope'] : null,
22 2
            isset($params['obtainedIn']) ? $params['obtainedIn'] : null
23
        );
24
    }
25
26 2
    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 2
        return new Credential(
40 2
            $uri,
41 2
            $authorization,
42 2
            $grantType,
43 2
            $username,
44 2
            $password,
45 2
            $accessToken,
46 2
            $tokenType,
47 2
            $refreshToken,
48 2
            $expiresIn,
49 2
            $scope,
50 2
            $obtainedIn
51
        );
52
    }
53
}
54