Passed
Push — master ( 653599...c050da )
by Stephen
47s queued 12s
created

CurlRequestAction::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Sfneal\GooglePlaces\Actions;
4
5
use Sfneal\Actions\Action;
6
7
class CurlRequestAction extends Action
8
{
9
    /**
10
     * @var string
11
     */
12
    private $endpoint;
13
14
    /**
15
     * CurlRequestAction constructor.
16
     *
17
     * @param string $endpoint
18
     */
19
    public function __construct(string $endpoint)
20
    {
21
        $this->endpoint = $endpoint;
22
    }
23
24
    /**
25
     * Execute the cURL request and JSON decode the result.
26
     *
27
     * @return mixed
28
     */
29
    public function execute()
30
    {
31
        $ch = curl_init();
32
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
33
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
34
        curl_setopt($ch, CURLOPT_URL, $this->endpoint);
35
        $result = curl_exec($ch);
36
        curl_close($ch);
37
38
        return json_decode($result, true);
0 ignored issues
show
Bug introduced by
It seems like $result can also be of type true; however, parameter $json of json_decode() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

38
        return json_decode(/** @scrutinizer ignore-type */ $result, true);
Loading history...
39
    }
40
}
41