Skip to content

Commit b87bd20

Browse files
feat(client)!: redesign methods
1 parent 50fd6a3 commit b87bd20

50 files changed

Lines changed: 1000 additions & 1539 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ use LegalesignSDK\Client;
4949

5050
$client = new Client(apiKey: getenv("LEGALESIGN_SDK_API_KEY") ?: "My API Key");
5151

52-
$documents = $client->document->list(group: "REPLACE_ME");
52+
$documents = $client->document->list(["group" => "REPLACE_ME"]);
5353

5454
var_dump($documents->meta);
5555
```
@@ -71,7 +71,7 @@ When the library is unable to connect to the API, or if the API returns a non-su
7171
use LegalesignSDK\Core\Exceptions\APIConnectionException;
7272

7373
try {
74-
$documents = $client->document->list(group: "REPLACE_ME");
74+
$documents = $client->document->list(["group" => "REPLACE_ME"]);
7575
} catch (APIConnectionException $e) {
7676
echo "The server could not be reached", PHP_EOL;
7777
var_dump($e->getPrevious());
@@ -118,7 +118,7 @@ $client = new Client(maxRetries: 0);
118118

119119
// Or, configure per-request:
120120
$result = $client->document->list(
121-
group: "REPLACE_ME", requestOptions: RequestOptions::with(maxRetries: 5)
121+
["group" => "REPLACE_ME"], RequestOptions::with(maxRetries: 5)
122122
);
123123
```
124124

@@ -138,15 +138,13 @@ Note: the `extra*` parameters of the same name overrides the documented paramete
138138
use LegalesignSDK\RequestOptions;
139139

