GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

CurlTransport::call()   B
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 30
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 30
rs 8.8571
c 0
b 0
f 0
cc 3
eloc 18
nc 2
nop 1
1
<?php
2
3
namespace Lexik\Bundle\PayboxBundle\Transport;
4
5
use Lexik\Bundle\PayboxBundle\Paybox\RequestInterface;
6
7
/**
8
 * Class CurlTransport
9
 *
10
 * @package Lexik\Bundle\PayboxBundle\Transport
11
 *
12
 * @author Fabien Pomerol <[email protected]>
13
 */
14
class CurlTransport extends AbstractTransport
15
{
16
    /**
17
     * Constructor
18
     *
19
     * @param  string $url to paybox endpoint
20
     *
21
     * @throws \RuntimeException If cURL is not available
22
     */
23
    public function __construct($url = '')
24
    {
25
        if (!function_exists('curl_init')) {
26
            throw new \RuntimeException('cURL is not available. Activate it first.');
27
        }
28
29
        parent::__construct($url);
30
    }
31
32
    /**
33
     * {@inheritDoc}
34
     *
35
     * @param RequestInterface $request Request instance
36
     *
37
     * @throws \RuntimeException On cURL error
38
     *
39
     * @return string $response The html of the temporary form
40
     */
41
    public function call(RequestInterface $request)
42
    {
43
        $this->checkEndpoint();
44
45
        $ch = curl_init();
46
47
        // cURL options
48
        $options = array(
49
            CURLOPT_URL            => $this->getEndpoint(),
50
            CURLOPT_HEADER         => false,
51
            CURLOPT_RETURNTRANSFER => true,
52
            CURLOPT_POST           => true,
53
            CURLOPT_POSTFIELDS     => http_build_query($request->getParameters()),
54
        );
55
        curl_setopt_array($ch, $options);
56
57
        $response = curl_exec($ch);
58
59
        $curlErrorNumber = curl_errno($ch);
60
        $curlErrorMessage = curl_error($ch);
61
        $responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
62
63
        if ($curlErrorNumber > 0 || !in_array($responseCode, array(0, 200, 201, 204))) {
64
            throw new \RuntimeException('cUrl returns some errors (cURL errno '.$curlErrorNumber.'): '.$curlErrorMessage.' (HTTP Code: '.$responseCode.')');
65
        }
66
67
        curl_close($ch);
68
69
        return $response;
70
    }
71
}
72