Skip to content

Commit 545d221

Browse files
committed
refactor(http-client): Refactor HasHttpClient trait
- Update namespace for GuzzleHttp\Client - Change type declaration for httpClient property - Change type declaration for httpOptions property - Change return type for setHttpOptions method - Change return type for getHttpOptions method - Refactor instantiation of httpClient in setHttpClient method
1 parent 6ff05b6 commit 545d221

1 file changed

Lines changed: 5 additions & 11 deletions

File tree

src/Foundation/Traits/HasHttpClient.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,21 @@
1212

1313
namespace Guanguans\Notify\Foundation\Traits;
1414

15-
use Guanguans\Notify\Http\Client;
15+
use GuzzleHttp\Client;
1616

1717
trait HasHttpClient
1818
{
19-
/**
20-
* @var Client
21-
*/
22-
protected $httpClient;
19+
protected ?Client $httpClient;
2320

24-
protected $httpOptions = [];
21+
protected array $httpOptions = [];
2522

26-
public function setHttpOptions(array $httpOptions)
23+
public function setHttpOptions(array $httpOptions): self
2724
{
2825
$this->httpOptions = array_merge($this->httpOptions, $httpOptions);
2926

3027
return $this;
3128
}
3229

33-
/**
34-
* @return mixed[]
35-
*/
3630
public function getHttpOptions(): array
3731
{
3832
return $this->httpOptions;
@@ -43,7 +37,7 @@ public function getHttpClient(array $config = []): Client
4337
$config && $this->setHttpOptions($config);
4438

4539
if ($config || ! $this->httpClient instanceof Client) {
46-
$this->httpClient = Client::create($this->httpOptions);
40+
$this->httpClient = new Client($this->httpOptions);
4741
}
4842

4943
return $this->httpClient;

0 commit comments

Comments
 (0)