Skip to content

Commit 0cd048d

Browse files
chore: intuitively order union types
1 parent 7297553 commit 0cd048d

36 files changed

+132
-126
lines changed

.php-cs-fixer.dist.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,11 @@
77
return (new Config())
88
->setParallelConfig(ParallelConfigFactory::detect())
99
->setFinder(Finder::create()->in([__DIR__.'/src', __DIR__.'/tests']))
10-
->setRules(['@PhpCsFixer' => true, 'phpdoc_align' => false, 'new_with_parentheses' => ['named_class' => false]])
10+
->setRules([
11+
'@PhpCsFixer' => true,
12+
'phpdoc_align' => false,
13+
'new_with_parentheses' => ['named_class' => false],
14+
'ordered_types' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'],
15+
'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'],
16+
])
1117
;

src/Contracts/CrawlContract.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function retrieveResults(
2121
* @param int $depth Maximum crawl depth from starting URL
2222
* @param bool $extractionMode Use AI extraction (true) or markdown conversion (false)
2323
* @param int $maxPages Maximum number of pages to crawl
24-
* @param null|string $prompt Extraction prompt (required if extraction_mode is true)
24+
* @param string|null $prompt Extraction prompt (required if extraction_mode is true)
2525
* @param bool $renderHeavyJs Enable heavy JavaScript rendering
2626
* @param Rules $rules
2727
* @param mixed $schema Output schema for extraction

src/Contracts/FeedbackContract.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ interface FeedbackContract
1212
/**
1313
* @param int $rating Rating score
1414
* @param string $requestID Request to provide feedback for
15-
* @param null|string $feedbackText Optional feedback comments
15+
* @param string|null $feedbackText Optional feedback comments
1616
*/
1717
public function submit(
1818
$rating,

src/Core/Attributes/Api.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,20 @@
1414
final class Api
1515
{
1616
/**
17-
* @var null|class-string<ConverterSource>|Converter|string
17+
* @var class-string<ConverterSource>|Converter|string|null
1818
*/
19-
public readonly null|Converter|string $type;
19+
public readonly Converter|string|null $type;
2020

2121
/**
22-
* @param null|class-string<ConverterSource>|Converter|string $type
23-
* @param null|class-string<ConverterSource>|Converter $enum
24-
* @param null|class-string<ConverterSource>|Converter|string $union
22+
* @param class-string<ConverterSource>|Converter|string|null $type
23+
* @param class-string<ConverterSource>|Converter|null $enum
24+
* @param class-string<ConverterSource>|Converter|string|null $union
2525
*/
2626
public function __construct(
2727
public readonly ?string $apiName = null,
28-
null|Converter|string $type = null,
29-
null|Converter|string $enum = null,
30-
null|Converter|string $union = null,
28+
Converter|string|null $type = null,
29+
Converter|string|null $enum = null,
30+
Converter|string|null $union = null,
3131
public readonly bool $nullable = false,
3232
public readonly bool $optional = false,
3333
) {

src/Core/BaseClient.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class BaseClient
2929
protected ClientInterface $transporter;
3030

3131
/**
32-
* @param array<string, null|int|list<int|string>|string> $headers
32+
* @param array<string, string|int|list<string|int>|null> $headers
3333
*/
3434
public function __construct(
3535
protected array $headers,
@@ -45,13 +45,13 @@ public function __construct(
4545
}
4646

4747
/**
48-
* @param list<mixed>|string $path
48+
* @param string|list<mixed> $path
4949
* @param array<string, mixed> $query
5050
* @param array<string, mixed> $headers
5151
*/
5252
public function request(
5353
string $method,
54-
array|string $path,
54+
string|array $path,
5555
array $query = [],
5656
array $headers = [],
5757
mixed $body = null,
@@ -88,27 +88,27 @@ protected function authHeaders(): array
8888
}
8989

9090
/**
91-
* @param list<string>|string $path
91+
* @param string|list<string> $path
9292
* @param array<string, mixed> $query
93-
* @param array<string, null|int|list<int|string>|string> $headers
94-
* @param null|array{
95-
* timeout?: null|float,
96-
* maxRetries?: null|int,
97-
* initialRetryDelay?: null|float,
98-
* maxRetryDelay?: null|float,
99-
* extraHeaders?: null|list<string>,
100-
* extraQueryParams?: null|list<string>,
101-
* extraBodyParams?: null|list<string>,
102-
* }|RequestOptions $opts
93+
* @param array<string, string|int|list<string|int>|null> $headers
94+
* @param array{
95+
* timeout?: float|null,
96+
* maxRetries?: int|null,
97+
* initialRetryDelay?: float|null,
98+
* maxRetryDelay?: float|null,
99+
* extraHeaders?: list<string>|null,
100+
* extraQueryParams?: list<string>|null,
101+
* extraBodyParams?: list<string>|null,
102+
* }|RequestOptions|null $opts
103103
*
104104
* @return array{RequestInterface, RequestOptions}
105105
*/
106106
protected function buildRequest(
107107
string $method,
108-
array|string $path,
108+
string|array $path,
109109
array $query,
110110
array $headers,
111-
null|array|RequestOptions $opts,
111+
array|RequestOptions|null $opts,
112112
): array {
113113
$opts = [...$this->options->__serialize(), ...RequestOptions::parse($opts)->__serialize()];
114114
$options = new RequestOptions(...$opts);
@@ -119,7 +119,7 @@ protected function buildRequest(
119119
$mergedQuery = array_merge_recursive($query, $options->extraQueryParams);
120120
$uri = Util::joinUri($this->baseUrl, path: $parsedPath, query: $mergedQuery);
121121

122-
/** @var array<string, list<string>|string> $mergedHeaders */
122+
/** @var array<string, string | list<string>> $mergedHeaders */
123123
$mergedHeaders = [...$this->headers,
124124
...$this->authHeaders(),
125125
...$headers,
@@ -146,9 +146,9 @@ protected function followRedirect(
146146
}
147147

148148
/**
149-
* @param null|array<string, mixed>|bool|float|int|resource|string|\Traversable<
149+
* @param bool|int|float|string|array<string, mixed>|resource|\Traversable<
150150
* mixed
151-
* > $data
151+
* >|null $data
152152
*/
153153
protected function sendRequest(
154154
RequestInterface $req,

src/Core/Concerns/SdkParams.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
trait SdkParams
1515
{
1616
/**
17-
* @param null|array<string, mixed>|self $params
18-
* @param null|array<string, mixed>|RequestOptions $options
17+
* @param array<string, mixed>|self|null $params
18+
* @param array<string, mixed>|RequestOptions|null $options
1919
*
2020
* @return array{array<string, mixed>, array{
2121
* timeout: float,
@@ -27,7 +27,7 @@ trait SdkParams
2727
* extraBodyParams: list<string>,
2828
* }}
2929
*/
30-
public static function parseRequest(null|array|self $params, null|array|RequestOptions $options): array
30+
public static function parseRequest(array|self|null $params, array|RequestOptions|null $options): array
3131
{
3232
$converter = self::converter();
3333
$state = new DumpState;

src/Core/Conversion/Concerns/ArrayOf.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
*/
1616
trait ArrayOf
1717
{
18-
private readonly null|Converter|ConverterSource|string $type;
18+
private readonly Converter|ConverterSource|string|null $type;
1919

2020
public function __construct(
21-
null|Converter|ConverterSource|string $type = null,
22-
null|Converter|ConverterSource|string $enum = null,
23-
null|Converter|ConverterSource|string $union = null,
21+
Converter|ConverterSource|string|null $type = null,
22+
Converter|ConverterSource|string|null $enum = null,
23+
Converter|ConverterSource|string|null $union = null,
2424
private readonly bool $nullable = false,
2525
) {
2626
$this->type = $type ?? $enum ?? $union;

src/Core/Conversion/EnumOf.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ final class EnumOf implements Converter
1515
private readonly string $type;
1616

1717
/**
18-
* @param list<null|bool|float|int|string> $members
18+
* @param list<bool|float|int|string|null> $members
1919
*/
2020
public function __construct(private readonly array $members)
2121
{

src/Core/Conversion/PropertyInfo.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ public function __construct(public readonly \ReflectionProperty $property)
4646
}
4747

4848
/**
49-
* @param null|array<int|string,string>|Converter|ConverterSource|\ReflectionType|string $type
49+
* @param array<int|string,string>|Converter|ConverterSource|\ReflectionType|string|null $type
5050
*/
51-
private static function parse(null|array|Converter|ConverterSource|\ReflectionType|string $type): Converter|ConverterSource|string
51+
private static function parse(array|Converter|ConverterSource|\ReflectionType|string|null $type): Converter|ConverterSource|string
5252
{
5353
if (is_string($type) || $type instanceof Converter) {
5454
return $type;

src/Core/Conversion/UnionOf.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function dump(mixed $value, DumpState $state): mixed
7777

7878
private function resolveVariant(
7979
mixed $value,
80-
): null|Converter|ConverterSource|string {
80+
): Converter|ConverterSource|string|null {
8181
if ($value instanceof BaseModel) {
8282
return $value::class;
8383
}

0 commit comments

Comments
 (0)