Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
d8vjork committed Feb 23, 2024
1 parent 3b04132 commit 6b14575
Show file tree
Hide file tree
Showing 36 changed files with 336 additions and 306 deletions.
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
"require-dev": {
"laravel/pint": "^1.13",
"guzzlehttp/guzzle": "^7.1",
"phpstan/phpstan": "^1.0",
"phpunit/phpunit": "^10.0"
"pestphp/pest": "^2.34",
"phpstan/phpstan": "^1.0"
},
"minimum-stability": "dev",
"autoload": {
Expand All @@ -55,7 +55,8 @@
"config": {
"sort-packages": true,
"allow-plugins": {
"php-http/discovery": true
"php-http/discovery": true,
"pestphp/pest-plugin": true
}
}
}
}
6 changes: 1 addition & 5 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
includes:
- ./vendor/nunomaduro/larastan/extension.neon

parameters:

paths:
- src

# The level 8 is the highest level
level: 5
level: 'max'

checkMissingIterableValueType: false
4 changes: 2 additions & 2 deletions pint.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"preset": "laravel"
}
"preset": "per"
}
58 changes: 37 additions & 21 deletions src/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,90 +33,106 @@ class ApiClient

private HttpClient $client;

private RequestFactoryInterface $requestFactory;

private StreamFactoryInterface $streamFactory;

Check failure on line 38 in src/ApiClient.php

View workflow job for this annotation

GitHub Actions / PHPStan

Property OpenSoutheners\Docker\ApiClient::$streamFactory is never read, only written.

