Skip to content

Commit

Permalink
Define exceptions for request types
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnyphp committed Nov 28, 2023
1 parent d28f1d8 commit ee60f7b
Show file tree
Hide file tree
Showing 15 changed files with 91 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/Contract/Request/RequestInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@

interface RequestInterface
{
/**
* Returns class FQDN for exceptions
* @return class-string
*/
public function getExceptionClass(): string;

/**
* Returns required configuration bitmask
* @return int
Expand Down
6 changes: 6 additions & 0 deletions src/Request/Lock/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use SunnyPHP\TTLock\Contract\Request\Lock\DeleteInterface;
use SunnyPHP\TTLock\Contract\Request\Method;
use SunnyPHP\TTLock\Contract\Request\RequiredConfiguration;
use SunnyPHP\TTLock\Exception\LockException;
use SunnyPHP\TTLock\Helper\DateTime;

final class Delete implements DeleteInterface
Expand Down Expand Up @@ -46,6 +47,11 @@ public function getRequiredConfiguration(): int
return RequiredConfiguration::CLIENT_ID | RequiredConfiguration::ACCESS_TOKEN;
}

public function getExceptionClass(): string
{
return LockException::class;
}

public function getEndpointUrl(): string
{
return '/v3/lock/delete';
Expand Down
8 changes: 7 additions & 1 deletion src/Request/Lock/GetDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use SunnyPHP\TTLock\Contract\Request\Lock\GetDetailInterface;
use SunnyPHP\TTLock\Contract\Request\Method;
use SunnyPHP\TTLock\Contract\Request\RequiredConfiguration;
use SunnyPHP\TTLock\Exception\LockException;
use SunnyPHP\TTLock\Helper\DateTime;

final class GetDetail implements GetDetailInterface
Expand Down Expand Up @@ -41,6 +42,11 @@ public function getCurrentDateTime(): DateTimeImmutable
return $this->currentDateTime;
}

public function getExceptionClass(): string
{
return LockException::class;
}

public function getRequiredConfiguration(): int
{
return RequiredConfiguration::CLIENT_ID | RequiredConfiguration::ACCESS_TOKEN;
Expand All @@ -53,7 +59,7 @@ public function getEndpointUrl(): string

public function getEndpointMethod(): string
{
return Method::POST;
return Method::GET;
}

public function getRequestParams(): array
Expand Down
6 changes: 6 additions & 0 deletions src/Request/Lock/GetList.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use SunnyPHP\TTLock\Contract\Request\Lock\GetListInterface;
use SunnyPHP\TTLock\Contract\Request\Method;
use SunnyPHP\TTLock\Contract\Request\RequiredConfiguration;
use SunnyPHP\TTLock\Exception\LockException;
use SunnyPHP\TTLock\Helper\DateTime;
use Webmozart\Assert\Assert;

Expand Down Expand Up @@ -73,6 +74,11 @@ public function getCurrentDateTime(): DateTimeImmutable
return $this->currentDateTime;
}

public function getExceptionClass(): string
{
return LockException::class;
}

public function getRequiredConfiguration(): int
{
return RequiredConfiguration::CLIENT_ID | RequiredConfiguration::ACCESS_TOKEN;
Expand Down
6 changes: 6 additions & 0 deletions src/Request/Lock/Initialize.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use SunnyPHP\TTLock\Contract\Request\Lock\InitializeInterface;
use SunnyPHP\TTLock\Contract\Request\Method;
use SunnyPHP\TTLock\Contract\Request\RequiredConfiguration;
use SunnyPHP\TTLock\Exception\LockException;
use SunnyPHP\TTLock\Helper\DateTime;
use Webmozart\Assert\Assert;

Expand Down Expand Up @@ -72,6 +73,11 @@ public function getCurrentDateTime(): DateTimeImmutable
return $this->currentDateTime;
}

public function getExceptionClass(): string
{
return LockException::class;
}

public function getRequiredConfiguration(): int
{
return RequiredConfiguration::CLIENT_ID | RequiredConfiguration::ACCESS_TOKEN;
Expand Down
6 changes: 6 additions & 0 deletions src/Request/Lock/Rename.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use SunnyPHP\TTLock\Contract\Request\Lock\RenameInterface;
use SunnyPHP\TTLock\Contract\Request\Method;
use SunnyPHP\TTLock\Contract\Request\RequiredConfiguration;
use SunnyPHP\TTLock\Exception\LockException;
use SunnyPHP\TTLock\Helper\DateTime;
use Webmozart\Assert\Assert;

Expand Down Expand Up @@ -53,6 +54,11 @@ public function getCurrentDateTime(): DateTimeImmutable
return $this->currentDateTime;
}

public function getExceptionClass(): string
{
return LockException::class;
}

public function getRequiredConfiguration(): int
{
return RequiredConfiguration::CLIENT_ID | RequiredConfiguration::ACCESS_TOKEN;
Expand Down
6 changes: 6 additions & 0 deletions src/Request/Lock/Transfer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use SunnyPHP\TTLock\Contract\Request\Lock\TransferInterface;
use SunnyPHP\TTLock\Contract\Request\Method;
use SunnyPHP\TTLock\Contract\Request\RequiredConfiguration;
use SunnyPHP\TTLock\Exception\LockException;
use SunnyPHP\TTLock\Helper\DateTime;
use Webmozart\Assert\Assert;

Expand Down Expand Up @@ -55,6 +56,11 @@ public function getCurrentDateTime(): DateTimeImmutable
return $this->currentDateTime;
}

public function getExceptionClass(): string
{
return LockException::class;
}

public function getRequiredConfiguration(): int
{
return RequiredConfiguration::CLIENT_ID | RequiredConfiguration::ACCESS_TOKEN;
Expand Down
6 changes: 6 additions & 0 deletions src/Request/Lock/UpdateData.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use SunnyPHP\TTLock\Contract\Request\Lock\UpdateDataInterface;
use SunnyPHP\TTLock\Contract\Request\Method;
use SunnyPHP\TTLock\Contract\Request\RequiredConfiguration;
use SunnyPHP\TTLock\Exception\LockException;
use SunnyPHP\TTLock\Helper\DateTime;
use Webmozart\Assert\Assert;

Expand Down Expand Up @@ -53,6 +54,11 @@ public function getCurrentDateTime(): DateTimeImmutable
return $this->currentDateTime;
}

public function getExceptionClass(): string
{
return LockException::class;
}

public function getRequiredConfiguration(): int
{
return RequiredConfiguration::CLIENT_ID | RequiredConfiguration::ACCESS_TOKEN;
Expand Down
6 changes: 6 additions & 0 deletions src/Request/Lock/UpdateElectricQuantity.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use SunnyPHP\TTLock\Contract\Request\Lock\UpdateElectricQuantityInterface;
use SunnyPHP\TTLock\Contract\Request\Method;
use SunnyPHP\TTLock\Contract\Request\RequiredConfiguration;
use SunnyPHP\TTLock\Exception\LockException;
use SunnyPHP\TTLock\Helper\DateTime;

final class UpdateElectricQuantity implements UpdateElectricQuantityInterface
Expand Down Expand Up @@ -50,6 +51,11 @@ public function getCurrentDateTime(): DateTimeImmutable
return $this->currentDateTime;
}

public function getExceptionClass(): string
{
return LockException::class;
}

public function getRequiredConfiguration(): int
{
return RequiredConfiguration::CLIENT_ID | RequiredConfiguration::ACCESS_TOKEN;
Expand Down
6 changes: 6 additions & 0 deletions src/Request/OAuth2/AccessToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use SunnyPHP\TTLock\Contract\Request\Method;
use SunnyPHP\TTLock\Contract\Request\OAuth2\AccessTokenInterface;
use SunnyPHP\TTLock\Contract\Request\RequiredConfiguration;
use SunnyPHP\TTLock\Exception\CommonException;
use Webmozart\Assert\Assert;

final class AccessToken implements AccessTokenInterface
Expand Down Expand Up @@ -43,6 +44,11 @@ public function getPassword(): string
return $this->password;
}

public function getExceptionClass(): string
{
return CommonException::class;
}

public function getRequiredConfiguration(): int
{
return RequiredConfiguration::CLIENT_ID | RequiredConfiguration::CLIENT_SECRET;
Expand Down
6 changes: 6 additions & 0 deletions src/Request/OAuth2/RefreshAccessToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use SunnyPHP\TTLock\Contract\Request\Method;
use SunnyPHP\TTLock\Contract\Request\OAuth2\RefreshAccessTokenInterface;
use SunnyPHP\TTLock\Contract\Request\RequiredConfiguration;
use SunnyPHP\TTLock\Exception\CommonException;
use Webmozart\Assert\Assert;

final class RefreshAccessToken implements RefreshAccessTokenInterface
Expand Down Expand Up @@ -38,6 +39,11 @@ public function getGrantType(): string
return $this->grantType;
}

public function getExceptionClass(): string
{
return CommonException::class;
}

public function getRequiredConfiguration(): int
{
return RequiredConfiguration::CLIENT_ID | RequiredConfiguration::CLIENT_SECRET;
Expand Down
6 changes: 6 additions & 0 deletions src/Request/User/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use SunnyPHP\TTLock\Contract\Request\Method;
use SunnyPHP\TTLock\Contract\Request\RequiredConfiguration;
use SunnyPHP\TTLock\Contract\Request\User\DeleteInterface;
use SunnyPHP\TTLock\Exception\CommonException;
use SunnyPHP\TTLock\Helper\DateTime;
use Webmozart\Assert\Assert;

Expand Down Expand Up @@ -45,6 +46,11 @@ public function getCurrentDateTime(): DateTimeImmutable
return $this->currentDateTime;
}

public function getExceptionClass(): string
{
return CommonException::class;
}

public function getRequiredConfiguration(): int
{
return RequiredConfiguration::CLIENT_ID | RequiredConfiguration::CLIENT_SECRET;
Expand Down
6 changes: 6 additions & 0 deletions src/Request/User/GetList.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use SunnyPHP\TTLock\Contract\Request\Method;
use SunnyPHP\TTLock\Contract\Request\RequiredConfiguration;
use SunnyPHP\TTLock\Contract\Request\User\GetListInterface;
use SunnyPHP\TTLock\Exception\CommonException;
use SunnyPHP\TTLock\Helper\DateTime;
use Webmozart\Assert\Assert;

Expand Down Expand Up @@ -82,6 +83,11 @@ public function getCurrentDateTime(): DateTimeImmutable
return $this->currentDateTime;
}

public function getExceptionClass(): string
{
return CommonException::class;
}

public function getRequiredConfiguration(): int
{
return RequiredConfiguration::CLIENT_ID | RequiredConfiguration::CLIENT_SECRET;
Expand Down
6 changes: 6 additions & 0 deletions src/Request/User/Register.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use SunnyPHP\TTLock\Contract\Request\Method;
use SunnyPHP\TTLock\Contract\Request\RequiredConfiguration;
use SunnyPHP\TTLock\Contract\Request\User\RegisterInterface;
use SunnyPHP\TTLock\Exception\CommonException;
use SunnyPHP\TTLock\Helper\DateTime;
use Webmozart\Assert\Assert;

Expand Down Expand Up @@ -59,6 +60,11 @@ public function getCurrentDateTime(): DateTimeImmutable
return $this->currentDateTime;
}

public function getExceptionClass(): string
{
return CommonException::class;
}

public function getRequiredConfiguration(): int
{
return RequiredConfiguration::CLIENT_ID | RequiredConfiguration::CLIENT_SECRET;
Expand Down
6 changes: 6 additions & 0 deletions src/Request/User/ResetPassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use SunnyPHP\TTLock\Contract\Request\Method;
use SunnyPHP\TTLock\Contract\Request\RequiredConfiguration;
use SunnyPHP\TTLock\Contract\Request\User\ResetPasswordInterface;
use SunnyPHP\TTLock\Exception\CommonException;
use SunnyPHP\TTLock\Helper\DateTime;
use Webmozart\Assert\Assert;

Expand Down Expand Up @@ -59,6 +60,11 @@ public function getCurrentDateTime(): DateTimeImmutable
return $this->currentDateTime;
}

public function getExceptionClass(): string
{
return CommonException::class;
}

public function getRequiredConfiguration(): int
{
return RequiredConfiguration::CLIENT_ID | RequiredConfiguration::CLIENT_SECRET;
Expand Down

0 comments on commit ee60f7b

Please sign in to comment.