Skip to content

Commit fc64add

Browse files
sergix44github-actions[bot]
authored andcommitted
Fix styling
1 parent 0f7b0fc commit fc64add

6 files changed

Lines changed: 22 additions & 17 deletions

File tree

src/Client.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Client extends RemoteClient
3737

3838
private ?string $hfToken;
3939

40-
public function __construct(string $src, string $hfToken = null, Config $config = null)
40+
public function __construct(string $src, ?string $hfToken = null, ?Config $config = null)
4141
{
4242
parent::__construct($src);
4343
$this->config = $config ?? $this->http('get', self::HTTP_CONFIG, dto: Config::class);
@@ -62,7 +62,7 @@ public function getConfig(): Config
6262
return $this->config;
6363
}
6464

65-
public function predict(array $arguments, string $apiName = null, int $fnIndex = null): ?Output
65+
public function predict(array $arguments, ?string $apiName = null, ?int $fnIndex = null): ?Output
6666
{
6767
if ($apiName === null && $fnIndex === null) {
6868
throw new InvalidArgumentException('You must provide an apiName or fnIndex');
@@ -132,6 +132,7 @@ protected function makeUri(Endpoint $endpoint): string
132132
$name = $endpoint->apiName();
133133
if ($name !== null) {
134134
$name = str_replace('/', '', $name);
135+
135136
return "run/$name";
136137
}
137138

@@ -213,8 +214,8 @@ private function sseV1V2Loop(Endpoint $endpoint, array $payload): ?Output
213214
throw new GradioException('Error joining the queue');
214215
}
215216

216-
// $data = $this->decodeResponse($response);
217-
// $eventId = $data['event_id'];
217+
// $data = $this->decodeResponse($response);
218+
// $eventId = $data['event_id'];
218219

219220
$response = $this->httpRaw('get', self::SSE_GET_DATA, ['session_hash' => $this->sessionHash], [
220221
'headers' => [
@@ -225,10 +226,11 @@ private function sseV1V2Loop(Endpoint $endpoint, array $payload): ?Output
225226

226227
$buffer = '';
227228
$message = null;
228-
while (!$response->getBody()->eof()) {
229+
while (! $response->getBody()->eof()) {
229230
$data = $response->getBody()->read(1);
230231
if ($data !== "\n") {
231232
$buffer .= $data;
233+
232234
continue;
233235
}
234236

src/Client/Endpoint.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
readonly class Endpoint
88
{
9-
109
public function __construct(
1110
private Config $config,
1211
public int $index,
@@ -26,11 +25,11 @@ public function __isset(string $name): bool
2625

2726
public function skipsQueue(): bool
2827
{
29-
return !($this->data['queue'] ?? $this->config->enable_queue);
28+
return ! ($this->data['queue'] ?? $this->config->enable_queue);
3029
}
3130

3231
public function apiName(): ?string
3332
{
34-
return !empty($this->data['api_name']) ? $this->data['api_name'] : null;
33+
return ! empty($this->data['api_name']) ? $this->data['api_name'] : null;
3534
}
3635
}

src/Client/RemoteClient.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ abstract class RemoteClient extends RegisterEvents
2020
public function __construct(string $src)
2121
{
2222
if (
23-
!str_starts_with($src, 'http://') &&
24-
!str_starts_with($src, 'https://') &&
25-
!str_starts_with($src, 'ws://') &&
26-
!str_starts_with($src, 'wss://')
23+
! str_starts_with($src, 'http://') &&
24+
! str_starts_with($src, 'https://') &&
25+
! str_starts_with($src, 'ws://') &&
26+
! str_starts_with($src, 'wss://')
2727
) {
2828
throw new InvalidArgumentException('The src must not contain the protocol');
2929
}
@@ -44,12 +44,14 @@ public function __construct(string $src)
4444
protected function http(string $method, string $uri, array $params = [], array $opt = [], ?string $dto = null)
4545
{
4646
$response = $this->httpRaw($method, $uri, $params, $opt);
47+
4748
return $this->decodeResponse($response, $dto);
4849
}
4950

5051
protected function httpRaw(string $method, string $uri, array $params = [], array $opt = [])
5152
{
5253
$keyContent = $method === 'get' ? 'query' : 'json';
54+
5355
return $this->httpClient->request($method, $uri, array_merge([
5456
$keyContent => $params,
5557
], $opt));
@@ -60,7 +62,7 @@ protected function ws(string $uri, array $options = []): EnhancedClient
6062
return new EnhancedClient(str_replace('http', 'ws', $this->src).$uri, $options);
6163
}
6264

63-
protected function decodeResponse(ResponseInterface|string $response, string $mapTo = null): mixed
65+
protected function decodeResponse(ResponseInterface|string $response, ?string $mapTo = null): mixed
6466
{
6567
$body = $response instanceof ResponseInterface ? $response->getBody()->getContents() : $response;
6668

src/DTO/Resolvers/MessageResolver.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ public function concreteFor(array $data): ?string
2929
MessageType::PROCESS_GENERATING->value => ProcessGenerating::class,
3030
MessageType::PROCESS_COMPLETED->value => ProcessCompleted::class,
3131
MessageType::LOG->value => Log::class,
32-
default => (new class extends Message {})::class,
32+
default => (new class extends Message
33+
{
34+
})::class,
3335
};
3436
}
3537
}

src/Exception/QueueFullException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class QueueFullException extends GradioException
88
{
9-
public function __construct(string $message = 'Queue full.', int $code = 0, Throwable $previous = null)
9+
public function __construct(string $message = 'Queue full.', int $code = 0, ?Throwable $previous = null)
1010
{
1111
parent::__construct($message, $code, $previous);
1212
}

tests/ExampleTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
$client = new Client('https://multimodalart-stable-cascade.hf.space');
77

88
$response = $client->predict([
9-
"house", // string in 'Prompt' Textbox component
10-
"!", // string in 'Negative prompt' Textbox component
9+
'house', // string in 'Prompt' Textbox component
10+
'!', // string in 'Negative prompt' Textbox component
1111
0, // number (numeric value between 0 and 2147483647) in 'Seed' Slider component
1212
1024, // number (numeric value between 1024 and 1536) in 'Width' Slider component
1313
1024, // number (numeric value between 1024 and 1536) in 'Height' Slider component

0 commit comments

Comments
 (0)