public function __construct(
private string $baseUrl,
private ?SocketClient $socket = null,
private ?RequestFactoryInterface $requestFactory = null,
private ?StreamFactoryInterface $streamFactory = null,
private ?PluginClientFactory $pluginFactory = null,
?SocketClient $socket = null,
?RequestFactoryInterface $requestFactory = null,
?StreamFactoryInterface $streamFactory = null,
?PluginClientFactory $pluginFactory = null,
private array $headers = []
) {
$this->requestFactory ??= Psr17FactoryDiscovery::findRequestFactory();
$this->streamFactory ??= Psr17FactoryDiscovery::findStreamFactory();
$requestFactory ??= Psr17FactoryDiscovery::findRequestFactory();
$streamFactory ??= Psr17FactoryDiscovery::findStreamFactory();

$this->requestFactory = $requestFactory;
$this->streamFactory = $streamFactory;

$socket ??= new SocketClient($this->requestFactory, [

Check failure on line 54 in src/ApiClient.php

View workflow job for this annotation

GitHub Actions / PHPStan

Parameter #1 $config1 of class Http\Client\Socket\Client constructor expects array{remote_socket?: string|null, timeout?: int, stream_context?: resource, stream_context_options?: array<string, mixed>, stream_context_param?: array<string, mixed>, ssl?: bool|null, write_buffer_size?: int, ssl_method?: int}|Psr\Http\Message\ResponseFactoryInterface, Psr\Http\Message\RequestFactoryInterface given.
'remote_socket' => 'unix:///var/run/docker.sock',
]);

$this->pluginFactory ??= new PluginClientFactory;
$pluginFactory ??= new PluginClientFactory();

$this->client = $this->pluginFactory->createClient($socket, [
$this->client = $pluginFactory->createClient($socket, [
new ContentLengthPlugin(),
new DecoderPlugin(),
]);
}

public function get(string $path, array $params = [])
private function queryToString(array|RequestQuery $params = []): string
{
return build_http_query(
$params instanceof RequestQuery
? $params->toArray()
: $params
);
}

public function get(string $path, array|RequestQuery $params = []): mixed
{
$request = $this->requestFactory->createRequest(
'GET',
$this->baseUrl.$path.build_http_query($params)
$this->baseUrl . $path . $this->queryToString($params)
);

return $this->executeRequest($request);
}

public function head(string $path)
public function head(string $path, array|RequestQuery $params = []): mixed
{
$request = $this->requestFactory->createRequest(
'HEAD',
$this->baseUrl.$path
$this->baseUrl . $path
);

return $this->executeRequest($request);
}

public function post(string $path, $body = null, array $params = [], string $contentType = null)
public function post(string $path, $body = null, array|RequestQuery $params = [], ?string $contentType = null): mixed

Check failure on line 95 in src/ApiClient.php

View workflow job for this annotation

GitHub Actions / PHPStan

Method OpenSoutheners\Docker\ApiClient::post() has parameter $body with no type specified.
{
$this->contentType($contentType ?? static::JSON_CONTENT_TYPE);

$request = $this->requestFactory->createRequest(
'POST',
$this->baseUrl.$path.build_http_query($params)
$this->baseUrl . $path . $this->queryToString($params)
)->withBody($this->applySentBodyParsing($body));

Check failure on line 102 in src/ApiClient.php

View workflow job for this annotation

GitHub Actions / PHPStan

Parameter #1 $body of method Psr\Http\Message\MessageInterface::withBody() expects Psr\Http\Message\StreamInterface, mixed given.

return $this->executeRequest($request);
}

public function put(string $path, $body = null, array $params = [], string $contentType = null)
public function put(string $path, $body = null, array|RequestQuery $params = [], ?string $contentType = null): mixed

Check failure on line 107 in src/ApiClient.php

View workflow job for this annotation

GitHub Actions / PHPStan

Method OpenSoutheners\Docker\ApiClient::put() has parameter $body with no type specified.
{
$this->contentType($contentType ?? static::JSON_CONTENT_TYPE);

$request = $this->requestFactory->createRequest(
'PUT',
$this->baseUrl.$path.build_http_query($params)
$this->baseUrl . $path . $this->queryToString($params)
)->withBody($this->applySentBodyParsing($body));

Check failure on line 114 in src/ApiClient.php

View workflow job for this annotation

GitHub Actions / PHPStan

Parameter #1 $body of method Psr\Http\Message\MessageInterface::withBody() expects Psr\Http\Message\StreamInterface, mixed given.

return $this->executeRequest($request);
}

public function patch(string $path, $body = null, array $params = [], string $contentType = null)
public function patch(string $path, $body = null, array|RequestQuery $params = [], ?string $contentType = null): mixed

Check failure on line 119 in src/ApiClient.php

View workflow job for this annotation

GitHub Actions / PHPStan

Method OpenSoutheners\Docker\ApiClient::patch() has parameter $body with no type specified.
{
$this->contentType($contentType ?? static::JSON_CONTENT_TYPE);

$request = $this->requestFactory->createRequest(
'PATCH',
$this->baseUrl.$path.build_http_query($params)
$this->baseUrl . $path . $this->queryToString($params)
)->withBody($this->applySentBodyParsing($body));

Check failure on line 126 in src/ApiClient.php

View workflow job for this annotation

GitHub Actions / PHPStan

Parameter #1 $body of method Psr\Http\Message\MessageInterface::withBody() expects Psr\Http\Message\StreamInterface, mixed given.

return $this->executeRequest($request);
}

public function delete(string $path, array $params = [])
public function delete(string $path, array|RequestQuery $params = []): mixed
{
$request = $this->requestFactory->createRequest(
'DELETE',
$this->baseUrl.$path.build_http_query($params)
$this->baseUrl . $path . $this->queryToString($params)
);

return $this->executeRequest($request);
Expand All @@ -134,7 +150,7 @@ public function usingHeader(string $header, string $value): static
return $this;
}

private function executeRequest(RequestInterface $request)
private function executeRequest(RequestInterface $request): mixed
{
foreach ($this->headers as $header => $value) {
$request = $request->withAddedHeader($header, $value);
Expand Down
2 changes: 1 addition & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function __construct(
StreamFactoryInterface $streamFactory = null
) {
$this->apiClient = new ApiClient(
$url.'/'.static::DOCKER_API_VERSION,
$url . '/' . static::DOCKER_API_VERSION,
$socketClient,
$requestFactory,
$streamFactory
Expand Down
6 changes: 3 additions & 3 deletions src/Compose/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ protected function loadFromFile(): void

public function toFile(string $filePath = null): void
{
//
//
}

public function toArray(): array
{
return [
'version' => $this->version,
'services' => array_map(fn (Service $service) => $service->toArray(), $this->services),
'services' => array_map(fn(Service $service) => $service->toArray(), $this->services),
];
}

Expand All @@ -49,7 +49,7 @@ public function toYaml(int $indentation = 2)

public function newServiceBuilder(): ServiceBuilder
{
return new ServiceBuilder;
return new ServiceBuilder();
}

public function addService(string $id, Service $service): self
Expand Down
4 changes: 2 additions & 2 deletions src/Compose/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function __construct(
public array|null $ports = [],
public array|null $labels = [],
) {
//
//
}

public function toArray()
Expand All @@ -27,7 +27,7 @@ public function toArray()
'name' => $this->name,
'image' => $this->image,
'build' => $this->build,
'ports' => array_map(fn (ServicePort $port) => $port->mode ? $port->toArray() : (string) $port, $this->ports),
'ports' => array_map(fn(ServicePort $port) => $port->mode ? $port->toArray() : (string) $port, $this->ports),
'labels' => $this->labels,
]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Compose/ServiceBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class ServiceBuilder
public function __construct(
protected ?Service $service = null
) {
$this->service ??= new Service;
$this->service ??= new Service();
}

public function fromArray(array $data): self
Expand Down
2 changes: 1 addition & 1 deletion src/Compose/ServicePort.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function __construct(
public string|null $protocol = null,
public string|null $mode = null
) {
//
//
}

public function getPublished(): int|string
Expand Down
18 changes: 9 additions & 9 deletions src/Endpoints/Configs.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,28 @@ class Configs extends Endpoint
{
protected const PATH = '/configs';

public function list()
public function list(): mixed
{
return $this->client->get(self::PATH);
}

public function create()
public function create(): mixed
{
return $this->client->post(self::PATH.'/create');
return $this->client->post(self::PATH . '/create');
}

public function inspect(string $id)
public function inspect(string $id): mixed
{
return $this->client->get(self::PATH."/{$id}");
return $this->client->get(self::PATH . "/{$id}");
}

public function remove(string $id)
public function remove(string $id): mixed
{
return $this->client->delete(self::PATH."/{$id}");
return $this->client->delete(self::PATH . "/{$id}");
}

public function update(string $id)
public function update(string $id): mixed
{
return $this->client->post(self::PATH."/{$id}/update");
return $this->client->post(self::PATH . "/{$id}/update");
}
}
Loading

0 comments on commit 6b14575

Please sign in to comment.