Completed
Push — develop ( becfea...d327ce )
by Serhii
02:33
created

BaseOAuthProvider   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 2
Bugs 0 Features 2
Metric Value
wmc 8
lcom 1
cbo 4
dl 0
loc 74
rs 10
c 2
b 0
f 2

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setCredentials() 0 4 1
A doRequest() 0 16 3
A normalizeUrl() 0 9 3
1
<?php
2
3
namespace Sleepness\UberOAuthRestBundle\Provider;
4
5
use Sleepness\UberOAuthRestBundle\Exception\BadRequestException;
6
use GuzzleHttp\Client;
7
use GuzzleHttp\Exception\ClientException;
8
9
abstract class BaseOAuthProvider implements OAuthProviderInterface
10
{
11
    const GET = 'GET';
12
    const POST = 'POST';
13
14
    /**
15
     * @var Client
16
     */
17
    protected $client;
18
19
    /**
20
     * @var array
21
     */
22
    protected $credentials;
23
24
    /**
25
     * BaseOAuthProvider constructor.
26
     *
27
     * @param $client
28
     */
29
    public function __construct($client)
30
    {
31
        $this->client = $client;
32
    }
33
34
    /**
35
     * @param array $credentials
36
     */
37
    public function setCredentials(array $credentials)
38
    {
39
        $this->credentials = $credentials;
40
    }
41
42
    /**
43
     * @param $url
44
     * @param null $content
0 ignored issues
show
Bug introduced by
There is no parameter named $content. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
45
     * @param $headers
46
     * @param $method
47
     *
48
     * @return mixed|\Psr\Http\Message\ResponseInterface
49
     */
50
    protected function doRequest($url, $method, array $options = [])
51
    {
52
        try {
53
            $response = $this->client->request(
54
                strtoupper($method),
55
                $url,
56
                $options
57
            );
58
        } catch (ClientException $e) {
59
            if ($e->hasResponse()) {
60
                throw new BadRequestException('Error while sending request', $this->credentials['provider_name'], $e->getCode(), $e);
61
            }
62
        }
63
64
        return json_decode($response->getBody()->getContents());
65
    }
66
67
    /**
68
     * @param $url
69
     * @param array $parameters
70
     *
71
     * @return string
72
     */
73
    protected function normalizeUrl($url, array $parameters = array())
74
    {
75
        $normalizedUrl = $url;
76
        if (!empty($parameters)) {
77
            $normalizedUrl .= (false !== strpos($url, '?') ? '&' : '?').http_build_query($parameters, '', '&');
78
        }
79
80
        return $normalizedUrl;
81
    }
82
}
83