Skip to content

Commit

Permalink
Minor docblock updates and remove not used imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Roussetos Karafyllakis committed Jan 8, 2025
1 parent d2e0d2d commit e8abb38
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 45 deletions.
45 changes: 24 additions & 21 deletions src/Webuzo/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@

namespace Upmind\ProvisionProviders\SharedHosting\Webuzo;

use Illuminate\Support\Arr;
use JsonException;
use Upmind\ProvisionBase\Helper;
use GuzzleHttp\Client;
use RuntimeException;
use Illuminate\Support\Str;
use Upmind\ProvisionProviders\SharedHosting\Data\AccountInfo;
use Upmind\ProvisionProviders\SharedHosting\Data\CreateParams;
use Upmind\ProvisionProviders\SharedHosting\Data\UnitsConsumed;
use Upmind\ProvisionProviders\SharedHosting\Data\UsageData;
Expand All @@ -19,7 +16,6 @@
class Api
{
private Configuration $configuration;

protected Client $client;

public function __construct(Client $client, Configuration $configuration)
Expand All @@ -36,11 +32,10 @@ public function makeRequest(
string $command,
?array $body = null,
?string $method = 'POST'
): ?array
{
): ?array {
$requestParams = [];

if ($command == 'sso') {
if ($command === 'sso') {
$requestParams['query']['loginAs'] = $body['username'];
$requestParams['query']['noip'] = 1;
}
Expand Down Expand Up @@ -104,6 +99,10 @@ private function getResponseErrorMessage(array $response): ?string
return null;
}

/**
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Upmind\ProvisionBase\Exception\ProvisionFunctionError
*/
public function createAccount(CreateParams $params, string $username, bool $asReseller): void
{
$password = $params->password ?: Helper::generatePassword();
Expand All @@ -126,8 +125,8 @@ public function createAccount(CreateParams $params, string $username, bool $asRe
}

/**
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Upmind\ProvisionBase\Exception\ProvisionFunctionError
* @throws \RuntimeException
*/
public function getAccountData(string $username): array
{
Expand Down Expand Up @@ -170,31 +169,31 @@ public function getUserDetails(string $username): ?array
}

/**
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Upmind\ProvisionBase\Exception\ProvisionFunctionError
* @throws \RuntimeException
*/
public function getAccountUsage(string $username): UsageData
{
$account = $this->getUserDetails($username)['resource'];

$disk = UnitsConsumed::create()
->setUsed((int)$account['disk']['used_bytes'] / (1024 * 1024))
->setLimit(($account['disk']['limit_bytes'] == 0 || $account['disk']['limit_bytes'] == 'unlimited')
->setLimit(($account['disk']['limit_bytes'] == 0 || $account['disk']['limit_bytes'] === 'unlimited')
? null : (int)$account['disk']['limit_bytes'] / (1024 * 1024));

$bandwidth = UnitsConsumed::create()
->setUsed((int)$account['bandwidth']['used_bytes'] / (1024 * 1024))
->setLimit(($account['bandwidth']['limit_bytes'] == 0 || $account['bandwidth']['limit_bytes'] == 'unlimited')
->setLimit(($account['bandwidth']['limit_bytes'] == 0 || $account['bandwidth']['limit_bytes'] === 'unlimited')
? null : (int)$account['bandwidth']['limit_bytes'] / (1024 * 1024));

$inodes = UnitsConsumed::create()
->setUsed((int)$account['inode']['used'])
->setLimit($account['inode']['limit'] == 'unlimited'
->setLimit($account['inode']['limit'] === 'unlimited'
? null : (int)$account['inode']['limit']);

$mailboxes = UnitsConsumed::create()
->setUsed((int)$account['email_account']['used'])
->setLimit($account['email_account']['limit'] == 'unlimited'
->setLimit($account['email_account']['limit'] === 'unlimited'
? null : (int)$account['email_account']['limit']);

return UsageData::create()
Expand All @@ -205,8 +204,8 @@ public function getAccountUsage(string $username): UsageData
}

/**
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Upmind\ProvisionBase\Exception\ProvisionFunctionError
* @throws \RuntimeException
*/
public function suspendAccount(string $username): void
{
Expand All @@ -218,8 +217,8 @@ public function suspendAccount(string $username): void
}

/**
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Upmind\ProvisionBase\Exception\ProvisionFunctionError
* @throws \RuntimeException
*/
public function unsuspendAccount(string $username): void
{
Expand All @@ -231,8 +230,8 @@ public function unsuspendAccount(string $username): void
}

/**
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Upmind\ProvisionBase\Exception\ProvisionFunctionError
* @throws \RuntimeException
*/
public function deleteAccount(string $username): void
{
Expand All @@ -244,8 +243,8 @@ public function deleteAccount(string $username): void
}

/**
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Upmind\ProvisionBase\Exception\ProvisionFunctionError
* @throws \RuntimeException
*/
public function updatePackage(string $username, string $package): void
{
Expand All @@ -264,8 +263,8 @@ public function updatePackage(string $username, string $package): void
}

/**
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Upmind\ProvisionBase\Exception\ProvisionFunctionError
* @throws \RuntimeException
*/
public function updatePassword(string $username, string $password): void
{
Expand All @@ -286,8 +285,8 @@ public function updatePassword(string $username, string $password): void
}

/**
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Upmind\ProvisionBase\Exception\ProvisionFunctionError
* @throws \RuntimeException
*/
public function getLoginUrl(string $username): string
{
Expand All @@ -300,7 +299,11 @@ public function getLoginUrl(string $username): string
return $response['done']['url'];
}

public function setReseller(string $username, int $isReseller)
/**
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Upmind\ProvisionBase\Exception\ProvisionFunctionError
*/
public function setReseller(string $username, int $isReseller): void
{
$account = $this->getUserDetails($username);

Expand Down
6 changes: 3 additions & 3 deletions src/Webuzo/Data/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
/**
* Webuzo API credentials.
* @property-read string $hostname API hostname
* @property-read string $api_key API key
* @property-read string $username Username
* @property-read string $password Password
* @property-read string|null $api_key API key
* @property-read string|null $username Username
* @property-read string|null $password Password
*/
class Configuration extends DataSet
{
Expand Down
27 changes: 6 additions & 21 deletions src/Webuzo/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
namespace Upmind\ProvisionProviders\SharedHosting\Webuzo;

use GuzzleHttp\Client;
use Carbon\Carbon;
use Throwable;
use Upmind\ProvisionBase\Exception\ProvisionFunctionError;
use Upmind\ProvisionBase\Provider\Contract\ProviderInterface;
use Upmind\ProvisionBase\Provider\DataSet\AboutData;
use Upmind\ProvisionProviders\SharedHosting\Category;
Expand All @@ -32,15 +30,8 @@ class Provider extends Category implements ProviderInterface
{
protected const MAX_USERNAME_LENGTH = 10;

/**
* @var Configuration
*/
protected $configuration;

/**
* @var Api|null
*/
protected $api;
protected Configuration $configuration;
protected ?Api $api = null;

public function __construct(Configuration $configuration)
{
Expand All @@ -63,7 +54,6 @@ public static function aboutProvider(): AboutData
*
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Upmind\ProvisionBase\Exception\ProvisionFunctionError
* @throws \Throwable
*/
public function create(CreateParams $params): AccountInfo
{
Expand Down Expand Up @@ -109,7 +99,6 @@ protected function _getInfo(string $username, string $message): AccountInfo
*
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Upmind\ProvisionBase\Exception\ProvisionFunctionError
* @throws \Throwable
*/
public function getInfo(AccountUsername $params): AccountInfo
{
Expand All @@ -122,7 +111,6 @@ public function getInfo(AccountUsername $params): AccountInfo
/**
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Upmind\ProvisionBase\Exception\ProvisionFunctionError
* @throws \Throwable
*/
public function getUsage(AccountUsername $params): AccountUsage
{
Expand All @@ -137,7 +125,6 @@ public function getUsage(AccountUsername $params): AccountUsage
*
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Upmind\ProvisionBase\Exception\ProvisionFunctionError
* @throws \Throwable
*/
public function getLoginUrl(GetLoginUrlParams $params): LoginUrl
{
Expand All @@ -156,7 +143,6 @@ public function getLoginUrl(GetLoginUrlParams $params): LoginUrl
*
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Upmind\ProvisionBase\Exception\ProvisionFunctionError
* @throws \Throwable
*/
public function changePassword(ChangePasswordParams $params): EmptyResult
{
Expand All @@ -170,7 +156,6 @@ public function changePassword(ChangePasswordParams $params): EmptyResult
*
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Upmind\ProvisionBase\Exception\ProvisionFunctionError
* @throws \Throwable
*/
public function changePackage(ChangePackageParams $params): AccountInfo
{
Expand All @@ -187,7 +172,6 @@ public function changePackage(ChangePackageParams $params): AccountInfo
*
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Upmind\ProvisionBase\Exception\ProvisionFunctionError
* @throws \Throwable
*/
public function suspend(SuspendParams $params): AccountInfo
{
Expand All @@ -201,7 +185,6 @@ public function suspend(SuspendParams $params): AccountInfo
*
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Upmind\ProvisionBase\Exception\ProvisionFunctionError
* @throws \Throwable
*/
public function unSuspend(AccountUsername $params): AccountInfo
{
Expand All @@ -215,7 +198,6 @@ public function unSuspend(AccountUsername $params): AccountInfo
*
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Upmind\ProvisionBase\Exception\ProvisionFunctionError
* @throws \Throwable
*/
public function terminate(AccountUsername $params): EmptyResult
{
Expand All @@ -227,6 +209,7 @@ public function terminate(AccountUsername $params): EmptyResult
/**
* @inheritDoc
*
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Upmind\ProvisionBase\Exception\ProvisionFunctionError
*/
public function grantReseller(GrantResellerParams $params): ResellerPrivileges
Expand All @@ -241,6 +224,7 @@ public function grantReseller(GrantResellerParams $params): ResellerPrivileges
/**
* @inheritDoc
*
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Upmind\ProvisionBase\Exception\ProvisionFunctionError
*/
public function revokeReseller(AccountUsername $params): ResellerPrivileges
Expand All @@ -255,6 +239,7 @@ public function revokeReseller(AccountUsername $params): ResellerPrivileges
/**
* @return no-return
*
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Upmind\ProvisionBase\Exception\ProvisionFunctionError
* @throws \Throwable
*/
Expand All @@ -272,7 +257,7 @@ protected function api(): Api

$auth = '';

if (isset($this->configuration->username) && isset($this->configuration->password)) {
if (isset($this->configuration->username, $this->configuration->password)) {
$auth = $this->configuration->username . ':' . $this->configuration->password . '@';
}

Expand Down

0 comments on commit e8abb38

Please sign in to comment.