Skip to content

Commit

Permalink
chore: fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
loks0n committed Jun 12, 2024
1 parent 473fbe5 commit 25c6f98
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 20 deletions.
3 changes: 1 addition & 2 deletions src/Orchestration/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,10 @@ abstract public function listNetworks(): array;
/**
* Get usage stats of containers
*
* @param string $container
* @param array<string, string> $filters
* @return array<\Utopia\Orchestration\Container\Stats>
*/
abstract public function getStats(string $container = null, array $filters = []): array;
abstract public function getStats(?string $container = null, array $filters = []): array;

/**
* Pull Image
Expand Down
15 changes: 5 additions & 10 deletions src/Orchestration/Adapter/DockerAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,8 @@ class DockerAPI extends Adapter
{
/**
* Constructor
*
* @param string $username
* @param string $password
* @param string $email
*/
public function __construct(string $username = null, string $password = null, string $email = null)
public function __construct(?string $username = null, ?string $password = null, ?string $email = null)
{
if ($username && $password && $email) {
$this->registryAuth = base64_encode(json_encode([
Expand Down Expand Up @@ -188,9 +184,9 @@ public function createNetwork(string $name, bool $internal = false): bool
]);

if ($result['code'] === 409) {
throw new Orchestration('Network with name "' . $name . '" already exists: ' . $result['response']);
throw new Orchestration('Network with name "'.$name.'" already exists: '.$result['response']);
} elseif ($result['code'] !== 201) {
throw new Orchestration('Error creating network: ' . $result['response']);
throw new Orchestration('Error creating network: '.$result['response']);
}

return $result['response'];
Expand Down Expand Up @@ -256,11 +252,10 @@ public function networkDisconnect(string $container, string $network, bool $forc
/**
* Get usage stats of containers
*
* @param string $container
* @param array<string, string> $filters
* @return array<Stats>
*/
public function getStats(string $container = null, array $filters = []): array
public function getStats(?string $container = null, array $filters = []): array
{
// List ahead of time, since API does not allow listing all usage stats
$containerIds = [];
Expand All @@ -275,7 +270,7 @@ public function getStats(string $container = null, array $filters = []): array
$list = [];

foreach ($containerIds as $containerId) {
$result = $this->call('http://localhost/containers/' . $containerId . '/stats?stream=false', 'GET');
$result = $this->call('http://localhost/containers/'.$containerId.'/stats?stream=false', 'GET');

if ($result['code'] !== 200) {
throw new Orchestration($result['response']);
Expand Down
9 changes: 3 additions & 6 deletions src/Orchestration/Adapter/DockerCLI.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ class DockerCLI extends Adapter
/**
* Constructor
*
* @param string $username
* @param string $password
* @return void
*/
public function __construct(string $username = null, string $password = null)
public function __construct(?string $username = null, ?string $password = null)
{
if ($username && $password) {
$output = '';
Expand Down Expand Up @@ -81,11 +79,10 @@ public function networkDisconnect(string $container, string $network, bool $forc
/**
* Get usage stats of containers
*
* @param string $container
* @param array<string, string> $filters
* @return array<Stats>
*/
public function getStats(string $container = null, array $filters = []): array
public function getStats(?string $container = null, array $filters = []): array
{
// List ahead of time, since docker stats does not allow filtering
$containerIds = [];
Expand Down Expand Up @@ -163,7 +160,7 @@ private function parseIOStats(string $stats)
'TiB' => 1000000000000,
];

[ $inStr, $outStr ] = \explode(' / ', $stats);
[$inStr, $outStr] = \explode(' / ', $stats);

$inUnit = null;
$outUnit = null;
Expand Down
3 changes: 1 addition & 2 deletions src/Orchestration/Orchestration.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,10 @@ public function networkConnect(string $container, string $network): bool
/**
* Get usage stats of containers
*
* @param string $container
* @param array<string, string> $filters
* @return array<\Utopia\Orchestration\Container\Stats>
*/
public function getStats(string $container = null, array $filters = []): array
public function getStats(?string $container = null, array $filters = []): array
{
return $this->adapter->getStats($container, $filters);
}
Expand Down

0 comments on commit 25c6f98

Please sign in to comment.