Completed
Push — develop ( de0fb5...78995e )
by Risan Bagja
01:33
created

RequestFactory   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 91.3%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 5
dl 0
loc 103
ccs 21
cts 23
cp 0.913
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getAuthorizationHeader() 0 4 1
A getConfig() 0 4 1
A getUriParser() 0 4 1
A createForTemporaryCredentials() 0 8 1
A buildAuthorizationUri() 0 7 1
A createForTokenCredentials() 0 11 1
A create() 0 4 1
1
<?php
2
3
namespace Risan\OAuth1\Request;
4
5
use Risan\OAuth1\Credentials\TemporaryCredentials;
6
7
class RequestFactory implements RequestFactoryInterface
8
{
9
    /**
10
     * The AuthorizationHeaderInterface instance.
11
     *
12
     * @var \Risan\OAuth1\Request\AuthorizationHeaderInterface
13
     */
14
    protected $authorizationHeader;
15
16
    /**
17
     * The UriParserInterface instance.
18
     *
19
     * @var \Risan\OAuth1\Request\UriParserInterface
20
     */
21
    protected $uriParser;
22
23
    /**
24
     * Create the new instance of RequestFactory class.
25
     *
26
     * @param \Risan\OAuth1\Request\AuthorizationHeaderInterface $authorizationHeader
27
     * @param \Risan\OAuth1\Request\UriParserInterface $uriParser
28
     */
29 7
    public function __construct(AuthorizationHeaderInterface $authorizationHeader, UriParserInterface $uriParser)
30
    {
31 7
        $this->authorizationHeader = $authorizationHeader;
32 7
        $this->uriParser = $uriParser;
33 7
    }
34
35
    /**
36
     * {@inheritDoc}
37
     */
38 1
    public function getAuthorizationHeader()
39
    {
40 1
        return $this->authorizationHeader;
41
    }
42
43
    /**
44
     * {@inheritDoc}
45
     */
46 1
    public function getConfig()
47
    {
48 1
        return $this->authorizationHeader->getConfig();
49
    }
50
51
    /**
52
     * {@inheritDoc}
53
     */
54 1
    public function getUriParser()
55
    {
56 1
        return $this->uriParser;
57
    }
58
59
    /**
60
     * {@inheritDoc}
61
     */
62 1
    public function createForTemporaryCredentials()
63
    {
64 1
        return $this->create('POST', $this->getConfig()->getTemporaryCredentialsUri(), [
0 ignored issues
show
Documentation introduced by
$this->getConfig()->getTemporaryCredentialsUri() is of type object<Psr\Http\Message\UriInterface>, but the function expects a object<Risan\OAuth1\Request\strin>.

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...
65
            'headers' => [
66 1
                'Authorization' => $this->authorizationHeader->forTemporaryCredentials(),
67
            ],
68
        ]);
69
    }
70
71
    /**
72
     * {@inheritDoc}
73
     */
74 1
    public function buildAuthorizationUri(TemporaryCredentials $temporaryCredentials)
75
    {
76 1
        return $this->uriParser->appendQueryParameters(
77 1
            $this->getConfig()->getAuthorizationUri(),
78 1
            ['oauth_token' => $temporaryCredentials->getIdentifier()]
79
        );
80
    }
81
82
    /**
83
     * {@inheritDoc}
84
     */
85 1
    public function createForTokenCredentials(TemporaryCredentials $temporaryCredentials, $verificationCode)
86
    {
87 1
        return $this->create('POST', $this->getConfig()->getTokenCredentialsUri(), [
0 ignored issues
show
Documentation introduced by
$this->getConfig()->getTokenCredentialsUri() is of type object<Psr\Http\Message\UriInterface>, but the function expects a object<Risan\OAuth1\Request\strin>.

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...
88
            'headers' => [
89 1
                'Authorization' => $this->authorizationHeader->forTokenCredentials($temporaryCredentials, $verificationCode),
90
            ],
91
            'form_params' => [
92 1
                'oauth_verifier' => $verificationCode,
93
            ],
94
        ]);
95
    }
96
97
    /**
98
     * Create a new instance of Request class.
99
     *
100
     * @param  string $method
101
     * @param  strin $uri
102
     * @param  array  $options [description]
103
     * @return \Risan\OAuth1\Request\RequestInterface
104
     */
105
    public function create($method, $uri, array $options = [])
106
    {
107
        return new Request($method, $uri, $options);
108
    }
109
}
110