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.
Completed
Push — master ( b592f6...d63ed1 )
by Rob
03:19
created

Curl::_decode()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 1
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace RattfieldNz\SafeUrls\Libraries\Curl;
4
5
use Curl\Curl as PhpCurl;
6
use RattfieldNz\SafeUrls\Libraries\Config\Config;
7
8
/**
9
 * Class Curl.
10
 *
11
 * @category PHP
12
 *
13
 * @author  Rob Attfield <[email protected]>
14
 * @license https://github.com/rattfieldnz/safe-urls/blob/master/license.md MIT
15
 *
16
 * @link https://github.com/rattfieldnz/safe-urls/
17
 */
18
class Curl
19
{
20
    private $_postUrl;
21
    private $_payload;
22
    private $_defaultHeaders;
23
    private $_timeout;
24
    private $_curl;
25
26
    /**
27
     * Curl constructor.
28
     *
29
     * Set the needed properties to do a CURL request.
30
     *
31
     * @param string $postUrl URL to use for request.
32
     * @param array  $payload Data to be submitted with CURL request.
33
     * @param int    $timeout Timeout in seconds to complete a CURL request. Default is 10.
34
     *
35
     * @throws \ErrorException
36
     */
37
    public function __construct(string $postUrl, array $payload, int $timeout = 10)
38
    {
39
        $this->_curl = new PhpCurl();
40
        $this->_postUrl = $postUrl;
41
        $this->_payload = $payload;
42
        $this->_timeout = $timeout;
43
        self::_setDefaultHeaders();
0 ignored issues
show
Bug Best Practice introduced by
The method RattfieldNz\SafeUrls\Lib...l::_setDefaultHeaders() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

43
        self::/** @scrutinizer ignore-call */ 
44
              _setDefaultHeaders();
Loading history...
44
    }
45
46
    /**
47
     * Execute a CURL request, and return current object for further processing.
48
     *
49
     * @return PhpCurl
50
     */
51
    public function execute(): PhpCurl
52
    {
53
        $this->_curl->setOpt(CURLOPT_RETURNTRANSFER, true);
54
        $this->_curl->setOpt(CURLOPT_CONNECTTIMEOUT, $this->_timeout);
55
        $this->_curl->setOpt(CURLOPT_HTTPHEADER, $this->_defaultHeaders);
56
        $this->_curl->setOpt(CURLOPT_POSTFIELDS, json_encode($this->_payload));
57
        $this->_curl->post($this->_postUrl);
58
        return $this->_curl;
59
    }
60
61
    /**
62
     * Get the data retrieved from executing CURL request.
63
     *
64
     * @return array|string
65
     * @see    \RattfieldNz\SafeUrls\Libraries\Curl\Curl->execute().
66
     */
67
    public function getData()
68
    {
69
        $dataObject = $this->execute();
70
        $data = [
71
            'status' => $dataObject->getHttpStatus(),
72
            'response' => json_decode($dataObject->response, true)
73
        ];
74
75
        return json_encode($data);
76
    }
77
78
    /**
79
     * Sets the default headers to use for CURL request.
80
     *
81
     * @return void
82
     */
83
    private function _setDefaultHeaders(): void
84
    {
85
        $this->_defaultHeaders = [
86
            'Content-Type: application/json',
87
            'Connection: Keep-Alive',
88
        ];
89
    }
90
}
91