Skip to content

Commit 323e828

Browse files
authored
feat: bump from latest generator (#5)
* Update from Infra files * Update from latest generator
1 parent 2a23c55 commit 323e828

25 files changed

+538
-394
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ For more information, please visit [https://ssl.reddit.com/dev/api](https://ssl.
88

99
### Requirements
1010

11-
PHP 7.4 and later.
12-
Should also work with PHP 8.0.
11+
PHP 8.1 and later.
1312

1413
### Composer
1514

@@ -120,4 +119,5 @@ [email protected]
120119
This PHP package is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project:
121120

122121
- API version: `1.1.0`
122+
- Generator version: `7.13.0-SNAPSHOT`
123123
- Build package: `org.openapitools.codegen.languages.PhpClientCodegen`

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
"guzzlehttp/psr7": "^2.0"
2727
},
2828
"require-dev": {
29-
"phpunit/phpunit": "^9.0",
30-
"sigwin/infra": "~1.5.0"
29+
"phpunit/phpunit": "^12.1.0",
30+
"sigwin/infra": "~1.16.0"
3131
},
3232
"autoload": {
3333
"psr-4": {

infection.json.dist

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"source": {
3+
"directories": [
4+
"src"
5+
]
6+
},
7+
"logs": {
8+
"text": "var/phpqa/infection.log"
9+
},
10+
"minCoveredMsi": 100,
11+
"mutators": {
12+
"@default": true,
13+
"IdenticalEqual": false,
14+
"NotIdenticalNotEqual": false,
15+
"MBString": false
16+
}
17+
}

phpunit.xml.dist

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,28 @@
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
33
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
44
beStrictAboutChangesToGlobalState="true"
5-
beStrictAboutCoversAnnotation="true"
5+
beStrictAboutCoverageMetadata="true"
66
beStrictAboutOutputDuringTests="true"
7-
beStrictAboutResourceUsageDuringSmallTests="true"
8-
beStrictAboutTodoAnnotatedTests="true"
97
bootstrap="./vendor/autoload.php"
10-
cacheResultFile="var/phpqa/phpunit.result.cache"
8+
cacheDirectory="var/phpqa/phpunit"
119
colors="true"
12-
convertDeprecationsToExceptions="true"
10+
displayDetailsOnPhpunitDeprecations="true"
11+
displayDetailsOnTestsThatTriggerDeprecations="true"
12+
displayDetailsOnTestsThatTriggerErrors="true"
13+
displayDetailsOnTestsThatTriggerNotices="true"
14+
displayDetailsOnTestsThatTriggerWarnings="true"
1315
enforceTimeLimit="true"
1416
executionOrder="random"
1517
failOnEmptyTestSuite="true"
1618
failOnRisky="true"
1719
failOnWarning="true"
18-
forceCoversAnnotation="true"
19-
verbose="true">
20-
<coverage processUncoveredFiles="true">
20+
requireCoverageMetadata="true">
21+
<coverage/>
22+
<source>
2123
<include>
22-
<directory suffix=".php">./src</directory>
24+
<directory>./src</directory>
2325
</include>
24-
</coverage>
26+
</source>
2527
<testsuites>
2628
<testsuite name="Suite">
2729
<directory>./tests</directory>

src/Api/ThingApi.php

Lines changed: 75 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
use GuzzleHttp\Psr7\MultipartStream;
2727
use GuzzleHttp\Psr7\Request;
2828
use GuzzleHttp\RequestOptions;
29+
use Psr\Http\Message\RequestInterface;
30+
use Psr\Http\Message\ResponseInterface;
2931
use Sigwin\RedditClient\ApiException;
3032
use Sigwin\RedditClient\Configuration;
3133
use Sigwin\RedditClient\HeaderSelector;
@@ -70,19 +72,16 @@ final class ThingApi
7072
];
7173

7274
/**
73-
* @param ClientInterface $client
74-
* @param Configuration $config
75-
* @param HeaderSelector $selector
76-
* @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec
75+
* @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec
7776
*/
7877
public function __construct(
79-
ClientInterface $client = null,
80-
Configuration $config = null,
81-
HeaderSelector $selector = null,
82-
$hostIndex = 0
78+
?ClientInterface $client = null,
79+
?Configuration $config = null,
80+
?HeaderSelector $selector = null,
81+
int $hostIndex = 0,
8382
) {
8483
$this->client = $client ?: new Client();
85-
$this->config = $config ?: new Configuration();
84+
$this->config = $config ?: Configuration::getDefaultConfiguration();
8685
$this->headerSelector = $selector ?: new HeaderSelector();
8786
$this->hostIndex = $hostIndex;
8887
}
@@ -117,12 +116,12 @@ public function getConfig(): Configuration
117116
*
118117
* Get thing info
119118
*
120-
* @param string $id id (optional)
121-
* @param string $sr_name sr_name (optional)
122-
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['getInfo'] to see the possible values for this operation
119+
* @param null|string $id id (optional)
120+
* @param null|string $sr_name sr_name (optional)
121+
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['getInfo'] to see the possible values for this operation
123122
*
124123
* @throws \InvalidArgumentException
125-
* @throws \Sigwin\RedditClient\ApiException on non-2xx response
124+
* @throws ApiException on non-2xx response or if the response body is not in the expected format
126125
*/
127126
public function getInfo($id = null, $sr_name = null, string $contentType = self::contentTypes['getInfo'][0]): \Sigwin\RedditClient\Model\ListingEnvelope
128127
{
@@ -136,14 +135,14 @@ public function getInfo($id = null, $sr_name = null, string $contentType = self:
136135
*
137136
* Get thing info
138137
*
139-
* @param string $id (optional)
140-
* @param string $sr_name (optional)
141-
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['getInfo'] to see the possible values for this operation
138+
* @param null|string $id (optional)
139+
* @param null|string $sr_name (optional)
140+
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['getInfo'] to see the possible values for this operation
142141
*
143142
* @return array of \Sigwin\RedditClient\Model\ListingEnvelope, HTTP status code, HTTP response headers (array of strings)
144143
*
145144
* @throws \InvalidArgumentException
146-
* @throws \Sigwin\RedditClient\ApiException on non-2xx response
145+
* @throws ApiException on non-2xx response or if the response body is not in the expected format
147146
*/
148147
public function getInfoWithHttpInfo($id = null, $sr_name = null, string $contentType = self::contentTypes['getInfo'][0]): array
149148
{
@@ -161,43 +160,24 @@ public function getInfoWithHttpInfo($id = null, $sr_name = null, string $content
161160

162161
$statusCode = $response->getStatusCode();
163162

164-
if ($statusCode < 200 || $statusCode > 299) {
165-
throw new ApiException(sprintf('[%d] Error connecting to the API (%s)', $statusCode, (string) $request->getUri()), $statusCode, $response->getHeaders(), (string) $response->getBody());
166-
}
167-
168163
switch ($statusCode) {
169164
case 200:
170-
if ('\Sigwin\RedditClient\Model\ListingEnvelope' === '\SplFileObject') {
171-
$content = $response->getBody(); // stream goes to serializer
172-
} else {
173-
$content = (string) $response->getBody();
174-
if ('\Sigwin\RedditClient\Model\ListingEnvelope' !== 'string') {
175-
$content = json_decode($content);
176-
}
177-
}
178-
179-
return [
180-
ObjectSerializer::deserialize($content, '\Sigwin\RedditClient\Model\ListingEnvelope', []),
181-
$response->getStatusCode(),
182-
$response->getHeaders(),
183-
];
165+
return $this->handleResponseWithDataType(
166+
'\Sigwin\RedditClient\Model\ListingEnvelope',
167+
$request,
168+
$response,
169+
);
184170
}
185171

186-
$returnType = '\Sigwin\RedditClient\Model\ListingEnvelope';
187-
if ($returnType === '\SplFileObject') {
188-
$content = $response->getBody(); // stream goes to serializer
189-
} else {
190-
$content = (string) $response->getBody();
191-
if ($returnType !== 'string') {
192-
$content = json_decode($content);
193-
}
172+
if ($statusCode < 200 || $statusCode > 299) {
173+
throw new ApiException(\sprintf('[%d] Error connecting to the API (%s)', $statusCode, (string) $request->getUri()), $statusCode, $response->getHeaders(), (string) $response->getBody());
194174
}
195175

196-
return [
197-
ObjectSerializer::deserialize($content, $returnType, []),
198-
$response->getStatusCode(),
199-
$response->getHeaders(),
200-
];
176+
return $this->handleResponseWithDataType(
177+
'\Sigwin\RedditClient\Model\ListingEnvelope',
178+
$request,
179+
$response,
180+
);
201181
} catch (ApiException $e) {
202182
switch ($e->getCode()) {
203183
case 200:
@@ -207,8 +187,9 @@ public function getInfoWithHttpInfo($id = null, $sr_name = null, string $content
207187
$e->getResponseHeaders()
208188
);
209189
$e->setResponseObject($data);
210-
break;
190+
throw $e;
211191
}
192+
212193
throw $e;
213194
}
214195
}
@@ -218,9 +199,9 @@ public function getInfoWithHttpInfo($id = null, $sr_name = null, string $content
218199
*
219200
* Get thing info
220201
*
221-
* @param string $id (optional)
222-
* @param string $sr_name (optional)
223-
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['getInfo'] to see the possible values for this operation
202+
* @param null|string $id (optional)
203+
* @param null|string $sr_name (optional)
204+
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['getInfo'] to see the possible values for this operation
224205
*
225206
* @throws \InvalidArgumentException
226207
*/
@@ -240,9 +221,9 @@ static function ($response) {
240221
*
241222
* Get thing info
242223
*
243-
* @param string $id (optional)
244-
* @param string $sr_name (optional)
245-
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['getInfo'] to see the possible values for this operation
224+
* @param null|string $id (optional)
225+
* @param null|string $sr_name (optional)
226+
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['getInfo'] to see the possible values for this operation
246227
*
247228
* @throws \InvalidArgumentException
248229
*/
@@ -273,7 +254,7 @@ static function ($response) use ($returnType) {
273254
static function ($exception): void {
274255
$response = $exception->getResponse();
275256
$statusCode = $response->getStatusCode();
276-
throw new ApiException(sprintf('[%d] Error connecting to the API (%s)', $statusCode, $exception->getRequest()->getUri()), $statusCode, $response->getHeaders(), (string) $response->getBody());
257+
throw new ApiException(\sprintf('[%d] Error connecting to the API (%s)', $statusCode, $exception->getRequest()->getUri()), $statusCode, $response->getHeaders(), (string) $response->getBody());
277258
}
278259
)
279260
;
@@ -282,9 +263,9 @@ static function ($exception): void {
282263
/**
283264
* Create request for operation 'getInfo'.
284265
*
285-
* @param string $id (optional)
286-
* @param string $sr_name (optional)
287-
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['getInfo'] to see the possible values for this operation
266+
* @param null|string $id (optional)
267+
* @param null|string $sr_name (optional)
268+
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['getInfo'] to see the possible values for this operation
288269
*
289270
* @throws \InvalidArgumentException
290271
*/
@@ -392,4 +373,39 @@ private function createHttpClientOption(): array
392373

393374
return $options;
394375
}
376+
377+
private function handleResponseWithDataType(
378+
string $dataType,
379+
RequestInterface $request,
380+
ResponseInterface $response,
381+
): array {
382+
if ($dataType === '\SplFileObject') {
383+
$content = $response->getBody(); // stream goes to serializer
384+
} else {
385+
$content = (string) $response->getBody();
386+
if ($dataType !== 'string') {
387+
try {
388+
$content = json_decode($content, false, 512, \JSON_THROW_ON_ERROR);
389+
} catch (\JsonException $exception) {
390+
throw new ApiException(\sprintf('Error JSON decoding server response (%s)', $request->getUri()), $response->getStatusCode(), $response->getHeaders(), $content);
391+
}
392+
}
393+
}
394+
395+
return [
396+
ObjectSerializer::deserialize($content, $dataType, []),
397+
$response->getStatusCode(),
398+
$response->getHeaders(),
399+
];
400+
}
401+
402+
private function responseWithinRangeCode(
403+
string $rangeCode,
404+
int $statusCode,
405+
): bool {
406+
$left = (int) ($rangeCode[0].'00');
407+
$right = (int) ($rangeCode[0].'99');
408+
409+
return $statusCode >= $left && $statusCode <= $right;
410+
}
395411
}

0 commit comments

Comments
 (0)