Skip to content

Commit 1edc10f

Browse files
authored
Merge pull request #1345 from php-api-clients/GitHubEnterpriseCloud/from-1.1.4-ce89601d3b185e31dcb10fd63f1ad656-from-1.1.4-ce89601d3b185e31dcb10fd63f1ad656
2 parents cdbdca0 + c3e87aa commit 1edc10f

File tree

95 files changed

+5301
-241
lines changed

Some content is hidden

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

95 files changed

+5301
-241
lines changed

clients/GitHubEnterpriseCloud/README.md

Lines changed: 366 additions & 6 deletions
Large diffs are not rendered by default.

clients/GitHubEnterpriseCloud/etc/openapi-client-generator.state

Lines changed: 235 additions & 47 deletions
Large diffs are not rendered by default.

clients/GitHubEnterpriseCloud/src/Client.php

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

clients/GitHubEnterpriseCloud/src/ClientInterface.php

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.
Lines changed: 248 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,248 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace ApiClients\Client\GitHubEnterpriseCloud\Internal\Hydrator\Operation\Orgs\Org\Insights\Api;
6+
7+
use ApiClients\Client\GitHubEnterpriseCloud\Schema\ApiInsightsSummaryStats;
8+
use EventSauce\ObjectHydrator\IterableList;
9+
use EventSauce\ObjectHydrator\ObjectMapper;
10+
use EventSauce\ObjectHydrator\PropertySerializers\SerializeArrayItems;
11+
use EventSauce\ObjectHydrator\PropertySerializers\SerializeDateTime;
12+
use EventSauce\ObjectHydrator\PropertySerializers\SerializeUuidToString;
13+
use EventSauce\ObjectHydrator\UnableToHydrateObject;
14+
use EventSauce\ObjectHydrator\UnableToSerializeObject;
15+
use Generator;
16+
use LogicException;
17+
use Throwable;
18+
19+
use function assert;
20+
use function count;
21+
use function is_a;
22+
23+
class SummaryStats implements ObjectMapper
24+
{
25+
private array $hydrationStack = [];
26+
27+
public function __construct()
28+
{
29+
}
30+
31+
/**
32+
* @param class-string<T> $className
33+
*
34+
* @return T
35+
*
36+
* @template T of object
37+
*/
38+
public function hydrateObject(string $className, array $payload): object
39+
{
40+
return match ($className) {
41+
'ApiClients\Client\GitHubEnterpriseCloud\Schema\ApiInsightsSummaryStats' => $this->hydrateApiClients⚡️Client⚡️GitHubEnterpriseCloud⚡️Schema⚡️ApiInsightsSummaryStats($payload),
42+
default => throw UnableToHydrateObject::noHydrationDefined($className, $this->hydrationStack),
43+
};
44+
}
45+
46+
private function hydrateApiClients⚡️Client⚡️GitHubEnterpriseCloud⚡️Schema⚡️ApiInsightsSummaryStats(array $payload): ApiInsightsSummaryStats
47+
{
48+
$properties = [];
49+
$missingFields = [];
50+
try {
51+
$value = $payload['total_request_count'] ?? null;
52+
53+
if ($value === null) {
54+
$properties['totalRequestCount'] = null;
55+
goto after_totalRequestCount;
56+
}
57+
58+
$properties['totalRequestCount'] = $value;
59+
60+
after_totalRequestCount:
61+
62+
$value = $payload['rate_limited_request_count'] ?? null;
63+
64+
if ($value === null) {
65+
$properties['rateLimitedRequestCount'] = null;
66+
goto after_rateLimitedRequestCount;
67+
}
68+
69+
$properties['rateLimitedRequestCount'] = $value;
70+
71+
after_rateLimitedRequestCount:
72+
} catch (Throwable $exception) {
73+
throw UnableToHydrateObject::dueToError('ApiClients\Client\GitHubEnterpriseCloud\Schema\ApiInsightsSummaryStats', $exception, stack: $this->hydrationStack);
74+
}
75+
76+
if (count($missingFields) > 0) {
77+
throw UnableToHydrateObject::dueToMissingFields(ApiInsightsSummaryStats::class, $missingFields, stack: $this->hydrationStack);
78+
}
79+
80+
try {
81+
return new ApiInsightsSummaryStats(...$properties);
82+
} catch (Throwable $exception) {
83+
throw UnableToHydrateObject::dueToError('ApiClients\Client\GitHubEnterpriseCloud\Schema\ApiInsightsSummaryStats', $exception, stack: $this->hydrationStack);
84+
}
85+
}
86+
87+
private function serializeViaTypeMap(string $accessor, object $object, array $payloadToTypeMap): array
88+
{
89+
foreach ($payloadToTypeMap as $payloadType => [$valueType, $method]) {
90+
if (is_a($object, $valueType)) {
91+
return [$accessor => $payloadType] + $this->{$method}($object);
92+
}
93+
}
94+
95+
throw new LogicException('No type mapped for object of class: ' . $object::class);
96+
}
97+
98+
public function serializeObject(object $object): mixed
99+
{
100+
return $this->serializeObjectOfType($object, $object::class);
101+
}
102+
103+
/**
104+
* @param T $object
105+
* @param class-string<T> $className
106+
*
107+
* @template T
108+
*/
109+
public function serializeObjectOfType(object $object, string $className): mixed
110+
{
111+
try {
112+
return match ($className) {
113+
'array' => $this->serializeValuearray($object),
114+
'Ramsey\Uuid\UuidInterface' => $this->serializeValueRamsey⚡️Uuid⚡️UuidInterface($object),
115+
'DateTime' => $this->serializeValueDateTime($object),
116+
'DateTimeImmutable' => $this->serializeValueDateTimeImmutable($object),
117+
'DateTimeInterface' => $this->serializeValueDateTimeInterface($object),
118+
'ApiClients\Client\GitHubEnterpriseCloud\Schema\ApiInsightsSummaryStats' => $this->serializeObjectApiClients⚡️Client⚡️GitHubEnterpriseCloud⚡️Schema⚡️ApiInsightsSummaryStats($object),
119+
default => throw new LogicException("No serialization defined for $className"),
120+
};
121+
} catch (Throwable $exception) {
122+
throw UnableToSerializeObject::dueToError($className, $exception);
123+
}
124+
}
125+
126+
private function serializeValuearray(mixed $value): mixed
127+
{
128+
static $serializer;
129+
130+
if ($serializer === null) {
131+
$serializer = new SerializeArrayItems(...[]);
132+
}
133+
134+
return $serializer->serialize($value, $this);
135+
}
136+
137+
private function serializeValueRamsey⚡️Uuid⚡️UuidInterface(mixed $value): mixed
138+
{
139+
static $serializer;
140+
141+
if ($serializer === null) {
142+
$serializer = new SerializeUuidToString(...[]);
143+
}
144+
145+
return $serializer->serialize($value, $this);
146+
}
147+
148+
private function serializeValueDateTime(mixed $value): mixed
149+
{
150+
static $serializer;
151+
152+
if ($serializer === null) {
153+
$serializer = new SerializeDateTime(...[]);
154+
}
155+
156+
return $serializer->serialize($value, $this);
157+
}
158+
159+
private function serializeValueDateTimeImmutable(mixed $value): mixed
160+
{
161+
static $serializer;
162+
163+
if ($serializer === null) {
164+
$serializer = new SerializeDateTime(...[]);
165+
}
166+
167+
return $serializer->serialize($value, $this);
168+
}
169+
170+
private function serializeValueDateTimeInterface(mixed $value): mixed
171+
{
172+
static $serializer;
173+
174+
if ($serializer === null) {
175+
$serializer = new SerializeDateTime(...[]);
176+
}
177+
178+
return $serializer->serialize($value, $this);
179+
}
180+
181+
private function serializeObjectApiClients⚡️Client⚡️GitHubEnterpriseCloud⚡️Schema⚡️ApiInsightsSummaryStats(mixed $object): mixed
182+
{
183+
assert($object instanceof ApiInsightsSummaryStats);
184+
$result = [];
185+
186+
$totalRequestCount = $object->totalRequestCount;
187+
188+
if ($totalRequestCount === null) {
189+
goto after_totalRequestCount;
190+
}
191+
192+
after_totalRequestCount: $result['total_request_count'] = $totalRequestCount;
193+
194+
$rateLimitedRequestCount = $object->rateLimitedRequestCount;
195+
196+
if ($rateLimitedRequestCount === null) {
197+
goto after_rateLimitedRequestCount;
198+
}
199+
200+
after_rateLimitedRequestCount: $result['rate_limited_request_count'] = $rateLimitedRequestCount;
201+
202+
return $result;
203+
}
204+
205+
/**
206+
* @param class-string<T> $className
207+
* @param iterable<array> $payloads;
208+
*
209+
* @return IterableList<T>
210+
*
211+
* @throws UnableToHydrateObject
212+
*
213+
* @template T
214+
*/
215+
public function hydrateObjects(string $className, iterable $payloads): IterableList
216+
{
217+
return new IterableList($this->doHydrateObjects($className, $payloads));
218+
}
219+
220+
private function doHydrateObjects(string $className, iterable $payloads): Generator
221+
{
222+
foreach ($payloads as $index => $payload) {
223+
yield $index => $this->hydrateObject($className, $payload);
224+
}
225+
}
226+
227+
/**
228+
* @param class-string<T> $className
229+
* @param iterable<array> $payloads;
230+
*
231+
* @return IterableList<T>
232+
*
233+
* @throws UnableToSerializeObject
234+
*
235+
* @template T
236+
*/
237+
public function serializeObjects(iterable $payloads): IterableList
238+
{
239+
return new IterableList($this->doSerializeObjects($payloads));
240+
}
241+
242+
private function doSerializeObjects(iterable $objects): Generator
243+
{
244+
foreach ($objects as $index => $object) {
245+
yield $index => $this->serializeObject($object);
246+
}
247+
}
248+
}

0 commit comments

Comments
 (0)