Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor Client and Guzzle refactoring #368

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/classes/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Class for sending requests to a Ntfy server.

```PHP
Ntfy\Client(Server $server, ?Auth $auth = null)
Ntfy\Client(Server $server, User|Token $auth = null)
```

### Examples
Expand Down
7 changes: 4 additions & 3 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
namespace Ntfy;

use stdClass;
use Ntfy\Auth\AbstractAuth;
use Ntfy\Auth\User;
use Ntfy\Auth\Token;
use Ntfy\Exception\NtfyException;

class Client
Expand All @@ -13,9 +14,9 @@ class Client

/**
* @param Server $server Server URI
* @param ?AbstractAuth $auth Authentication class instance
* @param User|Token $auth Authentication class instance
*/
public function __construct(Server $server, ?AbstractAuth $auth = null)
public function __construct(Server $server, User|Token $auth = null)
{
$this->guzzle = new Guzzle(
$server->get(),
Expand Down
15 changes: 8 additions & 7 deletions src/Guzzle.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

namespace Ntfy;

use Ntfy\Auth\AbstractAuth;
use Ntfy\Auth\User;
use Ntfy\Auth\Token;
use GuzzleHttp\Client;
use GuzzleHttp\RequestOptions;
use GuzzleHttp\HandlerStack;
Expand All @@ -28,10 +29,10 @@ class Guzzle
/**
*
* @param string $uri Server URI
* @param ?AbstractAuth $auth Authentication class instance
* @param User|Token $auth Authentication class instance
* @param ?HandlerStack $handlerStack Guzzle handler stack
*/
public function __construct(string $uri, ?AbstractAuth $auth, ?HandlerStack $handlerStack = null)
public function __construct(string $uri, User|Token $auth = null, ?HandlerStack $handlerStack = null)
{
$config = $this->getConfig($uri, $auth, $handlerStack);
$this->client = new Client($config);
Expand Down Expand Up @@ -122,11 +123,11 @@ protected function request(string $method, string $endpoint, array $options = []
* Get GuzzleHttp client config
*
* @param string $uri Server URI
* @param ?AbstractAuth $auth Authentication class instance
* @param User|Token $auth Authentication class instance
* @param ?HandlerStack $handlerStack Guzzle handler stack
* @return array<string, mixed> Returns client config array
*/
private function getConfig(string $uri, ?AbstractAuth $auth, ?HandlerStack $handlerStack): array
private function getConfig(string $uri, User|Token $auth = null, ?HandlerStack $handlerStack = null): array
{
$config = [
'base_uri' => $uri,
Expand All @@ -150,10 +151,10 @@ private function getConfig(string $uri, ?AbstractAuth $auth, ?HandlerStack $hand
/**
* Get authentication config
*
* @param ?AbstractAuth $auth Authentication class instance
* @param User|Token $auth Authentication class instance
* @return array<string, array<int|string, string>>
*/
private function getAuthConfig(?AbstractAuth $auth): array
private function getAuthConfig(User|Token|null $auth): array
{
$config = [];

Expand Down