![]() Server : Apache/2.4.62 (Unix) OpenSSL/1.0.2k-fips System : Linux server1.richineiserver.com 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64 User : fdshops ( 1003) PHP Version : 8.2.21 Disable Function : NONE Directory : /home/fdshops/public_html/vendor/knuckleswtf/scribe/src/Extracting/Shared/ |
<?php namespace Knuckles\Scribe\Extracting\Shared; use Knuckles\Camel\Extraction\ExtractedEndpointData; use Knuckles\Camel\Extraction\Response; use Knuckles\Scribe\Extracting\ParamHelpers; use stdClass; class ResponseFieldTools { use ParamHelpers; public static function inferTypeOfResponseField(array $data, ExtractedEndpointData $endpointData): string { if (!empty($data['type'])) { return self::normalizeTypeName($data['type']); } // Try to get a type from first 2xx response $validResponse = collect($endpointData->responses)->first( fn(Response $r) => $r->status >= 200 && $r->status < 300 ); if ($validResponse && ($validResponseContent = json_decode($validResponse->content, true))) { $nonexistent = new stdClass(); $value = $validResponseContent[$data['name']] ?? $validResponseContent['data'][$data['name']] // Maybe it's a Laravel ApiResource ?? $validResponseContent[0][$data['name']] // Maybe it's a list ?? $validResponseContent['data'][0][$data['name']] // Maybe an Api Resource Collection? ?? $nonexistent; if ($value !== $nonexistent) { return self::normalizeTypeName(gettype($value), $value); } } return ""; } }