Skip to content

Commit

Permalink
Rename abstract classes and use union types (#399)
Browse files Browse the repository at this point in the history
  • Loading branch information
VerifiedJoseph authored Aug 1, 2024
1 parent 49940d6 commit 62f2bcb
Show file tree
Hide file tree
Showing 24 changed files with 57 additions and 58 deletions.
12 changes: 6 additions & 6 deletions docs/endpoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Jump to:
## Application

```PHP
Gotify\Endpoint\Application(Server $server, ?Auth $auth)
Gotify\Endpoint\Application(Server $server, Auth\User|Auth\Token $auth)
```

Class: [Application](../src/Endpoint/Application.php)
Expand Down Expand Up @@ -60,7 +60,7 @@ uploadImage(int $id, string $image): stdClass
## ApplicationMessage

```PHP
Gotify\Endpoint\ApplicationMessage(Server $server, ?Auth $auth)
Gotify\Endpoint\ApplicationMessage(Server $server, Auth\User|Auth\Token $auth)
```

Class: [ApplicationMessage](../src/Endpoint/ApplicationMessage.php)
Expand All @@ -84,7 +84,7 @@ deleteAll(int $id): boolean
## Message

```PHP
Gotify\Endpoint\Message(Server $server, ?Auth $auth)
Gotify\Endpoint\Message(Server $server, Auth\User|Auth\Token $auth)
```

Class: [Message](../src/Endpoint/Message.php)
Expand Down Expand Up @@ -151,7 +151,7 @@ deleteAll(): boolean
## Client

```PHP
Gotify\Endpoint\Client(Server $server, ?Auth $auth)
Gotify\Endpoint\Client(Server $server, Auth\User|Auth\Token $auth)
```

Class: [Client](../src/Endpoint/Client.php)
Expand Down Expand Up @@ -191,7 +191,7 @@ delete(int $id): boolean
## User

```PHP
Gotify\Endpoint\User(Server $server, ?Auth $auth)
Gotify\Endpoint\User(Server $server, Auth\User|Auth\Token $auth)
```

Class: [User](../src/Endpoint/User.php)
Expand Down Expand Up @@ -266,7 +266,7 @@ get(): stdClass
## Plugin

```PHP
Gotify\Endpoint\Plugin(Server $server, ?Auth $auth)
Gotify\Endpoint\Plugin(Server $server, Auth\User|Auth\Token $auth)
```

Class: [Plugin](../src/Endpoint/Plugin.php)
Expand Down
4 changes: 2 additions & 2 deletions src/Auth.php → src/Auth/AbstractAuth.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

namespace Gotify;
namespace Gotify\Auth;

/**
* Class for setting and validating authentication
*/
abstract class Auth
abstract class AbstractAuth
{
/** @var string $method Authentication method */
protected string $method = '';
Expand Down
4 changes: 1 addition & 3 deletions src/Auth/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

namespace Gotify\Auth;

use Gotify\Auth;

/**
* Class for setting and validating an authentication token
*/
class Token extends Auth
class Token extends AbstractAuth
{
/** @var string $method Authentication method */
protected string $method = 'token';
Expand Down
4 changes: 1 addition & 3 deletions src/Auth/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

namespace Gotify\Auth;

use Gotify\Auth;

/**
* Class for setting and validating username and password authentication
*/
class User extends Auth
class User extends AbstractAuth
{
/** @var string $method Authentication method */
protected string $method = 'user';
Expand Down
12 changes: 6 additions & 6 deletions src/Api.php → src/Endpoint/AbstractEndpoint.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
<?php

namespace Gotify;
namespace Gotify\Endpoint;

use Gotify\Server;
use Gotify\Guzzle;
use Gotify\Auth\User;
use Gotify\Auth\Token;

/**
* Class for interacting with the Gotify API using Guzzle
*/
abstract class Api
abstract class AbstractEndpoint
{
/** @var Guzzle $guzzle Guzzle class instance */
protected Guzzle $guzzle;

/**
* Create Guzzle instance
*
* @param Server $server Server URI
* @param ?Auth $auth Authentication
* @param null|User|Token $auth Authentication class instance
*/
final public function __construct(Server $server, ?Auth $auth = null)
final public function __construct(Server $server, null|User|Token $auth = null)
{
$this->guzzle = new Guzzle($server->get(), $auth);
}
Expand Down
3 changes: 1 addition & 2 deletions src/Endpoint/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Gotify\Endpoint;

use Gotify\Api;
use Gotify\Json;
use stdClass;

Expand All @@ -11,7 +10,7 @@
*
* @see https://gotify.net/api-docs#/application API docs for message endpoint
*/
class Application extends Api
class Application extends AbstractEndpoint
{
/** @var string $endpoint API endpoint */
private string $endpoint = 'application';
Expand Down
3 changes: 1 addition & 2 deletions src/Endpoint/ApplicationMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Gotify\Endpoint;

use Gotify\Api;
use Gotify\Json;
use stdClass;

Expand All @@ -11,7 +10,7 @@
*
* @see https://gotify.net/api-docs#/message API docs for message endpoint
*/
class ApplicationMessage extends Api
class ApplicationMessage extends AbstractEndpoint
{
/** @var string $endpoint API endpoint */
private string $endpoint = 'application';
Expand Down
3 changes: 1 addition & 2 deletions src/Endpoint/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Gotify\Endpoint;

use Gotify\Api;
use Gotify\Json;
use stdClass;

Expand All @@ -11,7 +10,7 @@
*
* @see https://gotify.net/api-docs#/client API docs for client endpoint
*/
class Client extends Api
class Client extends AbstractEndpoint
{
/** @var string $endpoint API endpoint */
private string $endpoint = 'client';
Expand Down
3 changes: 1 addition & 2 deletions src/Endpoint/Health.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Gotify\Endpoint;

use Gotify\Api;
use Gotify\Json;
use stdClass;

Expand All @@ -11,7 +10,7 @@
*
* @see https://gotify.net/api-docs#/health API docs for the health endpoint
*/
class Health extends Api
class Health extends AbstractEndpoint
{
/** @var string $endpoint API endpoint */
private string $endpoint = 'health';
Expand Down
3 changes: 1 addition & 2 deletions src/Endpoint/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Gotify\Endpoint;

use Gotify\Api;
use Gotify\Json;
use stdClass;

Expand All @@ -11,7 +10,7 @@
*
* @see https://gotify.net/api-docs#/message API docs for message endpoint
*/
class Message extends Api
class Message extends AbstractEndpoint
{
/**
* High message priority
Expand Down
3 changes: 1 addition & 2 deletions src/Endpoint/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Gotify\Endpoint;

use Gotify\Api;
use Gotify\Json;
use stdClass;

Expand All @@ -11,7 +10,7 @@
*
* @see https://gotify.net/api-docs#/plugin API docs for the user endpoint
*/
class Plugin extends Api
class Plugin extends AbstractEndpoint
{
/** @var string $endpoint API endpoint */
private string $endpoint = 'plugin';
Expand Down
3 changes: 1 addition & 2 deletions src/Endpoint/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Gotify\Endpoint;

use Gotify\Api;
use Gotify\Json;
use stdClass;

Expand All @@ -11,7 +10,7 @@
*
* @see https://gotify.net/api-docs#/user API docs for the user endpoint
*/
class User extends Api
class User extends AbstractEndpoint
{
/** @var string $endpoint API endpoint */
private string $endpoint = 'user';
Expand Down
3 changes: 1 addition & 2 deletions src/Endpoint/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Gotify\Endpoint;

use Gotify\Api;
use Gotify\Json;
use stdClass;

Expand All @@ -11,7 +10,7 @@
*
* @see https://gotify.net/api-docs#/version API docs for the version endpoint
*/
class Version extends Api
class Version extends AbstractEndpoint
{
/** @var string $endpoint API endpoint */
private string $endpoint = 'version';
Expand Down
15 changes: 8 additions & 7 deletions src/Guzzle.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Gotify;

use Gotify\Auth\User;
use Gotify\Auth\Token;
use GuzzleHttp\Psr7;
use GuzzleHttp\Client;
use GuzzleHttp\RequestOptions;
Expand All @@ -26,12 +28,11 @@ class Guzzle
private int $timeout = 10;

/**
*
* @param string $uri Server URI
* @param Auth $auth Authentication
* @param null|User|Token $auth Authentication class instance
* @param ?HandlerStack $handlerStack Guzzle handler stack
*/
public function __construct(string $uri, ?Auth $auth, ?HandlerStack $handlerStack = null)
public function __construct(string $uri, null|User|Token $auth = null, ?HandlerStack $handlerStack = null)
{
$config = $this->getConfig($uri, $auth, $handlerStack);

Expand Down Expand Up @@ -185,11 +186,11 @@ protected function request(string $method, string $endpoint, array $options = []
*
* @param string $uri Server URI
* @param ?HandlerStack $handlerStack Guzzle handler stack
* @param ?Auth $auth Authentication
* @param User|Token $auth Authentication class instance
*
* @return array<string, mixed> Returns client config array
*/
private function getConfig(string $uri, ?Auth $auth, ?HandlerStack $handlerStack): array
private function getConfig(string $uri, null|User|Token $auth = null, ?HandlerStack $handlerStack): array
{
$config = [
'base_uri' => $uri,
Expand All @@ -213,11 +214,11 @@ private function getConfig(string $uri, ?Auth $auth, ?HandlerStack $handlerStack
/**
* Get authentication config
*
* @param ?Auth $auth Authentication
* @param User|Token $auth Authentication class instance
*
* @return array<string, array<int|string, string>>
*/
private function getAuthConfig(?Auth $auth): array
private function getAuthConfig(null|User|Token $auth = null): array
{
$config = [];

Expand Down
3 changes: 2 additions & 1 deletion tests/Auth/TokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
use PHPUnit\Framework\Attributes\CoversClass;
use Tests\AbstractTestCase;
use Gotify\Auth\Token;
use Gotify\Auth\AbstractAuth;

#[CoversClass(Token::class)]
#[CoversClass(\Gotify\Auth::class)]
#[CoversClass(AbstractAuth::class)]
class TokenTest extends AbstractTestCase
{
protected string $method = 'token';
Expand Down
3 changes: 2 additions & 1 deletion tests/Auth/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
use PHPUnit\Framework\Attributes\CoversClass;
use Tests\AbstractTestCase;
use Gotify\Auth\User;
use Gotify\Auth\AbstractAuth;

#[CoversClass(User::class)]
#[CoversClass(\Gotify\Auth::class)]
#[CoversClass(AbstractAuth::class)]
class UserTest extends AbstractTestCase
{
private string $method = 'user';
Expand Down
5 changes: 3 additions & 2 deletions tests/Endpoints/ApplicationMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@
use Tests\AbstractTestCase;
use Gotify\Endpoint\Application;
use Gotify\Endpoint\ApplicationMessage;
use Gotify\Endpoint\AbstractEndpoint;

#[CoversClass(ApplicationMessage::class)]
#[UsesClass(Application::class)]
#[UsesClass(\Gotify\Api::class)]
#[UsesClass(AbstractEndpoint::class)]
#[UsesClass(\Gotify\Guzzle::class)]
#[UsesClass(\Gotify\Json::class)]
#[UsesClass(\Gotify\Server::class)]
#[UsesClass(\Gotify\Auth::class)]
#[UsesClass(\Gotify\Auth\User::class)]
#[UsesClass(\Gotify\Auth\AbstractAuth::class)]
class ApplicationMessageTest extends AbstractTestCase
{
private static ApplicationMessage $applicationMessage;
Expand Down
5 changes: 3 additions & 2 deletions tests/Endpoints/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
use PHPUnit\Framework\Attributes\Depends;
use Tests\AbstractTestCase;
use Gotify\Endpoint\Application;
use Gotify\Endpoint\AbstractEndpoint;

#[CoversClass(Application::class)]
#[UsesClass(\Gotify\Api::class)]
#[UsesClass(AbstractEndpoint::class)]
#[UsesClass(\Gotify\Guzzle::class)]
#[UsesClass(\Gotify\Json::class)]
#[UsesClass(\Gotify\Server::class)]
#[UsesClass(\Gotify\Auth::class)]
#[UsesClass(\Gotify\Auth\User::class)]
#[UsesClass(\Gotify\Auth\AbstractAuth::class)]
class ApplicationTest extends AbstractTestCase
{
private static Application $application;
Expand Down
5 changes: 3 additions & 2 deletions tests/Endpoints/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
use PHPUnit\Framework\Attributes\Depends;
use Tests\AbstractTestCase;
use Gotify\Endpoint\Client;
use Gotify\Endpoint\AbstractEndpoint;

#[CoversClass(Client::class)]
#[UsesClass(\Gotify\Api::class)]
#[UsesClass(AbstractEndpoint::class)]
#[UsesClass(\Gotify\Guzzle::class)]
#[UsesClass(\Gotify\Json::class)]
#[UsesClass(\Gotify\Server::class)]
#[UsesClass(\Gotify\Auth::class)]
#[UsesClass(\Gotify\Auth\User::class)]
#[UsesClass(\Gotify\Auth\AbstractAuth::class)]
class ClientTest extends AbstractTestCase
{
private static Client $client;
Expand Down
Loading

0 comments on commit 62f2bcb

Please sign in to comment.