Skip to content

Commit 2836175

Browse files
committed
update fix some error
1 parent 94bf29c commit 2836175

File tree

7 files changed

+69
-19
lines changed

7 files changed

+69
-19
lines changed

src/AbstractClient.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,6 @@ public function sendRequest(RequestInterface $request): ResponseInterface
330330
* @param string $saveAs
331331
*
332332
* @return bool
333-
* @throws Exception
334333
*/
335334
public function download(string $url, string $saveAs): bool
336335
{
@@ -393,7 +392,7 @@ public function SSLVerify(bool $enable)
393392
*
394393
* @return $this
395394
*/
396-
public function setCookie(string $key, $value)
395+
public function setCookie(string $key, $value): ClientInterface
397396
{
398397
$this->cookies[$key] = $value;
399398
return $this;
@@ -676,7 +675,7 @@ public function getPsr7Response(): ResponseInterface
676675
*
677676
* @return $this
678677
*/
679-
protected function resetOptions()
678+
protected function resetOptions(): ClientInterface
680679
{
681680
$this->options = $this->defaultOptions;
682681
return $this;

src/Curl/CurlClient.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use PhpComp\Http\Client\ClientUtil;
1616
use PhpComp\Http\Client\Exception\ClientException;
1717
use PhpComp\Http\Client\Traits\ParseRawResponseTrait;
18+
use function array_merge;
1819
use function curl_close;
1920
use function curl_errno;
2021
use function curl_error;
@@ -109,9 +110,9 @@ class CurlClient extends AbstractClient implements CurlClientInterface
109110
use ParseRawResponseTrait;
110111

111112
// ssl auth type
112-
const SSL_TYPE_CERT = 'cert';
113+
public const SSL_TYPE_CERT = 'cert';
113114

114-
const SSL_TYPE_KEY = 'key';
115+
public const SSL_TYPE_KEY = 'key';
115116

116117
/**
117118
* Can to retry request
@@ -306,7 +307,7 @@ public function downloadImage(string $imgUrl, string $saveDir, string $rename =
306307
*
307308
* @return $this
308309
*/
309-
public function request(string $url, $data = null, string $method = 'GET', array $headers = [], array $options = [])
310+
public function request(string $url, $data = null, string $method = 'GET', array $headers = [], array $options = []): ClientInterface
310311
{
311312
if ($method = strtoupper($method)) {
312313
$options['method'] = $method;
@@ -381,7 +382,7 @@ protected function prepareRequest(string $url, $data, array $headers, array $opt
381382
}
382383

383384
// merge global options.
384-
$options = \array_merge($this->options, $options);
385+
$options = array_merge($this->options, $options);
385386
$method = $this->formatAndCheckMethod($options['method']);
386387

387388
switch ($method) {
@@ -426,12 +427,12 @@ protected function prepareRequest(string $url, $data, array $headers, array $opt
426427
$curlOptions[CURLOPT_URL] = ClientUtil::encodeURL($url);
427428

428429
// append http headers
429-
if ($headers = \array_merge($this->headers, $options['headers'], $headers)) {
430+
if ($headers = array_merge($this->headers, $options['headers'], $headers)) {
430431
$curlOptions[CURLOPT_HTTPHEADER] = $this->formatHeaders($headers);
431432
}
432433

433434
// append http cookies
434-
if ($cookies = \array_merge($this->cookies, $options['cookies'])) {
435+
if ($cookies = array_merge($this->cookies, $options['cookies'])) {
435436
$curlOptions[CURLOPT_COOKIE] = http_build_query($cookies, '', '; ');
436437
}
437438

@@ -480,7 +481,7 @@ public function getTotalTime(): int
480481
/**
481482
* @return $this
482483
*/
483-
public function resetOptions()
484+
public function resetOptions(): ClientInterface
484485
{
485486
// $this->_curlOptions = [];
486487

@@ -491,7 +492,7 @@ public function resetOptions()
491492
/**
492493
* @return $this
493494
*/
494-
public function resetResponse()
495+
public function resetResponse(): ClientInterface
495496
{
496497
$this->rawResponse = '';
497498
$this->responseParsed = false;
@@ -535,7 +536,7 @@ public function setReferrer(string $referrer): self
535536
*
536537
* @return $this
537538
*/
538-
public function setUserAuth(string $user, string $pwd = '', int $authType = CURLAUTH_BASIC)
539+
public function setUserAuth(string $user, string $pwd = '', int $authType = CURLAUTH_BASIC): ClientInterface
539540
{
540541
$this->_curlOptions[CURLOPT_HTTPAUTH] = $authType;
541542
$this->_curlOptions[CURLOPT_USERPWD] = "$user:$pwd";
@@ -551,7 +552,7 @@ public function setUserAuth(string $user, string $pwd = '', int $authType = CURL
551552
*
552553
* @return $this
553554
*/
554-
public function setSSLAuth(string $pwd, string $file, string $authType = self::SSL_TYPE_CERT)
555+
public function setSSLAuth(string $pwd, string $file, string $authType = self::SSL_TYPE_CERT): ClientInterface
555556
{
556557
if ($authType !== self::SSL_TYPE_CERT && $authType !== self::SSL_TYPE_KEY) {
557558
throw new InvalidArgumentException('The SSL auth type only allow: cert|key');

src/Curl/CurlClientInterface.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ interface CurlClientInterface
2020
* Set curl options
2121
*
2222
* @param array $options
23-
*
24-
* @return $this
2523
*/
2624
public function setCurlOptions(array $options);
2725

src/Curl/CurlMulti.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,12 @@ class CurlMulti // extends CurlLite
102102
*/
103103
private $options;
104104

105-
public static function create(array $options = [])
105+
/**
106+
* @param array $options
107+
*
108+
* @return CurlMulti
109+
*/
110+
public static function create(array $options = []): CurlMulti
106111
{
107112
return new static($options);
108113
}
@@ -124,7 +129,7 @@ public function __construct(array $options = [])
124129
*
125130
* @return self
126131
*/
127-
public function build(array $data)
132+
public function build(array $data): self
128133
{
129134
$this->mh = curl_multi_init();
130135

@@ -314,7 +319,7 @@ public function createResource($url, $data = null, array $headers = [], array $o
314319
*
315320
* @return string
316321
*/
317-
protected function buildUrl(string $url, $data = null)
322+
protected function buildUrl(string $url, $data = null): string
318323
{
319324
$url = trim($url);
320325

src/Middleware/DemoMiddleware.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace PhpComp\Http\Client\Middleware;
4+
5+
use Psr\Http\Message\RequestInterface;
6+
use Psr\Http\Message\ResponseInterface;
7+
8+
/**
9+
* Class DemoMiddleware
10+
*
11+
* @package PhpComp\Http\Client\Middleware
12+
*/
13+
class DemoMiddleware implements MiddlewareInterface
14+
{
15+
/**
16+
* @param RequestInterface $request
17+
* @param \Closure $next
18+
*
19+
* @return ResponseInterface
20+
*/
21+
public function request(RequestInterface $request, \Closure $next): ResponseInterface
22+
{
23+
return $next($request);
24+
}
25+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace PhpComp\Http\Client\Middleware;
4+
5+
use Closure;
6+
use Psr\Http\Message\RequestInterface;
7+
use Psr\Http\Message\ResponseInterface;
8+
9+
/**
10+
* Interface MiddlewareInterface
11+
*
12+
* @package PhpComp\Http\Client\Middleware
13+
*/
14+
interface MiddlewareInterface
15+
{
16+
/**
17+
* @param RequestInterface $request
18+
* @param Closure $next
19+
*
20+
* @return ResponseInterface
21+
*/
22+
public function request(RequestInterface $request, Closure $next): ResponseInterface;
23+
}

src/Swoole/CoClient.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ public static function isAvailable(): bool
5353
* @param string $saveAs
5454
*
5555
* @return bool
56-
* @throws Exception
5756
*/
5857
public function download(string $url, string $saveAs): bool
5958
{

0 commit comments

Comments
 (0)