Skip to content

Commit bd739dd

Browse files
authored
Merge pull request #536 from thelovekesh/fix/phpstan-errors
Fix PHPStan errors
2 parents 325bc7b + e00195e commit bd739dd

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/RemoteRequest/CurlRemoteGetRequest.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use AmpProject\Exception\FailedToGetFromRemoteUrl;
77
use AmpProject\RemoteGetRequest;
88
use AmpProject\Response;
9+
use AmpProject\Exception\FailedToParseUrl;
910

1011
/**
1112
* Remote request transport using cURL.
@@ -97,13 +98,18 @@ public function __construct($sslVerify = true, $timeout = self::DEFAULT_TIMEOUT,
9798
public function get($url, $headers = [])
9899
{
99100
$retriesLeft = $this->retries;
101+
102+
if (! is_string($url) || empty($url)) {
103+
throw FailedToGetFromRemoteUrl::withException($url, FailedToParseUrl::forUrl($url));
104+
}
105+
100106
do {
101107
$curlHandle = curl_init();
102108

103109
curl_setopt($curlHandle, CURLOPT_URL, $url);
104-
curl_setopt($curlHandle, CURLOPT_HEADER, 0);
110+
curl_setopt($curlHandle, CURLOPT_HEADER, false);
105111
curl_setopt($curlHandle, CURLOPT_FOLLOWLOCATION, true);
106-
curl_setopt($curlHandle, CURLOPT_SSL_VERIFYPEER, $this->sslVerify ? 1 : 0);
112+
curl_setopt($curlHandle, CURLOPT_SSL_VERIFYPEER, $this->sslVerify);
107113
curl_setopt($curlHandle, CURLOPT_SSL_VERIFYHOST, $this->sslVerify ? 2 : 0);
108114
curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);
109115
curl_setopt($curlHandle, CURLOPT_FAILONERROR, true);

tests/RemoteRequest/CurlRemoteGetRequestTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace AmpProject\RemoteRequest;
44

55
use AmpProject\RemoteGetRequest;
6+
use AmpProject\Exception\FailedToGetFromRemoteUrl;
67
use AmpProject\Tests\TestCase;
78

89
/**
@@ -19,4 +20,20 @@ public function testInstantiation()
1920
$this->assertInstanceOf(RemoteGetRequest::class, $curlRequest);
2021
$this->assertInstanceOf(CurlRemoteGetRequest::class, $curlRequest);
2122
}
23+
24+
/**
25+
* @covers ::get()
26+
*/
27+
public function testGet()
28+
{
29+
$curlRequest = new CurlRemoteGetRequest(false);
30+
31+
// When passed url is not string, it should throw exception.
32+
$this->expectException(FailedToGetFromRemoteUrl::class);
33+
$curlRequest->get(123);
34+
35+
// When passed url is empty string, it should throw exception.
36+
$this->expectException(FailedToGetFromRemoteUrl::class);
37+
$curlRequest->get('');
38+
}
2239
}

0 commit comments

Comments
 (0)