140140
$documents = $client->document->list(
141-
group: "REPLACE_ME",
142-
requestOptions: RequestOptions::with(
141+
["group" => "REPLACE_ME"],
142+
RequestOptions::with(
143143
extraQueryParams: ["my_query_parameter" => "value"],
144144
extraBodyParams: ["my_body_parameter" => "value"],
145145
extraHeaders: ["my-header" => "value"],
146146
),
147147
);
148-
149-
var_dump($documents["my_undocumented_property"]);
150148
```
151149

152150
#### Undocumented request params

src/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public function __construct(?string $apiKey = null, ?string $baseUrl = null)
9696
$this->templatepdf = new TemplatepdfService($this);
9797
}
9898

99-
/** @return array<string, string> */
99+
/** @return array<string,string> */
100100
protected function authHeaders(): array
101101
{
102102
return $this->apiKey ? ['Authorization' => $this->apiKey] : [];

src/Core/BaseClient.php

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
* @phpstan-type normalized_request = array{
2525
* method: string,
2626
* path: string,
27-
* query: array<string, mixed>,
28-
* headers: array<string, string|null|list<string>>,
27+
* query: array<string,mixed>,
28+
* headers: array<string,string|null|list<string>>,
2929
* body: mixed,
3030
* }
3131
*/
@@ -36,7 +36,7 @@ abstract class BaseClient
3636
/**
3737
* @internal
3838
*
39-
* @param array<string, string|int|list<string|int>|null> $headers
39+
* @param array<string,string|int|list<string|int>|null> $headers
4040
*/
4141
public function __construct(
4242
protected array $headers,
@@ -49,11 +49,11 @@ public function __construct(
4949

5050
/**
5151
* @param string|list<mixed> $path
52-
* @param array<string, mixed> $query
53-
* @param array<string, mixed> $headers
52+
* @param array<string,mixed> $query
53+
* @param array<string,mixed> $headers
5454
* @param class-string<BasePage<mixed>> $page
5555
* @param class-string<BaseStream<mixed>> $stream
56-
* @param RequestOptions|array<string, mixed>|null $options
56+
* @param RequestOptions|array<string,mixed>|null $options
5757
*/
5858
public function request(
5959
string $method,
@@ -102,7 +102,7 @@ public function request(
102102
return Util::decodeContent($rsp);
103103
}
104104

105-
/** @return array<string, string> */
105+
/** @return array<string,string> */
106106
abstract protected function authHeaders(): array;
107107

108108
protected function getNormalizedOS(): string
@@ -159,15 +159,15 @@ protected function getNormalizedArchitecture(): string
159159
* @internal
160160
*
161161
* @param string|list<string> $path
162-
* @param array<string, mixed> $query
163-
* @param array<string, string|int|list<string|int>|null> $headers
162+
* @param array<string,mixed> $query
163+
* @param array<string,string|int|list<string|int>|null> $headers
164164
* @param array{
165165
* timeout?: float|null,
166166
* maxRetries?: int|null,
167167
* initialRetryDelay?: float|null,
168168
* maxRetryDelay?: float|null,
169-
* extraHeaders?: array<string, string|int|list<string|int>|null>|null,
170-
* extraQueryParams?: array<string, mixed>|null,
169+
* extraHeaders?: array<string,string|int|list<string|int>|null>|null,
170+
* extraQueryParams?: array<string,mixed>|null,
171171
* extraBodyParams?: mixed,
172172
* transporter?: ClientInterface|null,
173173
* uriFactory?: UriFactoryInterface|null,
@@ -189,14 +189,14 @@ protected function buildRequest(
189189

190190
$parsedPath = Util::parsePath($path);
191191

192-
/** @var array<string, mixed> $mergedQuery */
192+
/** @var array<string,mixed> $mergedQuery */
193193
$mergedQuery = array_merge_recursive(
194194
$query,
195195
$options->extraQueryParams ?? [],
196196
);
197197
$uri = Util::joinUri($this->baseUrl, path: $parsedPath, query: $mergedQuery)->__toString();
198198

199-
/** @var array<string, string|list<string>|null> $mergedHeaders */
199+
/** @var array<string,string|list<string>|null> $mergedHeaders */
200200
$mergedHeaders = [...$this->headers,
201201
...$this->authHeaders(),
202202
...$headers,
@@ -276,8 +276,7 @@ protected function retryDelay(
276276
/**
277277
* @internal
278278
*
279-
* @param bool|int|float|string|resource|\Traversable<mixed>|array<string,
280-
* mixed,>|null $data
279+
* @param bool|int|float|string|resource|\Traversable<mixed,>|array<string,mixed>|null $data
281280
*/
282281
protected function sendRequest(
283282
RequestOptions $opts,

src/Core/Util.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ final class Util
2626
public const JSONL_CONTENT_TYPE = '/^application\/(:?x-(?:n|l)djson)|(:?(?:x-)?jsonl)/';
2727

2828
/**
29-
* @return array<string, mixed>
29+
* @return array<string,mixed>
3030
*/
3131
public static function get_object_vars(object $object1): array
3232
{
@@ -36,10 +36,10 @@ public static function get_object_vars(object $object1): array
3636
/**
3737
* @template T
3838
*
39-
* @param array<string, T> $array
40-
* @param array<string, string> $map
39+
* @param array<string,T> $array
40+
* @param array<string,string> $map
4141
*
42-
* @return array<string, T>
42+
* @return array<string,T>
4343
*/
4444
public static function array_transform_keys(array $array, array $map): array
4545
{
@@ -52,9 +52,9 @@ public static function array_transform_keys(array $array, array $map): array
5252
}
5353

5454
/**
55-
* @param array<string, mixed> $arr
55+
* @param array<string,mixed> $arr
5656
*
57-
* @return array<string, mixed>
57+
* @return array<string,mixed>
5858
*/
5959
public static function array_filter_omit(array $arr): array
6060
{
@@ -106,7 +106,7 @@ public static function parsePath(string|array $path): string
106106
}
107107

108108
/**
109-
* @param array<string, mixed> $query
109+
* @param array<string,mixed> $query
110110
*/
111111
public static function joinUri(
112112
UriInterface $base,
@@ -141,7 +141,7 @@ public static function joinUri(
141141
}
142142

143143
/**
144-
* @param array<string, string|int|list<string|int>|null> $headers
144+
* @param array<string,string|int|list<string|int>|null> $headers
145145
*/
146146
public static function withSetHeaders(
147147
RequestInterface $req,
@@ -182,8 +182,7 @@ public static function streamIterator(StreamInterface $stream): \Iterator
182182
}
183183

184184
/**
185-
* @param bool|int|float|string|resource|\Traversable<mixed>|array<string,
186-
* mixed,>|null $body
185+
* @param bool|int|float|string|resource|\Traversable<mixed,>|array<string,mixed>|null $body
187186
*/
188187
public static function withSetBody(
189188
StreamFactoryInterface $factory,
@@ -409,8 +408,7 @@ private static function writeMultipartChunk(
409408
}
410409

411410
/**
412-
* @param bool|int|float|string|resource|\Traversable<mixed>|array<string,
413-
* mixed,>|null $body
411+
* @param bool|int|float|string|resource|\Traversable<mixed,>|array<string,mixed>|null $body
414412
*
415413
* @return array{string, \Generator<string>}
416414
*/

0 commit comments

Comments
 (0)