Skip to content

Commit

Permalink
refactor(http-client): Refactor HasHttpClient trait
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
guanguans committed Jan 24, 2024
1 parent 6ff05b6 commit 545d221
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions src/Foundation/Traits/HasHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,21 @@

namespace Guanguans\Notify\Foundation\Traits;

use Guanguans\Notify\Http\Client;
use GuzzleHttp\Client;

trait HasHttpClient
{
/**
* @var Client
*/
protected $httpClient;
protected ?Client $httpClient;

protected $httpOptions = [];
protected array $httpOptions = [];

public function setHttpOptions(array $httpOptions)
public function setHttpOptions(array $httpOptions): self
{
$this->httpOptions = array_merge($this->httpOptions, $httpOptions);

return $this;
}

/**
* @return mixed[]
*/
public function getHttpOptions(): array
{
return $this->httpOptions;
Expand All @@ -43,7 +37,7 @@ public function getHttpClient(array $config = []): Client
$config && $this->setHttpOptions($config);

if ($config || ! $this->httpClient instanceof Client) {
$this->httpClient = Client::create($this->httpOptions);
$this->httpClient = new Client($this->httpOptions);
}

return $this->httpClient;
Expand Down

0 comments on commit 545d221

Please sign in to comment.