From 50fbe5dfebbe02573f73df5c190512a0e566784d Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sat, 31 Jan 2026 12:35:52 +0000 Subject: [PATCH 01/40] feat: support unwrapping envelopes --- src/Client.php | 7 ++-- src/Core/BaseClient.php | 54 ++----------------------- src/Core/Implementation/RawResponse.php | 12 ++++-- src/Core/Util.php | 26 ++++++++++++ 4 files changed, 42 insertions(+), 57 deletions(-) diff --git a/src/Client.php b/src/Client.php index be2f97b..3c0b934 100644 --- a/src/Client.php +++ b/src/Client.php @@ -7,6 +7,7 @@ use Http\Discovery\Psr17FactoryDiscovery; use Http\Discovery\Psr18ClientDiscovery; use ModerationAPI\Core\BaseClient; +use ModerationAPI\Core\Util; use ModerationAPI\Services\AccountService; use ModerationAPI\Services\ActionsService; use ModerationAPI\Services\AuthorsService; @@ -77,9 +78,9 @@ public function __construct(?string $secretKey = null, ?string $baseUrl = null) 'User-Agent' => sprintf('moderation-api/PHP %s', '0.3.0'), 'X-Stainless-Lang' => 'php', 'X-Stainless-Package-Version' => '0.3.0', - 'X-Stainless-OS' => $this->getNormalizedOS(), - 'X-Stainless-Arch' => $this->getNormalizedArchitecture(), - 'X-Stainless-Runtime' => 'php', + 'X-Stainless-Arch' => Util::machtype(), + 'X-Stainless-OS' => Util::ostype(), + 'X-Stainless-Runtime' => php_sapi_name(), 'X-Stainless-Runtime-Version' => phpversion(), ], // x-release-please-end diff --git a/src/Core/BaseClient.php b/src/Core/BaseClient.php index f128692..387118e 100644 --- a/src/Core/BaseClient.php +++ b/src/Core/BaseClient.php @@ -53,6 +53,7 @@ public function __construct( * @param string|list $path * @param array $query * @param array $headers + * @param string|int|list|null $unwrap * @param class-string>|null $page * @param class-string>|null $stream * @param RequestOptions|array|null $options @@ -65,6 +66,7 @@ public function request( array $query = [], array $headers = [], mixed $body = null, + string|int|array|null $unwrap = null, string|Converter|ConverterSource|null $convert = null, ?string $page = null, ?string $stream = null, @@ -82,62 +84,12 @@ public function request( $rsp = $this->sendRequest($opts, req: $request, data: $body, redirectCount: 0, retryCount: 0); // @phpstan-ignore-next-line argument.type - return new RawResponse(client: $this, request: $request, response: $rsp, options: $opts, requestInfo: $req, stream: $stream, page: $page, convert: $convert ?? 'null'); + return new RawResponse(client: $this, request: $request, response: $rsp, options: $opts, requestInfo: $req, unwrap: $unwrap, stream: $stream, page: $page, convert: $convert ?? 'null'); } /** @return array */ abstract protected function authHeaders(): array; - protected function getNormalizedOS(): string - { - $os = strtolower(PHP_OS_FAMILY); - - switch ($os) { - case 'windows': - return 'Windows'; - - case 'darwin': - return 'MacOS'; - - case 'linux': - return 'Linux'; - - case 'bsd': - case 'freebsd': - case 'openbsd': - return 'BSD'; - - case 'solaris': - return 'Solaris'; - - case 'unix': - case 'unknown': - return 'Unknown'; - - default: - return 'Other:'.$os; - } - } - - protected function getNormalizedArchitecture(): string - { - $arch = php_uname('m'); - if (false !== strpos($arch, 'x86_64') || false !== strpos($arch, 'amd64')) { - return 'x64'; - } - if (false !== strpos($arch, 'i386') || false !== strpos($arch, 'i686')) { - return 'x32'; - } - if (false !== strpos($arch, 'aarch64') || false !== strpos($arch, 'arm64')) { - return 'arm64'; - } - if (false !== strpos($arch, 'arm')) { - return 'arm'; - } - - return 'unknown'; - } - /** * @internal * diff --git a/src/Core/Implementation/RawResponse.php b/src/Core/Implementation/RawResponse.php index 6fa68bb..804ff12 100644 --- a/src/Core/Implementation/RawResponse.php +++ b/src/Core/Implementation/RawResponse.php @@ -2,7 +2,7 @@ namespace ModerationAPI\Core\Implementation; -use ModerationAPI\Client; +use ModerationAPI\Core\BaseClient; use ModerationAPI\Core\Concerns\ResponseProxy; use ModerationAPI\Core\Contracts\BaseResponse; use ModerationAPI\Core\Conversion; @@ -36,13 +36,15 @@ class RawResponse implements BaseResponse /** * @param normalized_request $requestInfo + * @param list|string|int|null $unwrap */ public function __construct( - private Client $client, + private BaseClient $client, private RequestOptions $options, private RequestInterface $request, private ResponseInterface $response, private array $requestInfo, + private array|string|int|null $unwrap, private Converter|ConverterSource|string $convert, private ?string $page, private ?string $stream, @@ -91,7 +93,11 @@ public function parse(): mixed private function getDecoded(): mixed { if (!$this->decoded) { - $this->decodedBody = Util::decodeContent($this->response); + $decoded = Util::decodeContent($this->response); + if (!is_null($this->unwrap)) { + $decoded = Util::dig($decoded, key: $this->unwrap); + } + $this->decodedBody = $decoded; $this->decoded = true; } diff --git a/src/Core/Util.php b/src/Core/Util.php index 2941ab3..dd19c2f 100644 --- a/src/Core/Util.php +++ b/src/Core/Util.php @@ -33,6 +33,32 @@ public static function get_object_vars(object $object): array return get_object_vars($object); } + public static function machtype(): string + { + $arch = php_uname('m'); + + return match (true) { + str_contains($arch, 'aarch64'), str_contains($arch, 'arm64') => 'arm64', + str_contains($arch, 'x86_64'), str_contains($arch, 'amd64') => 'x64', + str_contains($arch, 'i386'), str_contains($arch, 'i686') => 'x32', + str_contains($arch, 'arm') => 'arm', + default => 'unknown', + }; + } + + public static function ostype(): string + { + return match ($os = strtolower(PHP_OS_FAMILY)) { + 'linux' => 'Linux', + 'darwin' => 'MacOS', + 'windows' => 'Windows', + 'solaris' => 'Solaris', + // @phpstan-ignore-next-line match.alwaysFalse + 'bsd', 'freebsd', 'openbsd' => 'BSD', + default => "Other:{$os}", + }; + } + /** * @template T * From 8b350ba2b06ecf19174392a8b9b8bcc0b1a500c0 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 11 Dec 2025 07:04:35 +0000 Subject: [PATCH 02/40] fix: correctly serialize dates --- src/Core/Conversion.php | 2 +- src/Core/Util.php | 16 ++++++++++++++-- src/Services/Queue/ItemsRawService.php | 4 ++-- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/Core/Conversion.php b/src/Core/Conversion.php index 5650fb4..17c4298 100644 --- a/src/Core/Conversion.php +++ b/src/Core/Conversion.php @@ -30,7 +30,7 @@ public static function dump_unknown(mixed $value, DumpState $state): mixed } if (is_a($value, class: \DateTimeInterface::class)) { - return $value->format(format: \DateTimeInterface::RFC3339); + return date_format($value, format: \DateTimeInterface::RFC3339); } if (is_a($value, class: \JsonSerializable::class)) { diff --git a/src/Core/Util.php b/src/Core/Util.php index dd19c2f..9d7672c 100644 --- a/src/Core/Util.php +++ b/src/Core/Util.php @@ -127,8 +127,9 @@ public static function parsePath(string|array $path): string } [$template] = $path; + $mapped = array_map(static fn ($s) => self::rawUrlEncode($s), array: array_slice($path, 1)); - return sprintf($template, ...array_map('rawurlencode', array: array_slice($path, 1))); + return sprintf($template, ...$mapped); } /** @@ -381,6 +382,17 @@ public static function prettyEncodeJson(mixed $obj): string return json_encode($obj, flags: JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT) ?: ''; } + private static function rawUrlEncode( + string|int|\DateTimeInterface $value + ): string { + // @phpstan-ignore-next-line function.alreadyNarrowedType + if (is_object($value) && is_a($value, class: \DateTimeInterface::class)) { + $value = date_format($value, format: \DateTimeInterface::RFC3339); + } + + return rawurlencode((string) $value); + } + /** * @param list $closing * @@ -429,7 +441,7 @@ private static function writeMultipartChunk( yield 'Content-Disposition: form-data'; if (!is_null($key)) { - $name = rawurlencode($key); + $name = self::rawUrlEncode($key); yield "; name=\"{$name}\""; } diff --git a/src/Services/Queue/ItemsRawService.php b/src/Services/Queue/ItemsRawService.php index ace5c57..b4c705d 100644 --- a/src/Services/Queue/ItemsRawService.php +++ b/src/Services/Queue/ItemsRawService.php @@ -106,7 +106,7 @@ public function resolve( return $this->client->request( method: 'post', path: ['queue/%1$s/items/%2$s/resolve', $id, $itemID], - body: (object) array_diff_key($parsed, ['id']), + body: (object) array_diff_key($parsed, array_flip(['id'])), options: $options, convert: ItemResolveResponse::class, ); @@ -140,7 +140,7 @@ public function unresolve( return $this->client->request( method: 'post', path: ['queue/%1$s/items/%2$s/unresolve', $id, $itemID], - body: (object) array_diff_key($parsed, ['id']), + body: (object) array_diff_key($parsed, array_flip(['id'])), options: $options, convert: ItemUnresolveResponse::class, ); From 4a4332385de4fd74a5b6d6499fc915d6ad3b5ade Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 11 Dec 2025 07:05:31 +0000 Subject: [PATCH 03/40] fix: a number of serialization errors --- src/Core/BaseClient.php | 4 +- src/Core/Concerns/SdkEnum.php | 3 +- src/Core/Concerns/SdkModel.php | 50 +++++++++----- src/Core/Concerns/SdkPage.php | 9 --- src/Core/Concerns/SdkParams.php | 6 +- src/Core/Concerns/SdkUnion.php | 2 +- src/Core/Conversion/ListOf.php | 3 +- src/Core/Conversion/ModelOf.php | 3 +- src/Core/Conversion/PropertyInfo.php | 3 +- src/Core/Util.php | 62 ++++++++++++----- src/Services/Actions/ExecuteService.php | 37 ++++++----- src/Services/ActionsService.php | 69 ++++++++++--------- src/Services/AuthorsService.php | 73 +++++++++++---------- src/Services/ContentService.php | 27 ++++---- src/Services/Queue/ItemsService.php | 39 +++++------ src/Services/QueueService.php | 5 +- src/Services/Wordlist/WordsService.php | 5 +- src/Services/WordlistService.php | 19 +++--- tests/Core/{TestModel.php => ModelTest.php} | 22 +++---- tests/Core/UtilTest.php | 39 +++++++++++ 20 files changed, 281 insertions(+), 199 deletions(-) rename tests/Core/{TestModel.php => ModelTest.php} (91%) create mode 100644 tests/Core/UtilTest.php diff --git a/src/Core/BaseClient.php b/src/Core/BaseClient.php index 387118e..68c8e03 100644 --- a/src/Core/BaseClient.php +++ b/src/Core/BaseClient.php @@ -74,14 +74,14 @@ public function request( ): BaseResponse { // @phpstan-ignore-next-line [$req, $opts] = $this->buildRequest(method: $method, path: $path, query: $query, headers: $headers, body: $body, opts: $options); - ['method' => $method, 'path' => $uri, 'headers' => $headers] = $req; + ['method' => $method, 'path' => $uri, 'headers' => $headers, 'body' => $data] = $req; assert(!is_null($opts->requestFactory)); $request = $opts->requestFactory->createRequest($method, uri: $uri); $request = Util::withSetHeaders($request, headers: $headers); // @phpstan-ignore-next-line argument.type - $rsp = $this->sendRequest($opts, req: $request, data: $body, redirectCount: 0, retryCount: 0); + $rsp = $this->sendRequest($opts, req: $request, data: $data, redirectCount: 0, retryCount: 0); // @phpstan-ignore-next-line argument.type return new RawResponse(client: $this, request: $request, response: $rsp, options: $opts, requestInfo: $req, unwrap: $unwrap, stream: $stream, page: $page, convert: $convert ?? 'null'); diff --git a/src/Core/Concerns/SdkEnum.php b/src/Core/Concerns/SdkEnum.php index fe8f9a8..f6aa0a5 100644 --- a/src/Core/Concerns/SdkEnum.php +++ b/src/Core/Concerns/SdkEnum.php @@ -28,6 +28,7 @@ public static function converter(): Converter } } - return static::$converter = new EnumOf($acc); // @phpstan-ignore-line + // @phpstan-ignore-next-line return.type + return static::$converter = new EnumOf($acc); } } diff --git a/src/Core/Concerns/SdkModel.php b/src/Core/Concerns/SdkModel.php index 051ac02..d163f28 100644 --- a/src/Core/Concerns/SdkModel.php +++ b/src/Core/Concerns/SdkModel.php @@ -32,7 +32,7 @@ trait SdkModel */ public function __serialize(): array { - $properties = $this->toProperties(); // @phpstan-ignore-line + $properties = $this->toProperties(); return array_map(static fn ($v) => self::serialize($v), array: $properties); } @@ -45,7 +45,8 @@ public function __serialize(): array public function __unserialize(array $data): void { foreach ($data as $key => $value) { - $this->offsetSet($key, value: $value); // @phpstan-ignore-line + // @phpstan-ignore-next-line argument.type + $this->offsetSet($key, value: $value); } } @@ -94,7 +95,8 @@ public function __get(string $key): mixed // An optional property which was unset to be omitted from serialized is being accessed. // Return null to match user's expectations. - return null; // @phpstan-ignore-line + // @phpstan-ignore-next-line return.type + return null; } /** @@ -104,7 +106,8 @@ public function __get(string $key): mixed */ public function toProperties(): array { - return [...Util::get_object_vars($this), ...$this->_data]; // @phpstan-ignore-line + // @phpstan-ignore-next-line return.type + return [...Util::get_object_vars($this), ...$this->_data]; } /** @@ -114,7 +117,8 @@ public function toProperties(): array */ public function offsetExists(mixed $offset): bool { - if (!is_string($offset)) { // @phpstan-ignore-line + // @phpstan-ignore-next-line function.alreadyNarrowedType + if (!is_string($offset)) { throw new \InvalidArgumentException; } @@ -142,19 +146,24 @@ public function offsetExists(mixed $offset): bool */ public function &offsetGet(mixed $offset): mixed { - if (!is_string($offset)) { // @phpstan-ignore-line + // @phpstan-ignore-next-line function.alreadyNarrowedType + if (!is_string($offset)) { throw new \InvalidArgumentException; } - if (!$this->offsetExists($offset)) { // @phpstan-ignore-line - return null; // @phpstan-ignore-line + // @phpstan-ignore-next-line function.alreadyNarrowedType + if (!$this->offsetExists($offset)) { + // @phpstan-ignore-next-line return.type + return null; } if (array_key_exists($offset, array: $this->_data)) { - return $this->_data[$offset]; // @phpstan-ignore-line + // @phpstan-ignore-next-line return.type + return $this->_data[$offset]; } - return $this->{$offset}; // @phpstan-ignore-line + // @phpstan-ignore-next-line return.type + return $this->{$offset}; } /** @@ -164,7 +173,8 @@ public function &offsetGet(mixed $offset): mixed */ public function offsetSet(mixed $offset, mixed $value): void { - if (!is_string($offset)) { // @phpstan-ignore-line + // @phpstan-ignore-next-line function.alreadyNarrowedType + if (!is_string($offset)) { throw new \InvalidArgumentException; } @@ -174,13 +184,16 @@ public function offsetSet(mixed $offset, mixed $value): void $coerced = Conversion::coerce($type, value: $value, state: new CoerceState(translateNames: false)); - if (property_exists($this, property: $offset)) { // @phpstan-ignore-line + // @phpstan-ignore-next-line function.alreadyNarrowedType + if (property_exists($this, property: $offset)) { try { - $this->{$offset} = $coerced; // @phpstan-ignore-line + // @phpstan-ignore-next-line assign.propertyType + $this->{$offset} = $coerced; unset($this->_data[$offset]); return; - } catch (\TypeError) { // @phpstan-ignore-line + // @phpstan-ignore-next-line catch.neverThrown + } catch (\TypeError) { unset($this->{$offset}); } } @@ -195,11 +208,13 @@ public function offsetSet(mixed $offset, mixed $value): void */ public function offsetUnset(mixed $offset): void { - if (!is_string($offset)) { // @phpstan-ignore-line + // @phpstan-ignore-next-line function.alreadyNarrowedType + if (!is_string($offset)) { throw new \InvalidArgumentException; } - if (property_exists($this, property: $offset)) { // @phpstan-ignore-line + // @phpstan-ignore-next-line function.alreadyNarrowedType + if (property_exists($this, property: $offset)) { unset($this->{$offset}); } @@ -222,7 +237,8 @@ public function jsonSerialize(): array */ public static function fromArray(array $data): static { - return self::converter()->from($data); // @phpstan-ignore-line + // @phpstan-ignore-next-line argument.type + return self::converter()->from($data); } /** diff --git a/src/Core/Concerns/SdkPage.php b/src/Core/Concerns/SdkPage.php index 930c307..c7fd3c7 100644 --- a/src/Core/Concerns/SdkPage.php +++ b/src/Core/Concerns/SdkPage.php @@ -91,15 +91,6 @@ public function pagingEachItem(): \Generator } } - /** - * @internal - * - * @param array $data - * - * @return static - */ - abstract public static function fromArray(array $data): static; - /** * @internal * diff --git a/src/Core/Concerns/SdkParams.php b/src/Core/Concerns/SdkParams.php index f2360a1..62518a2 100644 --- a/src/Core/Concerns/SdkParams.php +++ b/src/Core/Concerns/SdkParams.php @@ -25,12 +25,14 @@ public static function parseRequest(mixed $params, array|RequestOptions|null $op $converter = self::converter(); $state = new DumpState; $dumped = (array) Conversion::dump($converter, value: $value, state: $state); - $opts = RequestOptions::parse($options); // @phpstan-ignore-line + // @phpstan-ignore-next-line argument.type + $opts = RequestOptions::parse($options); if (!$state->canRetry) { $opts->maxRetries = 0; } - return [$dumped, $opts]; // @phpstan-ignore-line + // @phpstan-ignore-next-line return.type + return [$dumped, $opts]; } } diff --git a/src/Core/Concerns/SdkUnion.php b/src/Core/Concerns/SdkUnion.php index 0da2ba6..0f706ae 100644 --- a/src/Core/Concerns/SdkUnion.php +++ b/src/Core/Concerns/SdkUnion.php @@ -15,7 +15,7 @@ trait SdkUnion { private static Converter $converter; - public static function discriminator(): ?string // @phpstan-ignore-line + public static function discriminator(): ?string { return null; } diff --git a/src/Core/Conversion/ListOf.php b/src/Core/Conversion/ListOf.php index 471db56..44111a2 100644 --- a/src/Core/Conversion/ListOf.php +++ b/src/Core/Conversion/ListOf.php @@ -14,7 +14,8 @@ final class ListOf implements Converter { use ArrayOf; - private function empty(): array|object // @phpstan-ignore-line + // @phpstan-ignore-next-line missingType.iterableValue + private function empty(): array|object { return []; } diff --git a/src/Core/Conversion/ModelOf.php b/src/Core/Conversion/ModelOf.php index 03abb1a..190c76c 100644 --- a/src/Core/Conversion/ModelOf.php +++ b/src/Core/Conversion/ModelOf.php @@ -91,7 +91,8 @@ public function coerce(mixed $value, CoerceState $state): mixed $acc[$name] = $item; } - return $this->from($acc); // @phpstan-ignore-line + // @phpstan-ignore-next-line return.type + return $this->from($acc); } public function dump(mixed $value, DumpState $state): mixed diff --git a/src/Core/Conversion/PropertyInfo.php b/src/Core/Conversion/PropertyInfo.php index 0f700c9..b7ca023 100644 --- a/src/Core/Conversion/PropertyInfo.php +++ b/src/Core/Conversion/PropertyInfo.php @@ -57,7 +57,8 @@ private static function parse(array|Converter|ConverterSource|\ReflectionType|st } if (is_array($type)) { - return new UnionOf($type); // @phpstan-ignore-line + // @phpstan-ignore-next-line return.type + return new UnionOf($type); } if ($type instanceof \ReflectionUnionType) { diff --git a/src/Core/Util.php b/src/Core/Util.php index 9d7672c..c48f9ca 100644 --- a/src/Core/Util.php +++ b/src/Core/Util.php @@ -87,6 +87,29 @@ public static function array_filter_omit(array $arr): array return array_filter($arr, fn ($v, $_) => OMIT !== $v, mode: ARRAY_FILTER_USE_BOTH); } + /** + * @param callable $callback + */ + public static function mapRecursive(mixed $callback, mixed $value): mixed + { + $mapped = match (true) { + is_array($value) => array_map(static fn ($v) => self::mapRecursive($callback, value: $v), $value), + default => $value, + }; + + return $callback($mapped); + } + + public static function removeNulls(mixed $value): mixed + { + $mapped = self::mapRecursive( + static fn ($vs) => is_array($vs) && !array_is_list($vs) ? array_filter($vs, callback: static fn ($v) => !is_null($v)) : $vs, + value: $value + ); + + return $mapped; + } + /** * @param string|int|list|callable $key */ @@ -127,7 +150,7 @@ public static function parsePath(string|array $path): string } [$template] = $path; - $mapped = array_map(static fn ($s) => self::rawUrlEncode($s), array: array_slice($path, 1)); + $mapped = array_map(static fn ($s) => rawurlencode(self::strVal($s)), array: array_slice($path, 1)); return sprintf($template, ...$mapped); } @@ -161,8 +184,9 @@ public static function joinUri( parse_str($base->getQuery(), $q1); parse_str($parsed['query'] ?? '', $q2); - $merged_query = array_merge_recursive($q1, $q2, $query); - $qs = http_build_query($merged_query, encoding_type: PHP_QUERY_RFC3986); + $mergedQuery = array_merge_recursive($q1, $q2, $query); + $normalizedQuery = array_map(static fn ($v) => self::strVal($v), array: $mergedQuery); + $qs = http_build_query($normalizedQuery, encoding_type: PHP_QUERY_RFC3986); return $base->withQuery($qs); } @@ -179,11 +203,7 @@ public static function withSetHeaders( /** @var RequestInterface */ $req = $req->withoutHeader($name); } else { - $value = is_int($value) - ? (string) $value - : (is_array($value) - ? array_map(static fn ($v) => (string) $v, array: $value) - : $value); + $value = is_array($value) ? array_map(static fn ($v) => self::strVal($v), array: $value) : self::strVal($value); /** @var RequestInterface */ $req = $req->withHeader($name, $value); @@ -251,6 +271,13 @@ public static function withSetBody( return $req->withBody($stream); } + if (is_string($body)) { + $stream = $factory->createStream($body); + + // @var RequestInterface + return $req->withBody($stream); + } + return $req; } @@ -382,15 +409,18 @@ public static function prettyEncodeJson(mixed $obj): string return json_encode($obj, flags: JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT) ?: ''; } - private static function rawUrlEncode( - string|int|\DateTimeInterface $value - ): string { - // @phpstan-ignore-next-line function.alreadyNarrowedType + private static function strVal(mixed $value): string + { + if (is_bool($value)) { + return $value ? 'true' : 'false'; + } + if (is_object($value) && is_a($value, class: \DateTimeInterface::class)) { - $value = date_format($value, format: \DateTimeInterface::RFC3339); + return date_format($value, format: \DateTimeInterface::RFC3339); } - return rawurlencode((string) $value); + // @phpstan-ignore-next-line argument.type + return strval($value); } /** @@ -415,7 +445,7 @@ private static function writeMultipartContent( } elseif (is_string($val) || is_numeric($val) || is_bool($val)) { yield sprintf($contentLine, $contentType ?? 'text/plain'); - yield (string) $val; + yield self::strVal($val); } else { yield sprintf($contentLine, $contentType ?? 'application/json'); @@ -441,7 +471,7 @@ private static function writeMultipartChunk( yield 'Content-Disposition: form-data'; if (!is_null($key)) { - $name = self::rawUrlEncode($key); + $name = rawurlencode(self::strVal($key)); yield "; name=\"{$name}\""; } diff --git a/src/Services/Actions/ExecuteService.php b/src/Services/Actions/ExecuteService.php index 98e018f..97720e7 100644 --- a/src/Services/Actions/ExecuteService.php +++ b/src/Services/Actions/ExecuteService.php @@ -8,6 +8,7 @@ use ModerationAPI\Actions\Execute\ExecuteExecuteResponse; use ModerationAPI\Client; use ModerationAPI\Core\Exceptions\APIException; +use ModerationAPI\Core\Util; use ModerationAPI\RequestOptions; use ModerationAPI\ServiceContracts\Actions\ExecuteContract; @@ -49,16 +50,16 @@ public function execute( ?string $value = null, ?RequestOptions $requestOptions = null, ): ExecuteExecuteResponse { - $params = [ - 'actionKey' => $actionKey, - 'authorIDs' => $authorIDs, - 'contentIDs' => $contentIDs, - 'duration' => $duration, - 'queueID' => $queueID, - 'value' => $value, - ]; - // @phpstan-ignore-next-line function.impossibleType - $params = array_filter($params, callback: static fn ($v) => !is_null($v)); + $params = Util::removeNulls( + [ + 'actionKey' => $actionKey, + 'authorIDs' => $authorIDs, + 'contentIDs' => $contentIDs, + 'duration' => $duration, + 'queueID' => $queueID, + 'value' => $value, + ], + ); // @phpstan-ignore-next-line argument.type $response = $this->raw->execute(params: $params, requestOptions: $requestOptions); @@ -89,14 +90,14 @@ public function executeByID( ?string $value = null, ?RequestOptions $requestOptions = null, ): ExecuteExecuteByIDResponse { - $params = [ - 'authorIDs' => $authorIDs, - 'contentIDs' => $contentIDs, - 'queueID' => $queueID, - 'value' => $value, - ]; - // @phpstan-ignore-next-line function.impossibleType - $params = array_filter($params, callback: static fn ($v) => !is_null($v)); + $params = Util::removeNulls( + [ + 'authorIDs' => $authorIDs, + 'contentIDs' => $contentIDs, + 'queueID' => $queueID, + 'value' => $value, + ], + ); // @phpstan-ignore-next-line argument.type $response = $this->raw->executeByID($actionID, params: $params, requestOptions: $requestOptions); diff --git a/src/Services/ActionsService.php b/src/Services/ActionsService.php index aa4496c..8f3b098 100644 --- a/src/Services/ActionsService.php +++ b/src/Services/ActionsService.php @@ -14,6 +14,7 @@ use ModerationAPI\Actions\ActionUpdateResponse; use ModerationAPI\Client; use ModerationAPI\Core\Exceptions\APIException; +use ModerationAPI\Core\Util; use ModerationAPI\RequestOptions; use ModerationAPI\ServiceContracts\ActionsContract; use ModerationAPI\Services\Actions\ExecuteService; @@ -78,22 +79,22 @@ public function create( array $webhooks = [], ?RequestOptions $requestOptions = null, ): ActionNewResponse { - $params = [ - 'name' => $name, - 'builtIn' => $builtIn, - 'description' => $description, - 'filterInQueueIDs' => $filterInQueueIDs, - 'freeText' => $freeText, - 'key' => $key, - 'position' => $position, - 'possibleValues' => $possibleValues, - 'queueBehaviour' => $queueBehaviour, - 'type' => $type, - 'valueRequired' => $valueRequired, - 'webhooks' => $webhooks, - ]; - // @phpstan-ignore-next-line function.impossibleType - $params = array_filter($params, callback: static fn ($v) => !is_null($v)); + $params = Util::removeNulls( + [ + 'name' => $name, + 'builtIn' => $builtIn, + 'description' => $description, + 'filterInQueueIDs' => $filterInQueueIDs, + 'freeText' => $freeText, + 'key' => $key, + 'position' => $position, + 'possibleValues' => $possibleValues, + 'queueBehaviour' => $queueBehaviour, + 'type' => $type, + 'valueRequired' => $valueRequired, + 'webhooks' => $webhooks, + ], + ); // @phpstan-ignore-next-line argument.type $response = $this->raw->create(params: $params, requestOptions: $requestOptions); @@ -161,22 +162,22 @@ public function update( array $webhooks = [], ?RequestOptions $requestOptions = null, ): ActionUpdateResponse { - $params = [ - 'builtIn' => $builtIn, - 'description' => $description, - 'filterInQueueIDs' => $filterInQueueIDs, - 'freeText' => $freeText, - 'key' => $key, - 'name' => $name, - 'position' => $position, - 'possibleValues' => $possibleValues, - 'queueBehaviour' => $queueBehaviour, - 'type' => $type, - 'valueRequired' => $valueRequired, - 'webhooks' => $webhooks, - ]; - // @phpstan-ignore-next-line function.impossibleType - $params = array_filter($params, callback: static fn ($v) => !is_null($v)); + $params = Util::removeNulls( + [ + 'builtIn' => $builtIn, + 'description' => $description, + 'filterInQueueIDs' => $filterInQueueIDs, + 'freeText' => $freeText, + 'key' => $key, + 'name' => $name, + 'position' => $position, + 'possibleValues' => $possibleValues, + 'queueBehaviour' => $queueBehaviour, + 'type' => $type, + 'valueRequired' => $valueRequired, + 'webhooks' => $webhooks, + ], + ); // @phpstan-ignore-next-line argument.type $response = $this->raw->update($id, params: $params, requestOptions: $requestOptions); @@ -197,9 +198,7 @@ public function list( ?string $queueID = null, ?RequestOptions $requestOptions = null ): array { - $params = ['queueID' => $queueID]; - // @phpstan-ignore-next-line function.impossibleType - $params = array_filter($params, callback: static fn ($v) => !is_null($v)); + $params = Util::removeNulls(['queueID' => $queueID]); // @phpstan-ignore-next-line argument.type $response = $this->raw->list(params: $params, requestOptions: $requestOptions); diff --git a/src/Services/AuthorsService.php b/src/Services/AuthorsService.php index 43113a4..947841a 100644 --- a/src/Services/AuthorsService.php +++ b/src/Services/AuthorsService.php @@ -13,6 +13,7 @@ use ModerationAPI\Authors\AuthorUpdateResponse; use ModerationAPI\Client; use ModerationAPI\Core\Exceptions\APIException; +use ModerationAPI\Core\Util; use ModerationAPI\RequestOptions; use ModerationAPI\ServiceContracts\AuthorsContract; @@ -64,19 +65,19 @@ public function create( ?string $profilePicture = null, ?RequestOptions $requestOptions = null, ): AuthorNewResponse { - $params = [ - 'externalID' => $externalID, - 'email' => $email, - 'externalLink' => $externalLink, - 'firstSeen' => $firstSeen, - 'lastSeen' => $lastSeen, - 'manualTrustLevel' => $manualTrustLevel, - 'metadata' => $metadata, - 'name' => $name, - 'profilePicture' => $profilePicture, - ]; - // @phpstan-ignore-next-line function.impossibleType - $params = array_filter($params, callback: static fn ($v) => !is_null($v)); + $params = Util::removeNulls( + [ + 'externalID' => $externalID, + 'email' => $email, + 'externalLink' => $externalLink, + 'firstSeen' => $firstSeen, + 'lastSeen' => $lastSeen, + 'manualTrustLevel' => $manualTrustLevel, + 'metadata' => $metadata, + 'name' => $name, + 'profilePicture' => $profilePicture, + ], + ); // @phpstan-ignore-next-line argument.type $response = $this->raw->create(params: $params, requestOptions: $requestOptions); @@ -136,18 +137,18 @@ public function update( ?string $profilePicture = null, ?RequestOptions $requestOptions = null, ): AuthorUpdateResponse { - $params = [ - 'email' => $email, - 'externalLink' => $externalLink, - 'firstSeen' => $firstSeen, - 'lastSeen' => $lastSeen, - 'manualTrustLevel' => $manualTrustLevel, - 'metadata' => $metadata, - 'name' => $name, - 'profilePicture' => $profilePicture, - ]; - // @phpstan-ignore-next-line function.impossibleType - $params = array_filter($params, callback: static fn ($v) => !is_null($v)); + $params = Util::removeNulls( + [ + 'email' => $email, + 'externalLink' => $externalLink, + 'firstSeen' => $firstSeen, + 'lastSeen' => $lastSeen, + 'manualTrustLevel' => $manualTrustLevel, + 'metadata' => $metadata, + 'name' => $name, + 'profilePicture' => $profilePicture, + ], + ); // @phpstan-ignore-next-line argument.type $response = $this->raw->update($id, params: $params, requestOptions: $requestOptions); @@ -177,17 +178,17 @@ public function list( string|SortDirection $sortDirection = 'desc', ?RequestOptions $requestOptions = null, ): AuthorListResponse { - $params = [ - 'contentTypes' => $contentTypes, - 'lastActiveDate' => $lastActiveDate, - 'memberSinceDate' => $memberSinceDate, - 'pageNumber' => $pageNumber, - 'pageSize' => $pageSize, - 'sortBy' => $sortBy, - 'sortDirection' => $sortDirection, - ]; - // @phpstan-ignore-next-line function.impossibleType - $params = array_filter($params, callback: static fn ($v) => !is_null($v)); + $params = Util::removeNulls( + [ + 'contentTypes' => $contentTypes, + 'lastActiveDate' => $lastActiveDate, + 'memberSinceDate' => $memberSinceDate, + 'pageNumber' => $pageNumber, + 'pageSize' => $pageSize, + 'sortBy' => $sortBy, + 'sortDirection' => $sortDirection, + ], + ); // @phpstan-ignore-next-line argument.type $response = $this->raw->list(params: $params, requestOptions: $requestOptions); diff --git a/src/Services/ContentService.php b/src/Services/ContentService.php index 91b921b..2c6a9fd 100644 --- a/src/Services/ContentService.php +++ b/src/Services/ContentService.php @@ -8,6 +8,7 @@ use ModerationAPI\Content\ContentSubmitParams\MetaType; use ModerationAPI\Content\ContentSubmitResponse; use ModerationAPI\Core\Exceptions\APIException; +use ModerationAPI\Core\Util; use ModerationAPI\RequestOptions; use ModerationAPI\ServiceContracts\ContentContract; @@ -53,19 +54,19 @@ public function submit( ?array $policies = null, ?RequestOptions $requestOptions = null, ): ContentSubmitResponse { - $params = [ - 'content' => $content, - 'authorID' => $authorID, - 'channel' => $channel, - 'contentID' => $contentID, - 'conversationID' => $conversationID, - 'doNotStore' => $doNotStore, - 'metadata' => $metadata, - 'metaType' => $metaType, - 'policies' => $policies, - ]; - // @phpstan-ignore-next-line function.impossibleType - $params = array_filter($params, callback: static fn ($v) => !is_null($v)); + $params = Util::removeNulls( + [ + 'content' => $content, + 'authorID' => $authorID, + 'channel' => $channel, + 'contentID' => $contentID, + 'conversationID' => $conversationID, + 'doNotStore' => $doNotStore, + 'metadata' => $metadata, + 'metaType' => $metaType, + 'policies' => $policies, + ], + ); // @phpstan-ignore-next-line argument.type $response = $this->raw->submit(params: $params, requestOptions: $requestOptions); diff --git a/src/Services/Queue/ItemsService.php b/src/Services/Queue/ItemsService.php index 9ae8c06..415251e 100644 --- a/src/Services/Queue/ItemsService.php +++ b/src/Services/Queue/ItemsService.php @@ -6,6 +6,7 @@ use ModerationAPI\Client; use ModerationAPI\Core\Exceptions\APIException; +use ModerationAPI\Core\Util; use ModerationAPI\Queue\Items\ItemListParams\SortDirection; use ModerationAPI\Queue\Items\ItemListParams\SortField; use ModerationAPI\Queue\Items\ItemListResponse; @@ -57,21 +58,21 @@ public function list( string|SortField|null $sortField = null, ?RequestOptions $requestOptions = null, ): ItemListResponse { - $params = [ - 'afterDate' => $afterDate, - 'authorID' => $authorID, - 'beforeDate' => $beforeDate, - 'conversationIDs' => $conversationIDs, - 'filteredActionIDs' => $filteredActionIDs, - 'includeResolved' => $includeResolved, - 'labels' => $labels, - 'pageNumber' => $pageNumber, - 'pageSize' => $pageSize, - 'sortDirection' => $sortDirection, - 'sortField' => $sortField, - ]; - // @phpstan-ignore-next-line function.impossibleType - $params = array_filter($params, callback: static fn ($v) => !is_null($v)); + $params = Util::removeNulls( + [ + 'afterDate' => $afterDate, + 'authorID' => $authorID, + 'beforeDate' => $beforeDate, + 'conversationIDs' => $conversationIDs, + 'filteredActionIDs' => $filteredActionIDs, + 'includeResolved' => $includeResolved, + 'labels' => $labels, + 'pageNumber' => $pageNumber, + 'pageSize' => $pageSize, + 'sortDirection' => $sortDirection, + 'sortField' => $sortField, + ], + ); // @phpstan-ignore-next-line argument.type $response = $this->raw->list($id, params: $params, requestOptions: $requestOptions); @@ -96,9 +97,7 @@ public function resolve( ?string $comment = null, ?RequestOptions $requestOptions = null, ): ItemResolveResponse { - $params = ['id' => $id, 'comment' => $comment]; - // @phpstan-ignore-next-line function.impossibleType - $params = array_filter($params, callback: static fn ($v) => !is_null($v)); + $params = Util::removeNulls(['id' => $id, 'comment' => $comment]); // @phpstan-ignore-next-line argument.type $response = $this->raw->resolve($itemID, params: $params, requestOptions: $requestOptions); @@ -123,9 +122,7 @@ public function unresolve( ?string $comment = null, ?RequestOptions $requestOptions = null, ): ItemUnresolveResponse { - $params = ['id' => $id, 'comment' => $comment]; - // @phpstan-ignore-next-line function.impossibleType - $params = array_filter($params, callback: static fn ($v) => !is_null($v)); + $params = Util::removeNulls(['id' => $id, 'comment' => $comment]); // @phpstan-ignore-next-line argument.type $response = $this->raw->unresolve($itemID, params: $params, requestOptions: $requestOptions); diff --git a/src/Services/QueueService.php b/src/Services/QueueService.php index af97cdd..d8844e2 100644 --- a/src/Services/QueueService.php +++ b/src/Services/QueueService.php @@ -6,6 +6,7 @@ use ModerationAPI\Client; use ModerationAPI\Core\Exceptions\APIException; +use ModerationAPI\Core\Util; use ModerationAPI\Queue\QueueGetResponse; use ModerationAPI\Queue\QueueGetStatsResponse; use ModerationAPI\RequestOptions; @@ -67,9 +68,7 @@ public function getStats( string $withinDays = '30', ?RequestOptions $requestOptions = null, ): QueueGetStatsResponse { - $params = ['withinDays' => $withinDays]; - // @phpstan-ignore-next-line function.impossibleType - $params = array_filter($params, callback: static fn ($v) => !is_null($v)); + $params = Util::removeNulls(['withinDays' => $withinDays]); // @phpstan-ignore-next-line argument.type $response = $this->raw->getStats($id, params: $params, requestOptions: $requestOptions); diff --git a/src/Services/Wordlist/WordsService.php b/src/Services/Wordlist/WordsService.php index 7ad36e6..b02922f 100644 --- a/src/Services/Wordlist/WordsService.php +++ b/src/Services/Wordlist/WordsService.php @@ -6,6 +6,7 @@ use ModerationAPI\Client; use ModerationAPI\Core\Exceptions\APIException; +use ModerationAPI\Core\Util; use ModerationAPI\RequestOptions; use ModerationAPI\ServiceContracts\Wordlist\WordsContract; use ModerationAPI\Wordlist\Words\WordAddResponse; @@ -41,7 +42,7 @@ public function add( array $words, ?RequestOptions $requestOptions = null ): WordAddResponse { - $params = ['words' => $words]; + $params = Util::removeNulls(['words' => $words]); // @phpstan-ignore-next-line argument.type $response = $this->raw->add($id, params: $params, requestOptions: $requestOptions); @@ -64,7 +65,7 @@ public function remove( array $words, ?RequestOptions $requestOptions = null ): WordRemoveResponse { - $params = ['words' => $words]; + $params = Util::removeNulls(['words' => $words]); // @phpstan-ignore-next-line argument.type $response = $this->raw->remove($id, params: $params, requestOptions: $requestOptions); diff --git a/src/Services/WordlistService.php b/src/Services/WordlistService.php index f68380c..e656a0d 100644 --- a/src/Services/WordlistService.php +++ b/src/Services/WordlistService.php @@ -6,6 +6,7 @@ use ModerationAPI\Client; use ModerationAPI\Core\Exceptions\APIException; +use ModerationAPI\Core\Util; use ModerationAPI\RequestOptions; use ModerationAPI\ServiceContracts\WordlistContract; use ModerationAPI\Services\Wordlist\WordsService; @@ -77,15 +78,15 @@ public function update( ?array $words = null, ?RequestOptions $requestOptions = null, ): WordlistUpdateResponse { - $params = [ - 'description' => $description, - 'key' => $key, - 'name' => $name, - 'strict' => $strict, - 'words' => $words, - ]; - // @phpstan-ignore-next-line function.impossibleType - $params = array_filter($params, callback: static fn ($v) => !is_null($v)); + $params = Util::removeNulls( + [ + 'description' => $description, + 'key' => $key, + 'name' => $name, + 'strict' => $strict, + 'words' => $words, + ], + ); // @phpstan-ignore-next-line argument.type $response = $this->raw->update($id, params: $params, requestOptions: $requestOptions); diff --git a/tests/Core/TestModel.php b/tests/Core/ModelTest.php similarity index 91% rename from tests/Core/TestModel.php rename to tests/Core/ModelTest.php index 402b1bb..d06bc40 100644 --- a/tests/Core/TestModel.php +++ b/tests/Core/ModelTest.php @@ -10,7 +10,7 @@ use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; -class TestModel implements BaseModel +class Model implements BaseModel { /** @use SdkModel> */ use SdkModel; @@ -53,12 +53,12 @@ public function __construct( * @coversNothing */ #[CoversNothing] -class TestModelTest extends TestCase +class ModelTest extends TestCase { #[Test] public function testBasicGetAndSet(): void { - $model = new TestModel( + $model = new Model( name: 'Bob', ageYears: 12, owner: null, @@ -72,7 +72,7 @@ public function testBasicGetAndSet(): void #[Test] public function testNullAccess(): void { - $model = new TestModel( + $model = new Model( name: 'Bob', ageYears: 12, owner: null, @@ -84,7 +84,7 @@ public function testNullAccess(): void #[Test] public function testArrayGetAndSet(): void { - $model = new TestModel( + $model = new Model( name: 'Bob', ageYears: 12, owner: null, @@ -98,12 +98,12 @@ public function testArrayGetAndSet(): void #[Test] public function testDiscernsBetweenNullAndUnset(): void { - $modelUnsetFriends = new TestModel( + $modelUnsetFriends = new Model( name: 'Bob', ageYears: 12, owner: null, ); - $modelNullFriends = new TestModel( + $modelNullFriends = new Model( name: 'bob', ageYears: 12, owner: null, @@ -126,7 +126,7 @@ public function testDiscernsBetweenNullAndUnset(): void #[Test] public function testIssetOnOmittedProperties(): void { - $model = new TestModel( + $model = new Model( name: 'Bob', ageYears: 12, owner: null, @@ -138,7 +138,7 @@ public function testIssetOnOmittedProperties(): void #[Test] public function testSerializeBasicModel(): void { - $model = new TestModel( + $model = new Model( name: 'Bob', ageYears: 12, owner: 'Eve', @@ -153,7 +153,7 @@ public function testSerializeBasicModel(): void #[Test] public function testSerializeModelWithOmittedProperties(): void { - $model = new TestModel( + $model = new Model( name: 'Bob', ageYears: 12, owner: null, @@ -167,7 +167,7 @@ public function testSerializeModelWithOmittedProperties(): void #[Test] public function testSerializeModelWithExplicitNull(): void { - $model = new TestModel( + $model = new Model( name: 'Bob', ageYears: 12, owner: null, diff --git a/tests/Core/UtilTest.php b/tests/Core/UtilTest.php new file mode 100644 index 0000000..fbbac57 --- /dev/null +++ b/tests/Core/UtilTest.php @@ -0,0 +1,39 @@ + $v, + ], + [ + ['a' => null, 'b' => [null, null], 'c' => ['d' => null, 'e' => 0], 'f' => ['g' => null]], + ['b' => [null, null], 'c' => ['e' => 0], 'f' => []], + static fn ($vs) => is_array($vs) && !array_is_list($vs) ? array_filter($vs, callback: static fn ($v) => !is_null($v)) : $vs, + ], + ]; + + foreach ($cases as [$input, $output, $xform]) { + $mapped = Util::mapRecursive($xform, value: $input); + $this->assertEquals($mapped, $output); + } + } +} From 4b941bd0c16b8fe812da9ad660d49a4cb24e936d Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sat, 31 Jan 2026 12:39:18 +0000 Subject: [PATCH 04/40] feat: add idempotency header support --- composer.json | 1 + release-please-config.json | 2 +- src/Client.php | 6 ++---- src/Core/BaseClient.php | 23 ++++++++++++++++++++--- src/Version.php | 9 +++++++++ 5 files changed, 33 insertions(+), 8 deletions(-) create mode 100644 src/Version.php diff --git a/composer.json b/composer.json index 659c673..4c8d0b6 100644 --- a/composer.json +++ b/composer.json @@ -4,6 +4,7 @@ "autoload": { "files": [ "src/Core.php", + "src/Version.php", "src/Client.php" ], "psr-4": { diff --git a/release-please-config.json b/release-please-config.json index 5c15181..83bea62 100644 --- a/release-please-config.json +++ b/release-please-config.json @@ -62,6 +62,6 @@ "release-type": "php", "extra-files": [ "README.md", - "src/Client.php" + "src/Version.php" ] } \ No newline at end of file diff --git a/src/Client.php b/src/Client.php index 3c0b934..30d21e5 100644 --- a/src/Client.php +++ b/src/Client.php @@ -71,11 +71,10 @@ public function __construct(?string $secretKey = null, ?string $baseUrl = null) ); parent::__construct( - // x-release-please-start-version headers: [ 'Content-Type' => 'application/json', 'Accept' => 'application/json', - 'User-Agent' => sprintf('moderation-api/PHP %s', '0.3.0'), + 'User-Agent' => sprintf('moderation-api/PHP %s', VERSION), 'X-Stainless-Lang' => 'php', 'X-Stainless-Package-Version' => '0.3.0', 'X-Stainless-Arch' => Util::machtype(), @@ -83,9 +82,8 @@ public function __construct(?string $secretKey = null, ?string $baseUrl = null) 'X-Stainless-Runtime' => php_sapi_name(), 'X-Stainless-Runtime-Version' => phpversion(), ], - // x-release-please-end baseUrl: $baseUrl, - options: $options, + options: $options ); $this->authors = new AuthorsService($this); diff --git a/src/Core/BaseClient.php b/src/Core/BaseClient.php index 68c8e03..0486b4e 100644 --- a/src/Core/BaseClient.php +++ b/src/Core/BaseClient.php @@ -43,6 +43,7 @@ abstract class BaseClient public function __construct( protected array $headers, string $baseUrl, + protected ?string $idempotencyHeader = null, protected RequestOptions $options = new RequestOptions, ) { assert(!is_null($this->options->uriFactory)); @@ -90,6 +91,16 @@ public function request( /** @return array */ abstract protected function authHeaders(): array; + /** + * @internal + */ + protected function generateIdempotencyKey(): string + { + $hex = bin2hex(random_bytes(32)); + + return "stainless-php-retry-{$hex}"; + } + /** * @internal * @@ -127,15 +138,21 @@ protected function buildRequest( /** @var array $mergedQuery */ $mergedQuery = array_merge_recursive( $query, - $options->extraQueryParams ?? [], + $options->extraQueryParams ?? [] ); $uri = Util::joinUri($this->baseUrl, path: $parsedPath, query: $mergedQuery)->__toString(); + $idempotencyHeaders = $this->idempotencyHeader && !array_key_exists($this->idempotencyHeader, array: $headers) + ? [$this->idempotencyHeader => $this->generateIdempotencyKey()] + : []; /** @var array|null> $mergedHeaders */ - $mergedHeaders = [...$this->headers, + $mergedHeaders = [ + ...$this->headers, ...$this->authHeaders(), ...$headers, - ...($options->extraHeaders ?? []), ]; + ...($options->extraHeaders ?? []), + ...$idempotencyHeaders, + ]; $req = ['method' => strtoupper($method), 'path' => $uri, 'query' => $mergedQuery, 'headers' => $mergedHeaders, 'body' => $body]; diff --git a/src/Version.php b/src/Version.php new file mode 100644 index 0000000..2e4744c --- /dev/null +++ b/src/Version.php @@ -0,0 +1,9 @@ + Date: Thu, 11 Dec 2025 13:15:22 +0000 Subject: [PATCH 05/40] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index e7f91f4..edf5253 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 27 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/moderation-api%2Fmoderation-api-3eaa6a0657e9f67ea196c65d3b604c71f5406108983981ec696642563fda0a93.yml -openapi_spec_hash: c417a44bb9fa62a02eca68bbb307c712 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/moderation-api%2Fmoderation-api-b6e4551f2cd18763b05733f792b2d07e5489c27fc1985c8d839668dd80578432.yml +openapi_spec_hash: ee9b7b9ddbf9da9a86da1f859b657198 config_hash: 6a52f6ae7d55cf3b4e91538cc7752aeb From cf5c8c2028e2713204a7f1c2d9c80585f0187662 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 11 Dec 2025 13:32:48 +0000 Subject: [PATCH 06/40] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index edf5253..e7f91f4 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 27 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/moderation-api%2Fmoderation-api-b6e4551f2cd18763b05733f792b2d07e5489c27fc1985c8d839668dd80578432.yml -openapi_spec_hash: ee9b7b9ddbf9da9a86da1f859b657198 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/moderation-api%2Fmoderation-api-3eaa6a0657e9f67ea196c65d3b604c71f5406108983981ec696642563fda0a93.yml +openapi_spec_hash: c417a44bb9fa62a02eca68bbb307c712 config_hash: 6a52f6ae7d55cf3b4e91538cc7752aeb From d69d1af850db2eda99cc2719bccb23b65d5e2301 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 11 Dec 2025 16:32:41 +0000 Subject: [PATCH 07/40] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index e7f91f4..8fac9df 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 27 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/moderation-api%2Fmoderation-api-3eaa6a0657e9f67ea196c65d3b604c71f5406108983981ec696642563fda0a93.yml -openapi_spec_hash: c417a44bb9fa62a02eca68bbb307c712 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/moderation-api%2Fmoderation-api-df0281b1aec24ed19b928d7e5912db35455378fa59390c6c3bf8d6700425d922.yml +openapi_spec_hash: 03107bb438d4b42d77fbabae3cfd3d79 config_hash: 6a52f6ae7d55cf3b4e91538cc7752aeb From 6171347fc5833d947bf081bcac878e965555bf91 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 12 Dec 2025 06:26:50 +0000 Subject: [PATCH 08/40] chore(internal): codegen related update --- src/Core/Attributes/Api.php | 66 +++++++ src/Core/Concerns/SdkResponse.php | 29 +++ .../Contracts/ResponseConverter.php | 18 ++ tests/Core/TestModel.php | 180 ++++++++++++++++++ 4 files changed, 293 insertions(+) create mode 100644 src/Core/Attributes/Api.php create mode 100644 src/Core/Concerns/SdkResponse.php create mode 100644 src/Core/Conversion/Contracts/ResponseConverter.php create mode 100644 tests/Core/TestModel.php diff --git a/src/Core/Attributes/Api.php b/src/Core/Attributes/Api.php new file mode 100644 index 0000000..95b9a2c --- /dev/null +++ b/src/Core/Attributes/Api.php @@ -0,0 +1,66 @@ +|Converter|string|null */ + public readonly Converter|string|null $type; + + /** @var array */ + private static array $enumConverters = []; + + /** + * @param class-string|Converter|string|null $type + * @param class-string<\BackedEnum>|Converter|null $enum + * @param class-string|Converter|null $union + * @param class-string|Converter|string|null $list + * @param class-string|Converter|string|null $map + */ + public function __construct( + public readonly ?string $apiName = null, + Converter|string|null $type = null, + Converter|string|null $enum = null, + Converter|string|null $union = null, + Converter|string|null $list = null, + Converter|string|null $map = null, + public readonly bool $nullable = false, + public readonly bool $optional = false, + ) { + $type ??= $union; + if (null !== $list) { + $type ??= new ListOf($list); + } + if (null !== $map) { + $type ??= new MapOf($map); + } + if (null !== $enum) { + $type ??= $enum instanceof Converter ? $enum : $this->getEnumConverter($enum); + } + + $this->type = $type; + } + + /** @property class-string<\BackedEnum> $enum */ + private function getEnumConverter(string $enum): Converter + { + if (!isset(self::$enumConverters[$enum])) { + $converter = new EnumOf(array_column($enum::cases(), 'value')); // @phpstan-ignore-line + self::$enumConverters[$enum] = $converter; + } + + return self::$enumConverters[$enum]; + } +} diff --git a/src/Core/Concerns/SdkResponse.php b/src/Core/Concerns/SdkResponse.php new file mode 100644 index 0000000..036f8af --- /dev/null +++ b/src/Core/Concerns/SdkResponse.php @@ -0,0 +1,29 @@ +_rawResponse = $response; + $instance->__unserialize(Util::decodeContent($response)); // @phpstan-ignore-line + + return $instance; + } + + public function getRawResponse(): ?ResponseInterface + { + return $this->_rawResponse; + } +} diff --git a/src/Core/Conversion/Contracts/ResponseConverter.php b/src/Core/Conversion/Contracts/ResponseConverter.php new file mode 100644 index 0000000..996a318 --- /dev/null +++ b/src/Core/Conversion/Contracts/ResponseConverter.php @@ -0,0 +1,18 @@ +> */ + use SdkModel; + + #[Api] + public string $name; + + #[Api('age_years')] + public int $ageYears; + + /** @var list|null */ + #[Api(optional: true)] + public ?array $friends; + + #[Api] + public ?string $owner; + + /** + * @param list|null $friends + */ + public function __construct( + string $name, + int $ageYears, + ?string $owner, + ?array $friends = null, + ) { + $this->initialize(); + + $this->name = $name; + $this->ageYears = $ageYears; + $this->owner = $owner; + + null != $friends && $this->friends = $friends; + } +} + +/** + * @internal + * + * @coversNothing + */ +#[CoversNothing] +class TestModelTest extends TestCase +{ + #[Test] + public function testBasicGetAndSet(): void + { + $model = new TestModel( + name: 'Bob', + ageYears: 12, + owner: null, + ); + $this->assertEquals(12, $model->ageYears); + + ++$model->ageYears; + $this->assertEquals(13, $model->ageYears); + } + + #[Test] + public function testNullAccess(): void + { + $model = new TestModel( + name: 'Bob', + ageYears: 12, + owner: null, + ); + $this->assertNull($model->owner); + $this->assertNull($model->friends); + } + + #[Test] + public function testArrayGetAndSet(): void + { + $model = new TestModel( + name: 'Bob', + ageYears: 12, + owner: null, + ); + $model->friends ??= []; + $this->assertEquals([], $model->friends); + $model->friends[] = 'Alice'; + $this->assertEquals(['Alice'], $model->friends); + } + + #[Test] + public function testDiscernsBetweenNullAndUnset(): void + { + $modelUnsetFriends = new TestModel( + name: 'Bob', + ageYears: 12, + owner: null, + ); + $modelNullFriends = new TestModel( + name: 'bob', + ageYears: 12, + owner: null, + ); + $modelNullFriends->friends = null; + + $this->assertEquals(12, $modelUnsetFriends->ageYears); + $this->assertEquals(12, $modelNullFriends->ageYears); + + $this->assertTrue($modelUnsetFriends->offsetExists('ageYears')); + $this->assertTrue($modelNullFriends->offsetExists('ageYears')); + + $this->assertNull($modelUnsetFriends->friends); + $this->assertNull($modelNullFriends->friends); + + $this->assertFalse($modelUnsetFriends->offsetExists('friends')); + $this->assertTrue($modelNullFriends->offsetExists('friends')); + } + + #[Test] + public function testIssetOnOmittedProperties(): void + { + $model = new TestModel( + name: 'Bob', + ageYears: 12, + owner: null, + ); + $this->assertFalse(isset($model->owner)); + $this->assertFalse(isset($model->friends)); + } + + #[Test] + public function testSerializeBasicModel(): void + { + $model = new TestModel( + name: 'Bob', + ageYears: 12, + owner: 'Eve', + friends: ['Alice', 'Charlie'], + ); + $this->assertEquals( + '{"name":"Bob","age_years":12,"friends":["Alice","Charlie"],"owner":"Eve"}', + json_encode($model) + ); + } + + #[Test] + public function testSerializeModelWithOmittedProperties(): void + { + $model = new TestModel( + name: 'Bob', + ageYears: 12, + owner: null, + ); + $this->assertEquals( + '{"name":"Bob","age_years":12,"owner":null}', + json_encode($model) + ); + } + + #[Test] + public function testSerializeModelWithExplicitNull(): void + { + $model = new TestModel( + name: 'Bob', + ageYears: 12, + owner: null, + ); + $model->friends = null; + $this->assertEquals( + '{"name":"Bob","age_years":12,"friends":null,"owner":null}', + json_encode($model) + ); + } +} From b7631a0f4a9fa10af3f6eda50be50fb78e66e222 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 12 Dec 2025 06:27:40 +0000 Subject: [PATCH 09/40] chore(internal): codegen related update --- src/Core/Attributes/Api.php | 66 ------- src/Core/Concerns/SdkResponse.php | 29 --- .../Contracts/ResponseConverter.php | 18 -- tests/Core/TestModel.php | 180 ------------------ 4 files changed, 293 deletions(-) delete mode 100644 src/Core/Attributes/Api.php delete mode 100644 src/Core/Concerns/SdkResponse.php delete mode 100644 src/Core/Conversion/Contracts/ResponseConverter.php delete mode 100644 tests/Core/TestModel.php diff --git a/src/Core/Attributes/Api.php b/src/Core/Attributes/Api.php deleted file mode 100644 index 95b9a2c..0000000 --- a/src/Core/Attributes/Api.php +++ /dev/null @@ -1,66 +0,0 @@ -|Converter|string|null */ - public readonly Converter|string|null $type; - - /** @var array */ - private static array $enumConverters = []; - - /** - * @param class-string|Converter|string|null $type - * @param class-string<\BackedEnum>|Converter|null $enum - * @param class-string|Converter|null $union - * @param class-string|Converter|string|null $list - * @param class-string|Converter|string|null $map - */ - public function __construct( - public readonly ?string $apiName = null, - Converter|string|null $type = null, - Converter|string|null $enum = null, - Converter|string|null $union = null, - Converter|string|null $list = null, - Converter|string|null $map = null, - public readonly bool $nullable = false, - public readonly bool $optional = false, - ) { - $type ??= $union; - if (null !== $list) { - $type ??= new ListOf($list); - } - if (null !== $map) { - $type ??= new MapOf($map); - } - if (null !== $enum) { - $type ??= $enum instanceof Converter ? $enum : $this->getEnumConverter($enum); - } - - $this->type = $type; - } - - /** @property class-string<\BackedEnum> $enum */ - private function getEnumConverter(string $enum): Converter - { - if (!isset(self::$enumConverters[$enum])) { - $converter = new EnumOf(array_column($enum::cases(), 'value')); // @phpstan-ignore-line - self::$enumConverters[$enum] = $converter; - } - - return self::$enumConverters[$enum]; - } -} diff --git a/src/Core/Concerns/SdkResponse.php b/src/Core/Concerns/SdkResponse.php deleted file mode 100644 index 036f8af..0000000 --- a/src/Core/Concerns/SdkResponse.php +++ /dev/null @@ -1,29 +0,0 @@ -_rawResponse = $response; - $instance->__unserialize(Util::decodeContent($response)); // @phpstan-ignore-line - - return $instance; - } - - public function getRawResponse(): ?ResponseInterface - { - return $this->_rawResponse; - } -} diff --git a/src/Core/Conversion/Contracts/ResponseConverter.php b/src/Core/Conversion/Contracts/ResponseConverter.php deleted file mode 100644 index 996a318..0000000 --- a/src/Core/Conversion/Contracts/ResponseConverter.php +++ /dev/null @@ -1,18 +0,0 @@ -> */ - use SdkModel; - - #[Api] - public string $name; - - #[Api('age_years')] - public int $ageYears; - - /** @var list|null */ - #[Api(optional: true)] - public ?array $friends; - - #[Api] - public ?string $owner; - - /** - * @param list|null $friends - */ - public function __construct( - string $name, - int $ageYears, - ?string $owner, - ?array $friends = null, - ) { - $this->initialize(); - - $this->name = $name; - $this->ageYears = $ageYears; - $this->owner = $owner; - - null != $friends && $this->friends = $friends; - } -} - -/** - * @internal - * - * @coversNothing - */ -#[CoversNothing] -class TestModelTest extends TestCase -{ - #[Test] - public function testBasicGetAndSet(): void - { - $model = new TestModel( - name: 'Bob', - ageYears: 12, - owner: null, - ); - $this->assertEquals(12, $model->ageYears); - - ++$model->ageYears; - $this->assertEquals(13, $model->ageYears); - } - - #[Test] - public function testNullAccess(): void - { - $model = new TestModel( - name: 'Bob', - ageYears: 12, - owner: null, - ); - $this->assertNull($model->owner); - $this->assertNull($model->friends); - } - - #[Test] - public function testArrayGetAndSet(): void - { - $model = new TestModel( - name: 'Bob', - ageYears: 12, - owner: null, - ); - $model->friends ??= []; - $this->assertEquals([], $model->friends); - $model->friends[] = 'Alice'; - $this->assertEquals(['Alice'], $model->friends); - } - - #[Test] - public function testDiscernsBetweenNullAndUnset(): void - { - $modelUnsetFriends = new TestModel( - name: 'Bob', - ageYears: 12, - owner: null, - ); - $modelNullFriends = new TestModel( - name: 'bob', - ageYears: 12, - owner: null, - ); - $modelNullFriends->friends = null; - - $this->assertEquals(12, $modelUnsetFriends->ageYears); - $this->assertEquals(12, $modelNullFriends->ageYears); - - $this->assertTrue($modelUnsetFriends->offsetExists('ageYears')); - $this->assertTrue($modelNullFriends->offsetExists('ageYears')); - - $this->assertNull($modelUnsetFriends->friends); - $this->assertNull($modelNullFriends->friends); - - $this->assertFalse($modelUnsetFriends->offsetExists('friends')); - $this->assertTrue($modelNullFriends->offsetExists('friends')); - } - - #[Test] - public function testIssetOnOmittedProperties(): void - { - $model = new TestModel( - name: 'Bob', - ageYears: 12, - owner: null, - ); - $this->assertFalse(isset($model->owner)); - $this->assertFalse(isset($model->friends)); - } - - #[Test] - public function testSerializeBasicModel(): void - { - $model = new TestModel( - name: 'Bob', - ageYears: 12, - owner: 'Eve', - friends: ['Alice', 'Charlie'], - ); - $this->assertEquals( - '{"name":"Bob","age_years":12,"friends":["Alice","Charlie"],"owner":"Eve"}', - json_encode($model) - ); - } - - #[Test] - public function testSerializeModelWithOmittedProperties(): void - { - $model = new TestModel( - name: 'Bob', - ageYears: 12, - owner: null, - ); - $this->assertEquals( - '{"name":"Bob","age_years":12,"owner":null}', - json_encode($model) - ); - } - - #[Test] - public function testSerializeModelWithExplicitNull(): void - { - $model = new TestModel( - name: 'Bob', - ageYears: 12, - owner: null, - ); - $model->friends = null; - $this->assertEquals( - '{"name":"Bob","age_years":12,"friends":null,"owner":null}', - json_encode($model) - ); - } -} From 8028859af7460243fc4c23f2e2541ff65ba542d6 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sat, 13 Dec 2025 03:38:28 +0000 Subject: [PATCH 10/40] feat!: improve identifier renaming for names that clash with builtins --- src/Content/ContentSubmitParams.php | 20 ++++++++-------- src/Content/ContentSubmitParams/Content.php | 4 ++-- .../Content/{Object1.php => Object_.php} | 24 +++++++++---------- .../Content/{Object1 => Object_}/Data.php | 10 ++++---- .../{Object1 => Object_}/Data/Audio.php | 2 +- .../{Object1 => Object_}/Data/Image.php | 2 +- .../{Object1 => Object_}/Data/Text.php | 2 +- .../{Object1 => Object_}/Data/Video.php | 2 +- src/Content/ContentSubmitResponse.php | 6 ++--- .../Policy/EntityMatcherOutput.php | 12 +++++----- .../{Match1.php => Match_.php} | 12 +++++----- 11 files changed, 48 insertions(+), 48 deletions(-) rename src/Content/ContentSubmitParams/Content/{Object1.php => Object_.php} (71%) rename src/Content/ContentSubmitParams/Content/{Object1 => Object_}/Data.php (70%) rename src/Content/ContentSubmitParams/Content/{Object1 => Object_}/Data/Audio.php (99%) rename src/Content/ContentSubmitParams/Content/{Object1 => Object_}/Data/Image.php (99%) rename src/Content/ContentSubmitParams/Content/{Object1 => Object_}/Data/Text.php (99%) rename src/Content/ContentSubmitParams/Content/{Object1 => Object_}/Data/Video.php (99%) rename src/Content/ContentSubmitResponse/Policy/EntityMatcherOutput/{Match1.php => Match_.php} (85%) diff --git a/src/Content/ContentSubmitParams.php b/src/Content/ContentSubmitParams.php index 201a7f6..2d8e14b 100644 --- a/src/Content/ContentSubmitParams.php +++ b/src/Content/ContentSubmitParams.php @@ -6,7 +6,7 @@ use ModerationAPI\Content\ContentSubmitParams\Content\Audio; use ModerationAPI\Content\ContentSubmitParams\Content\Image; -use ModerationAPI\Content\ContentSubmitParams\Content\Object1; +use ModerationAPI\Content\ContentSubmitParams\Content\Object_; use ModerationAPI\Content\ContentSubmitParams\Content\Text; use ModerationAPI\Content\ContentSubmitParams\Content\Video; use ModerationAPI\Content\ContentSubmitParams\MetaType; @@ -49,8 +49,8 @@ * type?: 'image', url: string * }|Video|array{type?: 'video', url: string}|Audio|array{ * type?: 'audio', url: string - * }|Object1|array{ - * data: array, + * }|Object_|array{ + * data: array, * type?: 'object', * }, * authorID?: string, @@ -104,7 +104,7 @@ final class ContentSubmitParams implements BaseModel * The content sent for moderation. */ #[Required] - public Text|Image|Video|Audio|Object1 $content; + public Text|Image|Video|Audio|Object_ $content; /** * The author of the content. @@ -188,8 +188,8 @@ public function __construct() * type?: 'image', url: string * }|Video|array{type?: 'video', url: string}|Audio|array{ * type?: 'audio', url: string - * }|Object1|array{ - * data: array, + * }|Object_|array{ + * data: array, * type?: 'object', * } $content * @param array $metadata @@ -228,7 +228,7 @@ public function __construct() * }> $policies */ public static function with( - Text|array|Image|Video|Audio|Object1 $content, + Text|array|Image|Video|Audio|Object_ $content, ?string $authorID = null, ?string $channel = null, ?string $contentID = null, @@ -261,13 +261,13 @@ public static function with( * type?: 'image', url: string * }|Video|array{type?: 'video', url: string}|Audio|array{ * type?: 'audio', url: string - * }|Object1|array{ - * data: array, + * }|Object_|array{ + * data: array, * type?: 'object', * } $content */ public function withContent( - Text|array|Image|Video|Audio|Object1 $content + Text|array|Image|Video|Audio|Object_ $content ): self { $self = clone $this; $self['content'] = $content; diff --git a/src/Content/ContentSubmitParams/Content.php b/src/Content/ContentSubmitParams/Content.php index b7c1205..b1d374a 100644 --- a/src/Content/ContentSubmitParams/Content.php +++ b/src/Content/ContentSubmitParams/Content.php @@ -6,7 +6,7 @@ use ModerationAPI\Content\ContentSubmitParams\Content\Audio; use ModerationAPI\Content\ContentSubmitParams\Content\Image; -use ModerationAPI\Content\ContentSubmitParams\Content\Object1; +use ModerationAPI\Content\ContentSubmitParams\Content\Object_; use ModerationAPI\Content\ContentSubmitParams\Content\Text; use ModerationAPI\Content\ContentSubmitParams\Content\Video; use ModerationAPI\Core\Concerns\SdkUnion; @@ -26,7 +26,7 @@ final class Content implements ConverterSource public static function variants(): array { return [ - Text::class, Image::class, Video::class, Audio::class, Object1::class, + Text::class, Image::class, Video::class, Audio::class, Object_::class, ]; } } diff --git a/src/Content/ContentSubmitParams/Content/Object1.php b/src/Content/ContentSubmitParams/Content/Object_.php similarity index 71% rename from src/Content/ContentSubmitParams/Content/Object1.php rename to src/Content/ContentSubmitParams/Content/Object_.php index a827ee7..5ed5129 100644 --- a/src/Content/ContentSubmitParams/Content/Object1.php +++ b/src/Content/ContentSubmitParams/Content/Object_.php @@ -4,11 +4,11 @@ namespace ModerationAPI\Content\ContentSubmitParams\Content; -use ModerationAPI\Content\ContentSubmitParams\Content\Object1\Data; -use ModerationAPI\Content\ContentSubmitParams\Content\Object1\Data\Audio; -use ModerationAPI\Content\ContentSubmitParams\Content\Object1\Data\Image; -use ModerationAPI\Content\ContentSubmitParams\Content\Object1\Data\Text; -use ModerationAPI\Content\ContentSubmitParams\Content\Object1\Data\Video; +use ModerationAPI\Content\ContentSubmitParams\Content\Object_\Data; +use ModerationAPI\Content\ContentSubmitParams\Content\Object_\Data\Audio; +use ModerationAPI\Content\ContentSubmitParams\Content\Object_\Data\Image; +use ModerationAPI\Content\ContentSubmitParams\Content\Object_\Data\Text; +use ModerationAPI\Content\ContentSubmitParams\Content\Object_\Data\Video; use ModerationAPI\Core\Attributes\Required; use ModerationAPI\Core\Concerns\SdkModel; use ModerationAPI\Core\Contracts\BaseModel; @@ -16,14 +16,14 @@ /** * Object. * - * @phpstan-type Object1Shape = array{ - * data: array, + * @phpstan-type ObjectShape = array{ + * data: array, * type?: 'object', * } */ -final class Object1 implements BaseModel +final class Object_ implements BaseModel { - /** @use SdkModel */ + /** @use SdkModel */ use SdkModel; /** @var 'object' $type */ @@ -39,17 +39,17 @@ final class Object1 implements BaseModel public array $data; /** - * `new Object1()` is missing required properties by the API. + * `new Object_()` is missing required properties by the API. * * To enforce required parameters use * ``` - * Object1::with(data: ...) + * Object_::with(data: ...) * ``` * * Otherwise ensure the following setters are called * * ``` - * (new Object1)->withData(...) + * (new Object_)->withData(...) * ``` */ public function __construct() diff --git a/src/Content/ContentSubmitParams/Content/Object1/Data.php b/src/Content/ContentSubmitParams/Content/Object_/Data.php similarity index 70% rename from src/Content/ContentSubmitParams/Content/Object1/Data.php rename to src/Content/ContentSubmitParams/Content/Object_/Data.php index 48dd866..ea3b9e7 100644 --- a/src/Content/ContentSubmitParams/Content/Object1/Data.php +++ b/src/Content/ContentSubmitParams/Content/Object_/Data.php @@ -2,12 +2,12 @@ declare(strict_types=1); -namespace ModerationAPI\Content\ContentSubmitParams\Content\Object1; +namespace ModerationAPI\Content\ContentSubmitParams\Content\Object_; -use ModerationAPI\Content\ContentSubmitParams\Content\Object1\Data\Audio; -use ModerationAPI\Content\ContentSubmitParams\Content\Object1\Data\Image; -use ModerationAPI\Content\ContentSubmitParams\Content\Object1\Data\Text; -use ModerationAPI\Content\ContentSubmitParams\Content\Object1\Data\Video; +use ModerationAPI\Content\ContentSubmitParams\Content\Object_\Data\Audio; +use ModerationAPI\Content\ContentSubmitParams\Content\Object_\Data\Image; +use ModerationAPI\Content\ContentSubmitParams\Content\Object_\Data\Text; +use ModerationAPI\Content\ContentSubmitParams\Content\Object_\Data\Video; use ModerationAPI\Core\Concerns\SdkUnion; use ModerationAPI\Core\Conversion\Contracts\Converter; use ModerationAPI\Core\Conversion\Contracts\ConverterSource; diff --git a/src/Content/ContentSubmitParams/Content/Object1/Data/Audio.php b/src/Content/ContentSubmitParams/Content/Object_/Data/Audio.php similarity index 99% rename from src/Content/ContentSubmitParams/Content/Object1/Data/Audio.php rename to src/Content/ContentSubmitParams/Content/Object_/Data/Audio.php index f354cba..461aad0 100644 --- a/src/Content/ContentSubmitParams/Content/Object1/Data/Audio.php +++ b/src/Content/ContentSubmitParams/Content/Object_/Data/Audio.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace ModerationAPI\Content\ContentSubmitParams\Content\Object1\Data; +namespace ModerationAPI\Content\ContentSubmitParams\Content\Object_\Data; use ModerationAPI\Core\Attributes\Required; use ModerationAPI\Core\Concerns\SdkModel; diff --git a/src/Content/ContentSubmitParams/Content/Object1/Data/Image.php b/src/Content/ContentSubmitParams/Content/Object_/Data/Image.php similarity index 99% rename from src/Content/ContentSubmitParams/Content/Object1/Data/Image.php rename to src/Content/ContentSubmitParams/Content/Object_/Data/Image.php index f2f26bb..a6eaffb 100644 --- a/src/Content/ContentSubmitParams/Content/Object1/Data/Image.php +++ b/src/Content/ContentSubmitParams/Content/Object_/Data/Image.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace ModerationAPI\Content\ContentSubmitParams\Content\Object1\Data; +namespace ModerationAPI\Content\ContentSubmitParams\Content\Object_\Data; use ModerationAPI\Core\Attributes\Required; use ModerationAPI\Core\Concerns\SdkModel; diff --git a/src/Content/ContentSubmitParams/Content/Object1/Data/Text.php b/src/Content/ContentSubmitParams/Content/Object_/Data/Text.php similarity index 99% rename from src/Content/ContentSubmitParams/Content/Object1/Data/Text.php rename to src/Content/ContentSubmitParams/Content/Object_/Data/Text.php index 4ae5447..456ce21 100644 --- a/src/Content/ContentSubmitParams/Content/Object1/Data/Text.php +++ b/src/Content/ContentSubmitParams/Content/Object_/Data/Text.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace ModerationAPI\Content\ContentSubmitParams\Content\Object1\Data; +namespace ModerationAPI\Content\ContentSubmitParams\Content\Object_\Data; use ModerationAPI\Core\Attributes\Required; use ModerationAPI\Core\Concerns\SdkModel; diff --git a/src/Content/ContentSubmitParams/Content/Object1/Data/Video.php b/src/Content/ContentSubmitParams/Content/Object_/Data/Video.php similarity index 99% rename from src/Content/ContentSubmitParams/Content/Object1/Data/Video.php rename to src/Content/ContentSubmitParams/Content/Object_/Data/Video.php index a32009d..6be05bb 100644 --- a/src/Content/ContentSubmitParams/Content/Object1/Data/Video.php +++ b/src/Content/ContentSubmitParams/Content/Object_/Data/Video.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace ModerationAPI\Content\ContentSubmitParams\Content\Object1\Data; +namespace ModerationAPI\Content\ContentSubmitParams\Content\Object_\Data; use ModerationAPI\Core\Attributes\Required; use ModerationAPI\Core\Concerns\SdkModel; diff --git a/src/Content/ContentSubmitResponse.php b/src/Content/ContentSubmitResponse.php index 48cff18..7996575 100644 --- a/src/Content/ContentSubmitResponse.php +++ b/src/Content/ContentSubmitResponse.php @@ -24,7 +24,7 @@ use ModerationAPI\Content\ContentSubmitResponse\Policy\ClassifierOutput; use ModerationAPI\Content\ContentSubmitResponse\Policy\ClassifierOutput\Label; use ModerationAPI\Content\ContentSubmitResponse\Policy\EntityMatcherOutput; -use ModerationAPI\Content\ContentSubmitResponse\Policy\EntityMatcherOutput\Match1; +use ModerationAPI\Content\ContentSubmitResponse\Policy\EntityMatcherOutput\Match_; use ModerationAPI\Content\ContentSubmitResponse\Recommendation; use ModerationAPI\Content\ContentSubmitResponse\Recommendation\Action; use ModerationAPI\Content\ContentSubmitResponse\Recommendation\ReasonCode; @@ -186,7 +186,7 @@ public function __construct() * }|EntityMatcherOutput|array{ * id: string, * flagged: bool, - * matches: list, + * matches: list, * probability: float, * type?: 'entity_matcher', * flaggedFields?: list|null, @@ -327,7 +327,7 @@ public function withMeta(Meta|array $meta): self * }|EntityMatcherOutput|array{ * id: string, * flagged: bool, - * matches: list, + * matches: list, * probability: float, * type?: 'entity_matcher', * flaggedFields?: list|null, diff --git a/src/Content/ContentSubmitResponse/Policy/EntityMatcherOutput.php b/src/Content/ContentSubmitResponse/Policy/EntityMatcherOutput.php index e0ec86e..a5f748e 100644 --- a/src/Content/ContentSubmitResponse/Policy/EntityMatcherOutput.php +++ b/src/Content/ContentSubmitResponse/Policy/EntityMatcherOutput.php @@ -4,7 +4,7 @@ namespace ModerationAPI\Content\ContentSubmitResponse\Policy; -use ModerationAPI\Content\ContentSubmitResponse\Policy\EntityMatcherOutput\Match1; +use ModerationAPI\Content\ContentSubmitResponse\Policy\EntityMatcherOutput\Match_; use ModerationAPI\Core\Attributes\Optional; use ModerationAPI\Core\Attributes\Required; use ModerationAPI\Core\Concerns\SdkModel; @@ -16,7 +16,7 @@ * @phpstan-type EntityMatcherOutputShape = array{ * id: string, * flagged: bool, - * matches: list, + * matches: list, * probability: float, * type?: 'entity_matcher', * flaggedFields?: list|null, @@ -37,8 +37,8 @@ final class EntityMatcherOutput implements BaseModel #[Required] public bool $flagged; - /** @var list $matches */ - #[Required(list: Match1::class)] + /** @var list $matches */ + #[Required(list: Match_::class)] public array $matches; #[Required] @@ -76,7 +76,7 @@ public function __construct() * * You must use named parameters to construct any parameters with a default value. * - * @param list * }> $matches * @param list $flaggedFields @@ -117,7 +117,7 @@ public function withFlagged(bool $flagged): self } /** - * @param list * }> $matches */ diff --git a/src/Content/ContentSubmitResponse/Policy/EntityMatcherOutput/Match1.php b/src/Content/ContentSubmitResponse/Policy/EntityMatcherOutput/Match_.php similarity index 85% rename from src/Content/ContentSubmitResponse/Policy/EntityMatcherOutput/Match1.php rename to src/Content/ContentSubmitResponse/Policy/EntityMatcherOutput/Match_.php index 7f3667e..b99e803 100644 --- a/src/Content/ContentSubmitResponse/Policy/EntityMatcherOutput/Match1.php +++ b/src/Content/ContentSubmitResponse/Policy/EntityMatcherOutput/Match_.php @@ -9,13 +9,13 @@ use ModerationAPI\Core\Contracts\BaseModel; /** - * @phpstan-type Match1Shape = array{ + * @phpstan-type MatchShape = array{ * match: string, probability: float, span: list * } */ -final class Match1 implements BaseModel +final class Match_ implements BaseModel { - /** @use SdkModel */ + /** @use SdkModel */ use SdkModel; #[Required] @@ -29,17 +29,17 @@ final class Match1 implements BaseModel public array $span; /** - * `new Match1()` is missing required properties by the API. + * `new Match_()` is missing required properties by the API. * * To enforce required parameters use * ``` - * Match1::with(match: ..., probability: ..., span: ...) + * Match_::with(match: ..., probability: ..., span: ...) * ``` * * Otherwise ensure the following setters are called * * ``` - * (new Match1)->withMatch(...)->withProbability(...)->withSpan(...) + * (new Match_)->withMatch(...)->withProbability(...)->withSpan(...) * ``` */ public function __construct() From e17e879f4fd01c07356de5ed18f2021ad9e5e426 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 17 Dec 2025 08:54:25 +0000 Subject: [PATCH 11/40] feat!: use aliases for phpstan types --- src/Account/AccountListResponse.php | 8 +- src/Actions/ActionCreateParams.php | 31 ++-- src/Actions/ActionGetResponse.php | 33 ++-- src/Actions/ActionListParams.php | 2 +- src/Actions/ActionListResponseItem.php | 33 ++-- src/Actions/ActionNewResponse.php | 14 +- src/Actions/ActionUpdateParams.php | 33 ++-- src/Actions/ActionUpdateResponse.php | 14 +- .../Execute/ExecuteExecuteByIDParams.php | 8 +- src/Actions/Execute/ExecuteExecuteParams.php | 10 +- src/Authors/AuthorCreateParams.php | 27 +-- src/Authors/AuthorGetResponse.php | 52 +++--- src/Authors/AuthorListParams.php | 14 +- src/Authors/AuthorListResponse.php | 63 +------ src/Authors/AuthorListResponse/Author.php | 52 +++--- src/Authors/AuthorNewResponse.php | 52 +++--- src/Authors/AuthorUpdateParams.php | 27 +-- src/Authors/AuthorUpdateResponse.php | 52 +++--- src/Content/ContentSubmitParams.php | 144 ++-------------- src/Content/ContentSubmitParams/Content.php | 8 + .../ContentSubmitParams/Content/Audio.php | 2 +- .../ContentSubmitParams/Content/Image.php | 2 +- .../ContentSubmitParams/Content/Object_.php | 27 +-- .../Content/Object_/Data.php | 7 + .../Content/Object_/Data/Audio.php | 2 +- .../Content/Object_/Data/Image.php | 2 +- .../Content/Object_/Data/Text.php | 2 +- .../Content/Object_/Data/Video.php | 2 +- .../ContentSubmitParams/Content/Text.php | 2 +- .../ContentSubmitParams/Content/Video.php | 2 +- src/Content/ContentSubmitParams/Policy.php | 27 +++ .../ContentSubmitParams/Policy/CodeAbuse.php | 2 +- .../ContentSubmitParams/Policy/Flirtation.php | 2 +- .../ContentSubmitParams/Policy/Guideline.php | 2 +- .../ContentSubmitParams/Policy/Hate.php | 2 +- .../ContentSubmitParams/Policy/Illicit.php | 2 +- .../Policy/IllicitAlcohol.php | 2 +- .../Policy/IllicitDrugs.php | 2 +- .../Policy/IllicitFirearms.php | 2 +- .../Policy/IllicitGambling.php | 2 +- .../Policy/IllicitTobacco.php | 2 +- .../Policy/PersonalInformation.php | 2 +- .../ContentSubmitParams/Policy/PiiMasking.php | 21 +-- .../Policy/PiiMasking/Entity.php | 2 +- .../ContentSubmitParams/Policy/Political.php | 2 +- .../ContentSubmitParams/Policy/Profanity.php | 2 +- .../ContentSubmitParams/Policy/Religion.php | 2 +- .../ContentSubmitParams/Policy/SelfHarm.php | 2 +- .../Policy/SelfPromotion.php | 2 +- .../ContentSubmitParams/Policy/Sexual.php | 2 +- .../ContentSubmitParams/Policy/Spam.php | 2 +- .../ContentSubmitParams/Policy/Toxicity.php | 2 +- .../Policy/ToxicitySevere.php | 2 +- .../ContentSubmitParams/Policy/URLMasking.php | 21 +-- .../Policy/URLMasking/Entity.php | 2 +- .../ContentSubmitParams/Policy/Violence.php | 2 +- src/Content/ContentSubmitResponse.php | 157 ++++-------------- src/Content/ContentSubmitResponse/Author.php | 17 +- src/Content/ContentSubmitResponse/Content.php | 18 +- .../Content/Modified.php | 4 + .../Modified/ModifiedNestedObjectContent.php | 7 + .../ModifiedNestedObjectContent/Audio.php | 2 +- .../ModifiedNestedObjectContent/Image.php | 2 +- .../ModifiedNestedObjectContent/Text.php | 2 +- .../ModifiedNestedObjectContent/Video.php | 2 +- src/Content/ContentSubmitResponse/Insight.php | 5 + .../Insight/LanguageInsight.php | 2 +- .../Insight/SentimentInsight.php | 6 +- src/Content/ContentSubmitResponse/Meta.php | 2 +- src/Content/ContentSubmitResponse/Policy.php | 5 + .../Policy/ClassifierOutput.php | 10 +- .../Policy/EntityMatcherOutput.php | 14 +- .../ContentSubmitResponse/Recommendation.php | 3 +- src/Core/Concerns/SdkModel.php | 2 - src/Queue/Items/ItemListParams.php | 22 +-- src/Queue/Items/ItemListResponse.php | 52 +----- src/Queue/Items/ItemListResponse/Item.php | 29 ++-- src/Queue/Items/ItemResolveParams.php | 2 +- src/Queue/Items/ItemUnresolveParams.php | 4 +- src/Queue/QueueGetResponse.php | 25 +-- src/Queue/QueueGetResponse/Queue.php | 32 +--- src/Queue/QueueGetResponse/Queue/Filter.php | 21 +-- .../Queue/Filter/FilterLabel.php | 2 +- src/Queue/QueueGetStatsParams.php | 2 +- src/Queue/QueueGetStatsResponse.php | 60 ++----- .../QueueGetStatsResponse/TopReviewer.php | 12 +- src/Queue/QueueGetStatsResponse/Trends.php | 23 +-- .../Actions/ExecuteRawContract.php | 4 +- src/ServiceContracts/ActionsRawContract.php | 6 +- src/ServiceContracts/AuthorsRawContract.php | 6 +- src/ServiceContracts/ContentRawContract.php | 2 +- .../Queue/ItemsRawContract.php | 6 +- src/ServiceContracts/QueueRawContract.php | 2 +- .../Wordlist/WordsRawContract.php | 4 +- src/ServiceContracts/WordlistRawContract.php | 2 +- src/Wordlist/WordlistUpdateParams.php | 10 +- 96 files changed, 500 insertions(+), 930 deletions(-) diff --git a/src/Account/AccountListResponse.php b/src/Account/AccountListResponse.php index 6c93889..c920f97 100644 --- a/src/Account/AccountListResponse.php +++ b/src/Account/AccountListResponse.php @@ -11,12 +11,14 @@ use ModerationAPI\Core\Contracts\BaseModel; /** + * @phpstan-import-type CurrentProjectShape from \ModerationAPI\Account\AccountListResponse\CurrentProject + * * @phpstan-type AccountListResponseShape = array{ * id: string, * paidPlanName: string, * remainingQuota: float, * textAPIQuota: float, - * currentProject?: CurrentProject|null, + * currentProject?: null|CurrentProject|CurrentProjectShape, * } */ final class AccountListResponse implements BaseModel @@ -81,7 +83,7 @@ public function __construct() * * You must use named parameters to construct any parameters with a default value. * - * @param CurrentProject|array{id: string, name: string} $currentProject + * @param CurrentProjectShape $currentProject */ public static function with( string $id, @@ -147,7 +149,7 @@ public function withTextAPIQuota(float $textAPIQuota): self } /** - * @param CurrentProject|array{id: string, name: string} $currentProject + * @param CurrentProjectShape $currentProject */ public function withCurrentProject( CurrentProject|array $currentProject diff --git a/src/Actions/ActionCreateParams.php b/src/Actions/ActionCreateParams.php index ac0edf9..ee9f6fb 100644 --- a/src/Actions/ActionCreateParams.php +++ b/src/Actions/ActionCreateParams.php @@ -20,21 +20,22 @@ * * @see ModerationAPI\Services\ActionsService::create() * + * @phpstan-import-type PossibleValueShape from \ModerationAPI\Actions\ActionCreateParams\PossibleValue + * @phpstan-import-type WebhookShape from \ModerationAPI\Actions\ActionCreateParams\Webhook + * * @phpstan-type ActionCreateParamsShape = array{ * name: string, * builtIn?: bool|null, * description?: string|null, - * filterInQueueIDs?: list, - * freeText?: bool, + * filterInQueueIDs?: list|null, + * freeText?: bool|null, * key?: string|null, - * position?: Position|value-of, - * possibleValues?: list, - * queueBehaviour?: QueueBehaviour|value-of, + * position?: null|Position|value-of, + * possibleValues?: list|null, + * queueBehaviour?: null|QueueBehaviour|value-of, * type?: null|Type|value-of, - * valueRequired?: bool, - * webhooks?: list, + * valueRequired?: bool|null, + * webhooks?: list|null, * } */ final class ActionCreateParams implements BaseModel @@ -153,12 +154,10 @@ public function __construct() * * @param list $filterInQueueIDs * @param Position|value-of $position - * @param list $possibleValues + * @param list $possibleValues * @param QueueBehaviour|value-of $queueBehaviour * @param Type|value-of|null $type - * @param list $webhooks + * @param list $webhooks */ public static function with( string $name, @@ -277,7 +276,7 @@ public function withPosition(Position|string $position): self /** * The possible values of the action. The user will be prompted to select one of these values when executing the action. * - * @param list $possibleValues + * @param list $possibleValues */ public function withPossibleValues(array $possibleValues): self { @@ -328,9 +327,7 @@ public function withValueRequired(bool $valueRequired): self /** * The action's webhooks. * - * @param list $webhooks + * @param list $webhooks */ public function withWebhooks(array $webhooks): self { diff --git a/src/Actions/ActionGetResponse.php b/src/Actions/ActionGetResponse.php index 0d86db0..8a26461 100644 --- a/src/Actions/ActionGetResponse.php +++ b/src/Actions/ActionGetResponse.php @@ -15,6 +15,9 @@ use ModerationAPI\Core\Contracts\BaseModel; /** + * @phpstan-import-type PossibleValueShape from \ModerationAPI\Actions\ActionGetResponse\PossibleValue + * @phpstan-import-type WebhookShape from \ModerationAPI\Actions\ActionGetResponse\Webhook + * * @phpstan-type ActionGetResponseShape = array{ * id: string, * builtIn: bool|null, @@ -22,14 +25,14 @@ * filterInQueueIDs: list, * freeText: bool, * name: string, - * position: value-of, - * possibleValues: list, - * queueBehaviour: value-of, + * position: Position|value-of, + * possibleValues: list, + * queueBehaviour: QueueBehaviour|value-of, * valueRequired: bool, - * webhooks: list, + * webhooks: list, * description?: string|null, * key?: string|null, - * type?: value-of|null, + * type?: null|Type|value-of, * } */ final class ActionGetResponse implements BaseModel @@ -182,15 +185,9 @@ public function __construct() * * @param list $filterInQueueIDs * @param Position|value-of $position - * @param list $possibleValues + * @param list $possibleValues * @param QueueBehaviour|value-of $queueBehaviour - * @param list $webhooks + * @param list $webhooks * @param Type|value-of|null $type */ public static function with( @@ -314,7 +311,7 @@ public function withPosition(Position|string $position): self /** * The possible values of the action. The user will be prompted to select one of these values when executing the action. * - * @param list $possibleValues + * @param list $possibleValues */ public function withPossibleValues(array $possibleValues): self { @@ -352,13 +349,7 @@ public function withValueRequired(bool $valueRequired): self /** * The action's webhooks. * - * @param list $webhooks + * @param list $webhooks */ public function withWebhooks(array $webhooks): self { diff --git a/src/Actions/ActionListParams.php b/src/Actions/ActionListParams.php index 90b4be8..3d8b8f7 100644 --- a/src/Actions/ActionListParams.php +++ b/src/Actions/ActionListParams.php @@ -14,7 +14,7 @@ * * @see ModerationAPI\Services\ActionsService::list() * - * @phpstan-type ActionListParamsShape = array{queueID?: string} + * @phpstan-type ActionListParamsShape = array{queueID?: string|null} */ final class ActionListParams implements BaseModel { diff --git a/src/Actions/ActionListResponseItem.php b/src/Actions/ActionListResponseItem.php index b490486..14d0ec0 100644 --- a/src/Actions/ActionListResponseItem.php +++ b/src/Actions/ActionListResponseItem.php @@ -15,6 +15,9 @@ use ModerationAPI\Core\Contracts\BaseModel; /** + * @phpstan-import-type PossibleValueShape from \ModerationAPI\Actions\ActionListResponseItem\PossibleValue + * @phpstan-import-type WebhookShape from \ModerationAPI\Actions\ActionListResponseItem\Webhook + * * @phpstan-type ActionListResponseItemShape = array{ * id: string, * builtIn: bool|null, @@ -22,14 +25,14 @@ * filterInQueueIDs: list, * freeText: bool, * name: string, - * position: value-of, - * possibleValues: list, - * queueBehaviour: value-of, + * position: Position|value-of, + * possibleValues: list, + * queueBehaviour: QueueBehaviour|value-of, * valueRequired: bool, - * webhooks: list, + * webhooks: list, * description?: string|null, * key?: string|null, - * type?: value-of|null, + * type?: null|Type|value-of, * } */ final class ActionListResponseItem implements BaseModel @@ -182,15 +185,9 @@ public function __construct() * * @param list $filterInQueueIDs * @param Position|value-of $position - * @param list $possibleValues + * @param list $possibleValues * @param QueueBehaviour|value-of $queueBehaviour - * @param list $webhooks + * @param list $webhooks * @param Type|value-of|null $type */ public static function with( @@ -314,7 +311,7 @@ public function withPosition(Position|string $position): self /** * The possible values of the action. The user will be prompted to select one of these values when executing the action. * - * @param list $possibleValues + * @param list $possibleValues */ public function withPossibleValues(array $possibleValues): self { @@ -352,13 +349,7 @@ public function withValueRequired(bool $valueRequired): self /** * The action's webhooks. * - * @param list $webhooks + * @param list $webhooks */ public function withWebhooks(array $webhooks): self { diff --git a/src/Actions/ActionNewResponse.php b/src/Actions/ActionNewResponse.php index 616afab..72d65d0 100644 --- a/src/Actions/ActionNewResponse.php +++ b/src/Actions/ActionNewResponse.php @@ -14,6 +14,8 @@ use ModerationAPI\Core\Contracts\BaseModel; /** + * @phpstan-import-type PossibleValueShape from \ModerationAPI\Actions\ActionNewResponse\PossibleValue + * * @phpstan-type ActionNewResponseShape = array{ * id: string, * builtIn: bool|null, @@ -21,13 +23,13 @@ * filterInQueueIDs: list, * freeText: bool, * name: string, - * position: value-of, - * possibleValues: list, - * queueBehaviour: value-of, + * position: Position|value-of, + * possibleValues: list, + * queueBehaviour: QueueBehaviour|value-of, * valueRequired: bool, * description?: string|null, * key?: string|null, - * type?: value-of|null, + * type?: null|Type|value-of, * } */ final class ActionNewResponse implements BaseModel @@ -170,7 +172,7 @@ public function __construct() * * @param list $filterInQueueIDs * @param Position|value-of $position - * @param list $possibleValues + * @param list $possibleValues * @param QueueBehaviour|value-of $queueBehaviour * @param Type|value-of|null $type */ @@ -293,7 +295,7 @@ public function withPosition(Position|string $position): self /** * The possible values of the action. The user will be prompted to select one of these values when executing the action. * - * @param list $possibleValues + * @param list $possibleValues */ public function withPossibleValues(array $possibleValues): self { diff --git a/src/Actions/ActionUpdateParams.php b/src/Actions/ActionUpdateParams.php index 7fd58e3..6cf1dfb 100644 --- a/src/Actions/ActionUpdateParams.php +++ b/src/Actions/ActionUpdateParams.php @@ -19,21 +19,22 @@ * * @see ModerationAPI\Services\ActionsService::update() * + * @phpstan-import-type PossibleValueShape from \ModerationAPI\Actions\ActionUpdateParams\PossibleValue + * @phpstan-import-type WebhookShape from \ModerationAPI\Actions\ActionUpdateParams\Webhook + * * @phpstan-type ActionUpdateParamsShape = array{ * builtIn?: bool|null, * description?: string|null, - * filterInQueueIDs?: list, - * freeText?: bool, + * filterInQueueIDs?: list|null, + * freeText?: bool|null, * key?: string|null, - * name?: string, - * position?: Position|value-of, - * possibleValues?: list, - * queueBehaviour?: QueueBehaviour|value-of, + * name?: string|null, + * position?: null|Position|value-of, + * possibleValues?: list|null, + * queueBehaviour?: null|QueueBehaviour|value-of, * type?: null|Type|value-of, - * valueRequired?: bool, - * webhooks?: list, + * valueRequired?: bool|null, + * webhooks?: list|null, * } */ final class ActionUpdateParams implements BaseModel @@ -138,12 +139,10 @@ public function __construct() * * @param list $filterInQueueIDs * @param Position|value-of $position - * @param list $possibleValues + * @param list $possibleValues * @param QueueBehaviour|value-of $queueBehaviour * @param Type|value-of|null $type - * @param list $webhooks + * @param list $webhooks */ public static function with( ?bool $builtIn = null, @@ -261,7 +260,7 @@ public function withPosition(Position|string $position): self /** * The possible values of the action. The user will be prompted to select one of these values when executing the action. * - * @param list $possibleValues + * @param list $possibleValues */ public function withPossibleValues(array $possibleValues): self { @@ -312,9 +311,7 @@ public function withValueRequired(bool $valueRequired): self /** * The action's webhooks. * - * @param list $webhooks + * @param list $webhooks */ public function withWebhooks(array $webhooks): self { diff --git a/src/Actions/ActionUpdateResponse.php b/src/Actions/ActionUpdateResponse.php index 9bb8c28..ed15b50 100644 --- a/src/Actions/ActionUpdateResponse.php +++ b/src/Actions/ActionUpdateResponse.php @@ -14,6 +14,8 @@ use ModerationAPI\Core\Contracts\BaseModel; /** + * @phpstan-import-type PossibleValueShape from \ModerationAPI\Actions\ActionUpdateResponse\PossibleValue + * * @phpstan-type ActionUpdateResponseShape = array{ * id: string, * builtIn: bool|null, @@ -21,13 +23,13 @@ * filterInQueueIDs: list, * freeText: bool, * name: string, - * position: value-of, - * possibleValues: list, - * queueBehaviour: value-of, + * position: Position|value-of, + * possibleValues: list, + * queueBehaviour: QueueBehaviour|value-of, * valueRequired: bool, * description?: string|null, * key?: string|null, - * type?: value-of|null, + * type?: null|Type|value-of, * } */ final class ActionUpdateResponse implements BaseModel @@ -170,7 +172,7 @@ public function __construct() * * @param list $filterInQueueIDs * @param Position|value-of $position - * @param list $possibleValues + * @param list $possibleValues * @param QueueBehaviour|value-of $queueBehaviour * @param Type|value-of|null $type */ @@ -293,7 +295,7 @@ public function withPosition(Position|string $position): self /** * The possible values of the action. The user will be prompted to select one of these values when executing the action. * - * @param list $possibleValues + * @param list $possibleValues */ public function withPossibleValues(array $possibleValues): self { diff --git a/src/Actions/Execute/ExecuteExecuteByIDParams.php b/src/Actions/Execute/ExecuteExecuteByIDParams.php index d64792e..af71966 100644 --- a/src/Actions/Execute/ExecuteExecuteByIDParams.php +++ b/src/Actions/Execute/ExecuteExecuteByIDParams.php @@ -16,10 +16,10 @@ * @see ModerationAPI\Services\Actions\ExecuteService::executeByID() * * @phpstan-type ExecuteExecuteByIDParamsShape = array{ - * authorIDs?: list, - * contentIDs?: list, - * queueID?: string, - * value?: string, + * authorIDs?: list|null, + * contentIDs?: list|null, + * queueID?: string|null, + * value?: string|null, * } */ final class ExecuteExecuteByIDParams implements BaseModel diff --git a/src/Actions/Execute/ExecuteExecuteParams.php b/src/Actions/Execute/ExecuteExecuteParams.php index 2073f29..fdaabb9 100644 --- a/src/Actions/Execute/ExecuteExecuteParams.php +++ b/src/Actions/Execute/ExecuteExecuteParams.php @@ -17,11 +17,11 @@ * * @phpstan-type ExecuteExecuteParamsShape = array{ * actionKey: string, - * authorIDs?: list, - * contentIDs?: list, - * duration?: float, - * queueID?: string, - * value?: string, + * authorIDs?: list|null, + * contentIDs?: list|null, + * duration?: float|null, + * queueID?: string|null, + * value?: string|null, * } */ final class ExecuteExecuteParams implements BaseModel diff --git a/src/Authors/AuthorCreateParams.php b/src/Authors/AuthorCreateParams.php index 5956b1e..12f88ab 100644 --- a/src/Authors/AuthorCreateParams.php +++ b/src/Authors/AuthorCreateParams.php @@ -16,19 +16,16 @@ * * @see ModerationAPI\Services\AuthorsService::create() * + * @phpstan-import-type MetadataShape from \ModerationAPI\Authors\AuthorCreateParams\Metadata + * * @phpstan-type AuthorCreateParamsShape = array{ * externalID: string, * email?: string|null, * externalLink?: string|null, - * firstSeen?: float, - * lastSeen?: float, + * firstSeen?: float|null, + * lastSeen?: float|null, * manualTrustLevel?: float|null, - * metadata?: Metadata|array{ - * emailVerified?: bool|null, - * identityVerified?: bool|null, - * isPayingCustomer?: bool|null, - * phoneVerified?: bool|null, - * }, + * metadata?: MetadataShape|null, * name?: string|null, * profilePicture?: string|null, * } @@ -114,12 +111,7 @@ public function __construct() * * You must use named parameters to construct any parameters with a default value. * - * @param Metadata|array{ - * emailVerified?: bool|null, - * identityVerified?: bool|null, - * isPayingCustomer?: bool|null, - * phoneVerified?: bool|null, - * } $metadata + * @param MetadataShape $metadata */ public static function with( string $externalID, @@ -214,12 +206,7 @@ public function withManualTrustLevel(?float $manualTrustLevel): self /** * Additional metadata provided by your system. We recommend including any relevant information that may assist in the moderation process. * - * @param Metadata|array{ - * emailVerified?: bool|null, - * identityVerified?: bool|null, - * isPayingCustomer?: bool|null, - * phoneVerified?: bool|null, - * } $metadata + * @param MetadataShape $metadata */ public function withMetadata(Metadata|array $metadata): self { diff --git a/src/Authors/AuthorGetResponse.php b/src/Authors/AuthorGetResponse.php index 482e8d6..243d7bc 100644 --- a/src/Authors/AuthorGetResponse.php +++ b/src/Authors/AuthorGetResponse.php @@ -16,16 +16,22 @@ use ModerationAPI\Core\Contracts\BaseModel; /** + * @phpstan-import-type BlockShape from \ModerationAPI\Authors\AuthorGetResponse\Block + * @phpstan-import-type MetadataShape from \ModerationAPI\Authors\AuthorGetResponse\Metadata + * @phpstan-import-type MetricsShape from \ModerationAPI\Authors\AuthorGetResponse\Metrics + * @phpstan-import-type RiskEvaluationShape from \ModerationAPI\Authors\AuthorGetResponse\RiskEvaluation + * @phpstan-import-type TrustLevelShape from \ModerationAPI\Authors\AuthorGetResponse\TrustLevel + * * @phpstan-type AuthorGetResponseShape = array{ * id: string, - * block: Block|null, + * block: null|Block|BlockShape, * firstSeen: float, * lastSeen: float, - * metadata: Metadata, - * metrics: Metrics, - * riskEvaluation: RiskEvaluation|null, - * status: value-of, - * trustLevel: TrustLevel, + * metadata: Metadata|MetadataShape, + * metrics: Metrics|MetricsShape, + * riskEvaluation: null|RiskEvaluation|RiskEvaluationShape, + * status: Status|value-of, + * trustLevel: TrustLevel|TrustLevelShape, * email?: string|null, * externalID?: string|null, * externalLink?: string|null, @@ -168,19 +174,12 @@ public function __construct() * * You must use named parameters to construct any parameters with a default value. * - * @param Block|array{reason?: string|null, until?: float|null}|null $block - * @param Metadata|array{ - * emailVerified?: bool|null, - * identityVerified?: bool|null, - * isPayingCustomer?: bool|null, - * phoneVerified?: bool|null, - * } $metadata - * @param Metrics|array{ - * flaggedContent: float, totalContent: float, averageSentiment?: float|null - * } $metrics - * @param RiskEvaluation|array{riskLevel?: float|null}|null $riskEvaluation + * @param BlockShape|null $block + * @param MetadataShape $metadata + * @param MetricsShape $metrics + * @param RiskEvaluationShape|null $riskEvaluation * @param Status|value-of $status - * @param TrustLevel|array{level: float, manual: bool} $trustLevel + * @param TrustLevelShape $trustLevel */ public static function with( string $id, @@ -235,7 +234,7 @@ public function withID(string $id): self /** * Block or suspension details, if applicable. Null if the author is enabled. * - * @param Block|array{reason?: string|null, until?: float|null}|null $block + * @param BlockShape|null $block */ public function withBlock(Block|array|null $block): self { @@ -270,12 +269,7 @@ public function withLastSeen(float $lastSeen): self /** * Additional metadata provided by your system. We recommend including any relevant information that may assist in the moderation process. * - * @param Metadata|array{ - * emailVerified?: bool|null, - * identityVerified?: bool|null, - * isPayingCustomer?: bool|null, - * phoneVerified?: bool|null, - * } $metadata + * @param MetadataShape $metadata */ public function withMetadata(Metadata|array $metadata): self { @@ -286,9 +280,7 @@ public function withMetadata(Metadata|array $metadata): self } /** - * @param Metrics|array{ - * flaggedContent: float, totalContent: float, averageSentiment?: float|null - * } $metrics + * @param MetricsShape $metrics */ public function withMetrics(Metrics|array $metrics): self { @@ -301,7 +293,7 @@ public function withMetrics(Metrics|array $metrics): self /** * Risk assessment details, if available. * - * @param RiskEvaluation|array{riskLevel?: float|null}|null $riskEvaluation + * @param RiskEvaluationShape|null $riskEvaluation */ public function withRiskEvaluation( RiskEvaluation|array|null $riskEvaluation @@ -326,7 +318,7 @@ public function withStatus(Status|string $status): self } /** - * @param TrustLevel|array{level: float, manual: bool} $trustLevel + * @param TrustLevelShape $trustLevel */ public function withTrustLevel(TrustLevel|array $trustLevel): self { diff --git a/src/Authors/AuthorListParams.php b/src/Authors/AuthorListParams.php index f8717de..152fb99 100644 --- a/src/Authors/AuthorListParams.php +++ b/src/Authors/AuthorListParams.php @@ -17,13 +17,13 @@ * @see ModerationAPI\Services\AuthorsService::list() * * @phpstan-type AuthorListParamsShape = array{ - * contentTypes?: string, - * lastActiveDate?: string, - * memberSinceDate?: string, - * pageNumber?: float, - * pageSize?: float, - * sortBy?: SortBy|value-of, - * sortDirection?: SortDirection|value-of, + * contentTypes?: string|null, + * lastActiveDate?: string|null, + * memberSinceDate?: string|null, + * pageNumber?: float|null, + * pageSize?: float|null, + * sortBy?: null|SortBy|value-of, + * sortDirection?: null|SortDirection|value-of, * } */ final class AuthorListParams implements BaseModel diff --git a/src/Authors/AuthorListResponse.php b/src/Authors/AuthorListResponse.php index 0097476..30e5fd5 100644 --- a/src/Authors/AuthorListResponse.php +++ b/src/Authors/AuthorListResponse.php @@ -5,20 +5,17 @@ namespace ModerationAPI\Authors; use ModerationAPI\Authors\AuthorListResponse\Author; -use ModerationAPI\Authors\AuthorListResponse\Author\Block; -use ModerationAPI\Authors\AuthorListResponse\Author\Metadata; -use ModerationAPI\Authors\AuthorListResponse\Author\Metrics; -use ModerationAPI\Authors\AuthorListResponse\Author\RiskEvaluation; -use ModerationAPI\Authors\AuthorListResponse\Author\Status; -use ModerationAPI\Authors\AuthorListResponse\Author\TrustLevel; use ModerationAPI\Authors\AuthorListResponse\Pagination; use ModerationAPI\Core\Attributes\Required; use ModerationAPI\Core\Concerns\SdkModel; use ModerationAPI\Core\Contracts\BaseModel; /** + * @phpstan-import-type AuthorShape from \ModerationAPI\Authors\AuthorListResponse\Author + * @phpstan-import-type PaginationShape from \ModerationAPI\Authors\AuthorListResponse\Pagination + * * @phpstan-type AuthorListResponseShape = array{ - * authors: list, pagination: Pagination + * authors: list, pagination: Pagination|PaginationShape * } */ final class AuthorListResponse implements BaseModel @@ -57,30 +54,8 @@ public function __construct() * * You must use named parameters to construct any parameters with a default value. * - * @param list, - * trustLevel: TrustLevel, - * email?: string|null, - * externalID?: string|null, - * externalLink?: string|null, - * lastIncident?: float|null, - * name?: string|null, - * profilePicture?: string|null, - * }> $authors - * @param Pagination|array{ - * hasNextPage: bool, - * hasPreviousPage: bool, - * pageNumber: float, - * pageSize: float, - * total: float, - * } $pagination + * @param list $authors + * @param PaginationShape $pagination */ public static function with( array $authors, @@ -95,23 +70,7 @@ public static function with( } /** - * @param list, - * trustLevel: TrustLevel, - * email?: string|null, - * externalID?: string|null, - * externalLink?: string|null, - * lastIncident?: float|null, - * name?: string|null, - * profilePicture?: string|null, - * }> $authors + * @param list $authors */ public function withAuthors(array $authors): self { @@ -122,13 +81,7 @@ public function withAuthors(array $authors): self } /** - * @param Pagination|array{ - * hasNextPage: bool, - * hasPreviousPage: bool, - * pageNumber: float, - * pageSize: float, - * total: float, - * } $pagination + * @param PaginationShape $pagination */ public function withPagination(Pagination|array $pagination): self { diff --git a/src/Authors/AuthorListResponse/Author.php b/src/Authors/AuthorListResponse/Author.php index 3b7a556..29d72e1 100644 --- a/src/Authors/AuthorListResponse/Author.php +++ b/src/Authors/AuthorListResponse/Author.php @@ -16,16 +16,22 @@ use ModerationAPI\Core\Contracts\BaseModel; /** + * @phpstan-import-type BlockShape from \ModerationAPI\Authors\AuthorListResponse\Author\Block + * @phpstan-import-type MetadataShape from \ModerationAPI\Authors\AuthorListResponse\Author\Metadata + * @phpstan-import-type MetricsShape from \ModerationAPI\Authors\AuthorListResponse\Author\Metrics + * @phpstan-import-type RiskEvaluationShape from \ModerationAPI\Authors\AuthorListResponse\Author\RiskEvaluation + * @phpstan-import-type TrustLevelShape from \ModerationAPI\Authors\AuthorListResponse\Author\TrustLevel + * * @phpstan-type AuthorShape = array{ * id: string, - * block: Block|null, + * block: null|Block|BlockShape, * firstSeen: float, * lastSeen: float, - * metadata: Metadata, - * metrics: Metrics, - * riskEvaluation: RiskEvaluation|null, - * status: value-of, - * trustLevel: TrustLevel, + * metadata: Metadata|MetadataShape, + * metrics: Metrics|MetricsShape, + * riskEvaluation: null|RiskEvaluation|RiskEvaluationShape, + * status: Status|value-of, + * trustLevel: TrustLevel|TrustLevelShape, * email?: string|null, * externalID?: string|null, * externalLink?: string|null, @@ -168,19 +174,12 @@ public function __construct() * * You must use named parameters to construct any parameters with a default value. * - * @param Block|array{reason?: string|null, until?: float|null}|null $block - * @param Metadata|array{ - * emailVerified?: bool|null, - * identityVerified?: bool|null, - * isPayingCustomer?: bool|null, - * phoneVerified?: bool|null, - * } $metadata - * @param Metrics|array{ - * flaggedContent: float, totalContent: float, averageSentiment?: float|null - * } $metrics - * @param RiskEvaluation|array{riskLevel?: float|null}|null $riskEvaluation + * @param BlockShape|null $block + * @param MetadataShape $metadata + * @param MetricsShape $metrics + * @param RiskEvaluationShape|null $riskEvaluation * @param Status|value-of $status - * @param TrustLevel|array{level: float, manual: bool} $trustLevel + * @param TrustLevelShape $trustLevel */ public static function with( string $id, @@ -235,7 +234,7 @@ public function withID(string $id): self /** * Block or suspension details, if applicable. Null if the author is enabled. * - * @param Block|array{reason?: string|null, until?: float|null}|null $block + * @param BlockShape|null $block */ public function withBlock(Block|array|null $block): self { @@ -270,12 +269,7 @@ public function withLastSeen(float $lastSeen): self /** * Additional metadata provided by your system. We recommend including any relevant information that may assist in the moderation process. * - * @param Metadata|array{ - * emailVerified?: bool|null, - * identityVerified?: bool|null, - * isPayingCustomer?: bool|null, - * phoneVerified?: bool|null, - * } $metadata + * @param MetadataShape $metadata */ public function withMetadata(Metadata|array $metadata): self { @@ -286,9 +280,7 @@ public function withMetadata(Metadata|array $metadata): self } /** - * @param Metrics|array{ - * flaggedContent: float, totalContent: float, averageSentiment?: float|null - * } $metrics + * @param MetricsShape $metrics */ public function withMetrics(Metrics|array $metrics): self { @@ -301,7 +293,7 @@ public function withMetrics(Metrics|array $metrics): self /** * Risk assessment details, if available. * - * @param RiskEvaluation|array{riskLevel?: float|null}|null $riskEvaluation + * @param RiskEvaluationShape|null $riskEvaluation */ public function withRiskEvaluation( RiskEvaluation|array|null $riskEvaluation @@ -326,7 +318,7 @@ public function withStatus(Status|string $status): self } /** - * @param TrustLevel|array{level: float, manual: bool} $trustLevel + * @param TrustLevelShape $trustLevel */ public function withTrustLevel(TrustLevel|array $trustLevel): self { diff --git a/src/Authors/AuthorNewResponse.php b/src/Authors/AuthorNewResponse.php index 7accc08..c8b1a87 100644 --- a/src/Authors/AuthorNewResponse.php +++ b/src/Authors/AuthorNewResponse.php @@ -16,16 +16,22 @@ use ModerationAPI\Core\Contracts\BaseModel; /** + * @phpstan-import-type BlockShape from \ModerationAPI\Authors\AuthorNewResponse\Block + * @phpstan-import-type MetadataShape from \ModerationAPI\Authors\AuthorNewResponse\Metadata + * @phpstan-import-type MetricsShape from \ModerationAPI\Authors\AuthorNewResponse\Metrics + * @phpstan-import-type RiskEvaluationShape from \ModerationAPI\Authors\AuthorNewResponse\RiskEvaluation + * @phpstan-import-type TrustLevelShape from \ModerationAPI\Authors\AuthorNewResponse\TrustLevel + * * @phpstan-type AuthorNewResponseShape = array{ * id: string, - * block: Block|null, + * block: null|Block|BlockShape, * firstSeen: float, * lastSeen: float, - * metadata: Metadata, - * metrics: Metrics, - * riskEvaluation: RiskEvaluation|null, - * status: value-of, - * trustLevel: TrustLevel, + * metadata: Metadata|MetadataShape, + * metrics: Metrics|MetricsShape, + * riskEvaluation: null|RiskEvaluation|RiskEvaluationShape, + * status: Status|value-of, + * trustLevel: TrustLevel|TrustLevelShape, * email?: string|null, * externalID?: string|null, * externalLink?: string|null, @@ -168,19 +174,12 @@ public function __construct() * * You must use named parameters to construct any parameters with a default value. * - * @param Block|array{reason?: string|null, until?: float|null}|null $block - * @param Metadata|array{ - * emailVerified?: bool|null, - * identityVerified?: bool|null, - * isPayingCustomer?: bool|null, - * phoneVerified?: bool|null, - * } $metadata - * @param Metrics|array{ - * flaggedContent: float, totalContent: float, averageSentiment?: float|null - * } $metrics - * @param RiskEvaluation|array{riskLevel?: float|null}|null $riskEvaluation + * @param BlockShape|null $block + * @param MetadataShape $metadata + * @param MetricsShape $metrics + * @param RiskEvaluationShape|null $riskEvaluation * @param Status|value-of $status - * @param TrustLevel|array{level: float, manual: bool} $trustLevel + * @param TrustLevelShape $trustLevel */ public static function with( string $id, @@ -235,7 +234,7 @@ public function withID(string $id): self /** * Block or suspension details, if applicable. Null if the author is enabled. * - * @param Block|array{reason?: string|null, until?: float|null}|null $block + * @param BlockShape|null $block */ public function withBlock(Block|array|null $block): self { @@ -270,12 +269,7 @@ public function withLastSeen(float $lastSeen): self /** * Additional metadata provided by your system. We recommend including any relevant information that may assist in the moderation process. * - * @param Metadata|array{ - * emailVerified?: bool|null, - * identityVerified?: bool|null, - * isPayingCustomer?: bool|null, - * phoneVerified?: bool|null, - * } $metadata + * @param MetadataShape $metadata */ public function withMetadata(Metadata|array $metadata): self { @@ -286,9 +280,7 @@ public function withMetadata(Metadata|array $metadata): self } /** - * @param Metrics|array{ - * flaggedContent: float, totalContent: float, averageSentiment?: float|null - * } $metrics + * @param MetricsShape $metrics */ public function withMetrics(Metrics|array $metrics): self { @@ -301,7 +293,7 @@ public function withMetrics(Metrics|array $metrics): self /** * Risk assessment details, if available. * - * @param RiskEvaluation|array{riskLevel?: float|null}|null $riskEvaluation + * @param RiskEvaluationShape|null $riskEvaluation */ public function withRiskEvaluation( RiskEvaluation|array|null $riskEvaluation @@ -326,7 +318,7 @@ public function withStatus(Status|string $status): self } /** - * @param TrustLevel|array{level: float, manual: bool} $trustLevel + * @param TrustLevelShape $trustLevel */ public function withTrustLevel(TrustLevel|array $trustLevel): self { diff --git a/src/Authors/AuthorUpdateParams.php b/src/Authors/AuthorUpdateParams.php index 63c65d1..d434a9e 100644 --- a/src/Authors/AuthorUpdateParams.php +++ b/src/Authors/AuthorUpdateParams.php @@ -15,18 +15,15 @@ * * @see ModerationAPI\Services\AuthorsService::update() * + * @phpstan-import-type MetadataShape from \ModerationAPI\Authors\AuthorUpdateParams\Metadata + * * @phpstan-type AuthorUpdateParamsShape = array{ * email?: string|null, * externalLink?: string|null, - * firstSeen?: float, - * lastSeen?: float, + * firstSeen?: float|null, + * lastSeen?: float|null, * manualTrustLevel?: float|null, - * metadata?: Metadata|array{ - * emailVerified?: bool|null, - * identityVerified?: bool|null, - * isPayingCustomer?: bool|null, - * phoneVerified?: bool|null, - * }, + * metadata?: MetadataShape|null, * name?: string|null, * profilePicture?: string|null, * } @@ -92,12 +89,7 @@ public function __construct() * * You must use named parameters to construct any parameters with a default value. * - * @param Metadata|array{ - * emailVerified?: bool|null, - * identityVerified?: bool|null, - * isPayingCustomer?: bool|null, - * phoneVerified?: bool|null, - * } $metadata + * @param MetadataShape $metadata */ public static function with( ?string $email = null, @@ -178,12 +170,7 @@ public function withManualTrustLevel(?float $manualTrustLevel): self /** * Additional metadata provided by your system. We recommend including any relevant information that may assist in the moderation process. * - * @param Metadata|array{ - * emailVerified?: bool|null, - * identityVerified?: bool|null, - * isPayingCustomer?: bool|null, - * phoneVerified?: bool|null, - * } $metadata + * @param MetadataShape $metadata */ public function withMetadata(Metadata|array $metadata): self { diff --git a/src/Authors/AuthorUpdateResponse.php b/src/Authors/AuthorUpdateResponse.php index 552a3f2..fb9b39b 100644 --- a/src/Authors/AuthorUpdateResponse.php +++ b/src/Authors/AuthorUpdateResponse.php @@ -16,16 +16,22 @@ use ModerationAPI\Core\Contracts\BaseModel; /** + * @phpstan-import-type BlockShape from \ModerationAPI\Authors\AuthorUpdateResponse\Block + * @phpstan-import-type MetadataShape from \ModerationAPI\Authors\AuthorUpdateResponse\Metadata + * @phpstan-import-type MetricsShape from \ModerationAPI\Authors\AuthorUpdateResponse\Metrics + * @phpstan-import-type RiskEvaluationShape from \ModerationAPI\Authors\AuthorUpdateResponse\RiskEvaluation + * @phpstan-import-type TrustLevelShape from \ModerationAPI\Authors\AuthorUpdateResponse\TrustLevel + * * @phpstan-type AuthorUpdateResponseShape = array{ * id: string, - * block: Block|null, + * block: null|Block|BlockShape, * firstSeen: float, * lastSeen: float, - * metadata: Metadata, - * metrics: Metrics, - * riskEvaluation: RiskEvaluation|null, - * status: value-of, - * trustLevel: TrustLevel, + * metadata: Metadata|MetadataShape, + * metrics: Metrics|MetricsShape, + * riskEvaluation: null|RiskEvaluation|RiskEvaluationShape, + * status: Status|value-of, + * trustLevel: TrustLevel|TrustLevelShape, * email?: string|null, * externalID?: string|null, * externalLink?: string|null, @@ -168,19 +174,12 @@ public function __construct() * * You must use named parameters to construct any parameters with a default value. * - * @param Block|array{reason?: string|null, until?: float|null}|null $block - * @param Metadata|array{ - * emailVerified?: bool|null, - * identityVerified?: bool|null, - * isPayingCustomer?: bool|null, - * phoneVerified?: bool|null, - * } $metadata - * @param Metrics|array{ - * flaggedContent: float, totalContent: float, averageSentiment?: float|null - * } $metrics - * @param RiskEvaluation|array{riskLevel?: float|null}|null $riskEvaluation + * @param BlockShape|null $block + * @param MetadataShape $metadata + * @param MetricsShape $metrics + * @param RiskEvaluationShape|null $riskEvaluation * @param Status|value-of $status - * @param TrustLevel|array{level: float, manual: bool} $trustLevel + * @param TrustLevelShape $trustLevel */ public static function with( string $id, @@ -235,7 +234,7 @@ public function withID(string $id): self /** * Block or suspension details, if applicable. Null if the author is enabled. * - * @param Block|array{reason?: string|null, until?: float|null}|null $block + * @param BlockShape|null $block */ public function withBlock(Block|array|null $block): self { @@ -270,12 +269,7 @@ public function withLastSeen(float $lastSeen): self /** * Additional metadata provided by your system. We recommend including any relevant information that may assist in the moderation process. * - * @param Metadata|array{ - * emailVerified?: bool|null, - * identityVerified?: bool|null, - * isPayingCustomer?: bool|null, - * phoneVerified?: bool|null, - * } $metadata + * @param MetadataShape $metadata */ public function withMetadata(Metadata|array $metadata): self { @@ -286,9 +280,7 @@ public function withMetadata(Metadata|array $metadata): self } /** - * @param Metrics|array{ - * flaggedContent: float, totalContent: float, averageSentiment?: float|null - * } $metrics + * @param MetricsShape $metrics */ public function withMetrics(Metrics|array $metrics): self { @@ -301,7 +293,7 @@ public function withMetrics(Metrics|array $metrics): self /** * Risk assessment details, if available. * - * @param RiskEvaluation|array{riskLevel?: float|null}|null $riskEvaluation + * @param RiskEvaluationShape|null $riskEvaluation */ public function withRiskEvaluation( RiskEvaluation|array|null $riskEvaluation @@ -326,7 +318,7 @@ public function withStatus(Status|string $status): self } /** - * @param TrustLevel|array{level: float, manual: bool} $trustLevel + * @param TrustLevelShape $trustLevel */ public function withTrustLevel(TrustLevel|array $trustLevel): self { diff --git a/src/Content/ContentSubmitParams.php b/src/Content/ContentSubmitParams.php index 2d8e14b..87d3de8 100644 --- a/src/Content/ContentSubmitParams.php +++ b/src/Content/ContentSubmitParams.php @@ -23,7 +23,6 @@ use ModerationAPI\Content\ContentSubmitParams\Policy\IllicitTobacco; use ModerationAPI\Content\ContentSubmitParams\Policy\PersonalInformation; use ModerationAPI\Content\ContentSubmitParams\Policy\PiiMasking; -use ModerationAPI\Content\ContentSubmitParams\Policy\PiiMasking\Entity; use ModerationAPI\Content\ContentSubmitParams\Policy\Political; use ModerationAPI\Content\ContentSubmitParams\Policy\Profanity; use ModerationAPI\Content\ContentSubmitParams\Policy\Religion; @@ -44,54 +43,19 @@ /** * @see ModerationAPI\Services\ContentService::submit() * + * @phpstan-import-type ContentShape from \ModerationAPI\Content\ContentSubmitParams\Content + * @phpstan-import-type PolicyShape from \ModerationAPI\Content\ContentSubmitParams\Policy + * * @phpstan-type ContentSubmitParamsShape = array{ - * content: Text|array{text: string, type?: 'text'}|Image|array{ - * type?: 'image', url: string - * }|Video|array{type?: 'video', url: string}|Audio|array{ - * type?: 'audio', url: string - * }|Object_|array{ - * data: array, - * type?: 'object', - * }, - * authorID?: string, - * channel?: string, - * contentID?: string, - * conversationID?: string, - * doNotStore?: bool, - * metadata?: array, - * metaType?: MetaType|value-of, - * policies?: list - * }|URLMasking|array{ - * id?: 'url', - * entities: array, - * }|Guideline|array{ - * id?: 'guideline', flag: bool, guidelineKey: string, instructions: string - * }>, + * content: ContentShape, + * authorID?: string|null, + * channel?: string|null, + * contentID?: string|null, + * conversationID?: string|null, + * doNotStore?: bool|null, + * metadata?: array|null, + * metaType?: null|MetaType|value-of, + * policies?: list|null, * } */ final class ContentSubmitParams implements BaseModel @@ -184,48 +148,10 @@ public function __construct() * * You must use named parameters to construct any parameters with a default value. * - * @param Text|array{text: string, type?: 'text'}|Image|array{ - * type?: 'image', url: string - * }|Video|array{type?: 'video', url: string}|Audio|array{ - * type?: 'audio', url: string - * }|Object_|array{ - * data: array, - * type?: 'object', - * } $content + * @param ContentShape $content * @param array $metadata * @param MetaType|value-of $metaType - * @param list - * }|URLMasking|array{ - * id?: 'url', - * entities: array, - * }|Guideline|array{ - * id?: 'guideline', flag: bool, guidelineKey: string, instructions: string - * }> $policies + * @param list $policies */ public static function with( Text|array|Image|Video|Audio|Object_ $content, @@ -257,14 +183,7 @@ public static function with( /** * The content sent for moderation. * - * @param Text|array{text: string, type?: 'text'}|Image|array{ - * type?: 'image', url: string - * }|Video|array{type?: 'video', url: string}|Audio|array{ - * type?: 'audio', url: string - * }|Object_|array{ - * data: array, - * type?: 'object', - * } $content + * @param ContentShape $content */ public function withContent( Text|array|Image|Video|Audio|Object_ $content @@ -359,38 +278,7 @@ public function withMetaType(MetaType|string $metaType): self /** * (Enterprise) override the channel policies for this moderation request only. * - * @param list - * }|URLMasking|array{ - * id?: 'url', - * entities: array, - * }|Guideline|array{ - * id?: 'guideline', flag: bool, guidelineKey: string, instructions: string - * }> $policies + * @param list $policies */ public function withPolicies(array $policies): self { diff --git a/src/Content/ContentSubmitParams/Content.php b/src/Content/ContentSubmitParams/Content.php index b1d374a..868d47e 100644 --- a/src/Content/ContentSubmitParams/Content.php +++ b/src/Content/ContentSubmitParams/Content.php @@ -15,6 +15,14 @@ /** * The content sent for moderation. + * + * @phpstan-import-type TextShape from \ModerationAPI\Content\ContentSubmitParams\Content\Text + * @phpstan-import-type ImageShape from \ModerationAPI\Content\ContentSubmitParams\Content\Image + * @phpstan-import-type VideoShape from \ModerationAPI\Content\ContentSubmitParams\Content\Video + * @phpstan-import-type AudioShape from \ModerationAPI\Content\ContentSubmitParams\Content\Audio + * @phpstan-import-type ObjectShape from \ModerationAPI\Content\ContentSubmitParams\Content\Object_ + * + * @phpstan-type ContentShape = TextShape|ImageShape|VideoShape|AudioShape|ObjectShape */ final class Content implements ConverterSource { diff --git a/src/Content/ContentSubmitParams/Content/Audio.php b/src/Content/ContentSubmitParams/Content/Audio.php index 6771041..c11689a 100644 --- a/src/Content/ContentSubmitParams/Content/Audio.php +++ b/src/Content/ContentSubmitParams/Content/Audio.php @@ -11,7 +11,7 @@ /** * Audio. * - * @phpstan-type AudioShape = array{type?: 'audio', url: string} + * @phpstan-type AudioShape = array{type: 'audio', url: string} */ final class Audio implements BaseModel { diff --git a/src/Content/ContentSubmitParams/Content/Image.php b/src/Content/ContentSubmitParams/Content/Image.php index 86124e4..11320b4 100644 --- a/src/Content/ContentSubmitParams/Content/Image.php +++ b/src/Content/ContentSubmitParams/Content/Image.php @@ -11,7 +11,7 @@ /** * Image. * - * @phpstan-type ImageShape = array{type?: 'image', url: string} + * @phpstan-type ImageShape = array{type: 'image', url: string} */ final class Image implements BaseModel { diff --git a/src/Content/ContentSubmitParams/Content/Object_.php b/src/Content/ContentSubmitParams/Content/Object_.php index 5ed5129..1bf56bf 100644 --- a/src/Content/ContentSubmitParams/Content/Object_.php +++ b/src/Content/ContentSubmitParams/Content/Object_.php @@ -16,10 +16,9 @@ /** * Object. * - * @phpstan-type ObjectShape = array{ - * data: array, - * type?: 'object', - * } + * @phpstan-import-type DataShape from \ModerationAPI\Content\ContentSubmitParams\Content\Object_\Data + * + * @phpstan-type ObjectShape = array{data: array, type: 'object'} */ final class Object_ implements BaseModel { @@ -62,15 +61,7 @@ public function __construct() * * You must use named parameters to construct any parameters with a default value. * - * @param array $data + * @param array $data */ public static function with(array $data): self { @@ -84,15 +75,7 @@ public static function with(array $data): self /** * Values in the object. Can be mixed content types. * - * @param array $data + * @param array $data */ public function withData(array $data): self { diff --git a/src/Content/ContentSubmitParams/Content/Object_/Data.php b/src/Content/ContentSubmitParams/Content/Object_/Data.php index ea3b9e7..bf0497c 100644 --- a/src/Content/ContentSubmitParams/Content/Object_/Data.php +++ b/src/Content/ContentSubmitParams/Content/Object_/Data.php @@ -14,6 +14,13 @@ /** * Text. + * + * @phpstan-import-type TextShape from \ModerationAPI\Content\ContentSubmitParams\Content\Object_\Data\Text + * @phpstan-import-type ImageShape from \ModerationAPI\Content\ContentSubmitParams\Content\Object_\Data\Image + * @phpstan-import-type VideoShape from \ModerationAPI\Content\ContentSubmitParams\Content\Object_\Data\Video + * @phpstan-import-type AudioShape from \ModerationAPI\Content\ContentSubmitParams\Content\Object_\Data\Audio + * + * @phpstan-type DataShape = TextShape|ImageShape|VideoShape|AudioShape */ final class Data implements ConverterSource { diff --git a/src/Content/ContentSubmitParams/Content/Object_/Data/Audio.php b/src/Content/ContentSubmitParams/Content/Object_/Data/Audio.php index 461aad0..b138e21 100644 --- a/src/Content/ContentSubmitParams/Content/Object_/Data/Audio.php +++ b/src/Content/ContentSubmitParams/Content/Object_/Data/Audio.php @@ -11,7 +11,7 @@ /** * Audio. * - * @phpstan-type AudioShape = array{type?: 'audio', url: string} + * @phpstan-type AudioShape = array{type: 'audio', url: string} */ final class Audio implements BaseModel { diff --git a/src/Content/ContentSubmitParams/Content/Object_/Data/Image.php b/src/Content/ContentSubmitParams/Content/Object_/Data/Image.php index a6eaffb..038cbad 100644 --- a/src/Content/ContentSubmitParams/Content/Object_/Data/Image.php +++ b/src/Content/ContentSubmitParams/Content/Object_/Data/Image.php @@ -11,7 +11,7 @@ /** * Image. * - * @phpstan-type ImageShape = array{type?: 'image', url: string} + * @phpstan-type ImageShape = array{type: 'image', url: string} */ final class Image implements BaseModel { diff --git a/src/Content/ContentSubmitParams/Content/Object_/Data/Text.php b/src/Content/ContentSubmitParams/Content/Object_/Data/Text.php index 456ce21..a91a425 100644 --- a/src/Content/ContentSubmitParams/Content/Object_/Data/Text.php +++ b/src/Content/ContentSubmitParams/Content/Object_/Data/Text.php @@ -11,7 +11,7 @@ /** * Text. * - * @phpstan-type TextShape = array{text: string, type?: 'text'} + * @phpstan-type TextShape = array{text: string, type: 'text'} */ final class Text implements BaseModel { diff --git a/src/Content/ContentSubmitParams/Content/Object_/Data/Video.php b/src/Content/ContentSubmitParams/Content/Object_/Data/Video.php index 6be05bb..f7aef23 100644 --- a/src/Content/ContentSubmitParams/Content/Object_/Data/Video.php +++ b/src/Content/ContentSubmitParams/Content/Object_/Data/Video.php @@ -11,7 +11,7 @@ /** * Video. * - * @phpstan-type VideoShape = array{type?: 'video', url: string} + * @phpstan-type VideoShape = array{type: 'video', url: string} */ final class Video implements BaseModel { diff --git a/src/Content/ContentSubmitParams/Content/Text.php b/src/Content/ContentSubmitParams/Content/Text.php index 43406b3..4512c7c 100644 --- a/src/Content/ContentSubmitParams/Content/Text.php +++ b/src/Content/ContentSubmitParams/Content/Text.php @@ -11,7 +11,7 @@ /** * Text. * - * @phpstan-type TextShape = array{text: string, type?: 'text'} + * @phpstan-type TextShape = array{text: string, type: 'text'} */ final class Text implements BaseModel { diff --git a/src/Content/ContentSubmitParams/Content/Video.php b/src/Content/ContentSubmitParams/Content/Video.php index 6bb5dc5..89e274b 100644 --- a/src/Content/ContentSubmitParams/Content/Video.php +++ b/src/Content/ContentSubmitParams/Content/Video.php @@ -11,7 +11,7 @@ /** * Video. * - * @phpstan-type VideoShape = array{type?: 'video', url: string} + * @phpstan-type VideoShape = array{type: 'video', url: string} */ final class Video implements BaseModel { diff --git a/src/Content/ContentSubmitParams/Policy.php b/src/Content/ContentSubmitParams/Policy.php index 0b0fb0e..170260a 100644 --- a/src/Content/ContentSubmitParams/Policy.php +++ b/src/Content/ContentSubmitParams/Policy.php @@ -31,6 +31,33 @@ use ModerationAPI\Core\Conversion\Contracts\Converter; use ModerationAPI\Core\Conversion\Contracts\ConverterSource; +/** + * @phpstan-import-type ToxicityShape from \ModerationAPI\Content\ContentSubmitParams\Policy\Toxicity + * @phpstan-import-type PersonalInformationShape from \ModerationAPI\Content\ContentSubmitParams\Policy\PersonalInformation + * @phpstan-import-type ToxicitySevereShape from \ModerationAPI\Content\ContentSubmitParams\Policy\ToxicitySevere + * @phpstan-import-type HateShape from \ModerationAPI\Content\ContentSubmitParams\Policy\Hate + * @phpstan-import-type IllicitShape from \ModerationAPI\Content\ContentSubmitParams\Policy\Illicit + * @phpstan-import-type IllicitDrugsShape from \ModerationAPI\Content\ContentSubmitParams\Policy\IllicitDrugs + * @phpstan-import-type IllicitAlcoholShape from \ModerationAPI\Content\ContentSubmitParams\Policy\IllicitAlcohol + * @phpstan-import-type IllicitFirearmsShape from \ModerationAPI\Content\ContentSubmitParams\Policy\IllicitFirearms + * @phpstan-import-type IllicitTobaccoShape from \ModerationAPI\Content\ContentSubmitParams\Policy\IllicitTobacco + * @phpstan-import-type IllicitGamblingShape from \ModerationAPI\Content\ContentSubmitParams\Policy\IllicitGambling + * @phpstan-import-type SexualShape from \ModerationAPI\Content\ContentSubmitParams\Policy\Sexual + * @phpstan-import-type FlirtationShape from \ModerationAPI\Content\ContentSubmitParams\Policy\Flirtation + * @phpstan-import-type ProfanityShape from \ModerationAPI\Content\ContentSubmitParams\Policy\Profanity + * @phpstan-import-type ViolenceShape from \ModerationAPI\Content\ContentSubmitParams\Policy\Violence + * @phpstan-import-type SelfHarmShape from \ModerationAPI\Content\ContentSubmitParams\Policy\SelfHarm + * @phpstan-import-type SpamShape from \ModerationAPI\Content\ContentSubmitParams\Policy\Spam + * @phpstan-import-type SelfPromotionShape from \ModerationAPI\Content\ContentSubmitParams\Policy\SelfPromotion + * @phpstan-import-type PoliticalShape from \ModerationAPI\Content\ContentSubmitParams\Policy\Political + * @phpstan-import-type ReligionShape from \ModerationAPI\Content\ContentSubmitParams\Policy\Religion + * @phpstan-import-type CodeAbuseShape from \ModerationAPI\Content\ContentSubmitParams\Policy\CodeAbuse + * @phpstan-import-type PiiMaskingShape from \ModerationAPI\Content\ContentSubmitParams\Policy\PiiMasking + * @phpstan-import-type URLMaskingShape from \ModerationAPI\Content\ContentSubmitParams\Policy\URLMasking + * @phpstan-import-type GuidelineShape from \ModerationAPI\Content\ContentSubmitParams\Policy\Guideline + * + * @phpstan-type PolicyShape = ToxicityShape|PersonalInformationShape|ToxicitySevereShape|HateShape|IllicitShape|IllicitDrugsShape|IllicitAlcoholShape|IllicitFirearmsShape|IllicitTobaccoShape|IllicitGamblingShape|SexualShape|FlirtationShape|ProfanityShape|ViolenceShape|SelfHarmShape|SpamShape|SelfPromotionShape|PoliticalShape|ReligionShape|CodeAbuseShape|PiiMaskingShape|URLMaskingShape|GuidelineShape + */ final class Policy implements ConverterSource { use SdkUnion; diff --git a/src/Content/ContentSubmitParams/Policy/CodeAbuse.php b/src/Content/ContentSubmitParams/Policy/CodeAbuse.php index 1f00b84..e3e3edf 100644 --- a/src/Content/ContentSubmitParams/Policy/CodeAbuse.php +++ b/src/Content/ContentSubmitParams/Policy/CodeAbuse.php @@ -9,7 +9,7 @@ use ModerationAPI\Core\Contracts\BaseModel; /** - * @phpstan-type CodeAbuseShape = array{id?: 'code_abuse', flag: bool} + * @phpstan-type CodeAbuseShape = array{id: 'code_abuse', flag: bool} */ final class CodeAbuse implements BaseModel { diff --git a/src/Content/ContentSubmitParams/Policy/Flirtation.php b/src/Content/ContentSubmitParams/Policy/Flirtation.php index 9232ba7..8487544 100644 --- a/src/Content/ContentSubmitParams/Policy/Flirtation.php +++ b/src/Content/ContentSubmitParams/Policy/Flirtation.php @@ -9,7 +9,7 @@ use ModerationAPI\Core\Contracts\BaseModel; /** - * @phpstan-type FlirtationShape = array{id?: 'flirtation', flag: bool} + * @phpstan-type FlirtationShape = array{id: 'flirtation', flag: bool} */ final class Flirtation implements BaseModel { diff --git a/src/Content/ContentSubmitParams/Policy/Guideline.php b/src/Content/ContentSubmitParams/Policy/Guideline.php index 2412b50..16f8752 100644 --- a/src/Content/ContentSubmitParams/Policy/Guideline.php +++ b/src/Content/ContentSubmitParams/Policy/Guideline.php @@ -10,7 +10,7 @@ /** * @phpstan-type GuidelineShape = array{ - * id?: 'guideline', flag: bool, guidelineKey: string, instructions: string + * id: 'guideline', flag: bool, guidelineKey: string, instructions: string * } */ final class Guideline implements BaseModel diff --git a/src/Content/ContentSubmitParams/Policy/Hate.php b/src/Content/ContentSubmitParams/Policy/Hate.php index 565421e..fb8ff6b 100644 --- a/src/Content/ContentSubmitParams/Policy/Hate.php +++ b/src/Content/ContentSubmitParams/Policy/Hate.php @@ -9,7 +9,7 @@ use ModerationAPI\Core\Contracts\BaseModel; /** - * @phpstan-type HateShape = array{id?: 'hate', flag: bool} + * @phpstan-type HateShape = array{id: 'hate', flag: bool} */ final class Hate implements BaseModel { diff --git a/src/Content/ContentSubmitParams/Policy/Illicit.php b/src/Content/ContentSubmitParams/Policy/Illicit.php index 44ad94a..2f6e206 100644 --- a/src/Content/ContentSubmitParams/Policy/Illicit.php +++ b/src/Content/ContentSubmitParams/Policy/Illicit.php @@ -9,7 +9,7 @@ use ModerationAPI\Core\Contracts\BaseModel; /** - * @phpstan-type IllicitShape = array{id?: 'illicit', flag: bool} + * @phpstan-type IllicitShape = array{id: 'illicit', flag: bool} */ final class Illicit implements BaseModel { diff --git a/src/Content/ContentSubmitParams/Policy/IllicitAlcohol.php b/src/Content/ContentSubmitParams/Policy/IllicitAlcohol.php index de716aa..312afc0 100644 --- a/src/Content/ContentSubmitParams/Policy/IllicitAlcohol.php +++ b/src/Content/ContentSubmitParams/Policy/IllicitAlcohol.php @@ -9,7 +9,7 @@ use ModerationAPI\Core\Contracts\BaseModel; /** - * @phpstan-type IllicitAlcoholShape = array{id?: 'illicit_alcohol', flag: bool} + * @phpstan-type IllicitAlcoholShape = array{id: 'illicit_alcohol', flag: bool} */ final class IllicitAlcohol implements BaseModel { diff --git a/src/Content/ContentSubmitParams/Policy/IllicitDrugs.php b/src/Content/ContentSubmitParams/Policy/IllicitDrugs.php index 9ac3cdd..43a720d 100644 --- a/src/Content/ContentSubmitParams/Policy/IllicitDrugs.php +++ b/src/Content/ContentSubmitParams/Policy/IllicitDrugs.php @@ -9,7 +9,7 @@ use ModerationAPI\Core\Contracts\BaseModel; /** - * @phpstan-type IllicitDrugsShape = array{id?: 'illicit_drugs', flag: bool} + * @phpstan-type IllicitDrugsShape = array{id: 'illicit_drugs', flag: bool} */ final class IllicitDrugs implements BaseModel { diff --git a/src/Content/ContentSubmitParams/Policy/IllicitFirearms.php b/src/Content/ContentSubmitParams/Policy/IllicitFirearms.php index 67a07d8..d239886 100644 --- a/src/Content/ContentSubmitParams/Policy/IllicitFirearms.php +++ b/src/Content/ContentSubmitParams/Policy/IllicitFirearms.php @@ -9,7 +9,7 @@ use ModerationAPI\Core\Contracts\BaseModel; /** - * @phpstan-type IllicitFirearmsShape = array{id?: 'illicit_firearms', flag: bool} + * @phpstan-type IllicitFirearmsShape = array{id: 'illicit_firearms', flag: bool} */ final class IllicitFirearms implements BaseModel { diff --git a/src/Content/ContentSubmitParams/Policy/IllicitGambling.php b/src/Content/ContentSubmitParams/Policy/IllicitGambling.php index 5b962f3..df6d101 100644 --- a/src/Content/ContentSubmitParams/Policy/IllicitGambling.php +++ b/src/Content/ContentSubmitParams/Policy/IllicitGambling.php @@ -9,7 +9,7 @@ use ModerationAPI\Core\Contracts\BaseModel; /** - * @phpstan-type IllicitGamblingShape = array{id?: 'illicit_gambling', flag: bool} + * @phpstan-type IllicitGamblingShape = array{id: 'illicit_gambling', flag: bool} */ final class IllicitGambling implements BaseModel { diff --git a/src/Content/ContentSubmitParams/Policy/IllicitTobacco.php b/src/Content/ContentSubmitParams/Policy/IllicitTobacco.php index df3bd3c..3e8686e 100644 --- a/src/Content/ContentSubmitParams/Policy/IllicitTobacco.php +++ b/src/Content/ContentSubmitParams/Policy/IllicitTobacco.php @@ -9,7 +9,7 @@ use ModerationAPI\Core\Contracts\BaseModel; /** - * @phpstan-type IllicitTobaccoShape = array{id?: 'illicit_tobacco', flag: bool} + * @phpstan-type IllicitTobaccoShape = array{id: 'illicit_tobacco', flag: bool} */ final class IllicitTobacco implements BaseModel { diff --git a/src/Content/ContentSubmitParams/Policy/PersonalInformation.php b/src/Content/ContentSubmitParams/Policy/PersonalInformation.php index 3f8c6b3..b42873e 100644 --- a/src/Content/ContentSubmitParams/Policy/PersonalInformation.php +++ b/src/Content/ContentSubmitParams/Policy/PersonalInformation.php @@ -10,7 +10,7 @@ /** * @phpstan-type PersonalInformationShape = array{ - * id?: 'personal_information', flag: bool + * id: 'personal_information', flag: bool * } */ final class PersonalInformation implements BaseModel diff --git a/src/Content/ContentSubmitParams/Policy/PiiMasking.php b/src/Content/ContentSubmitParams/Policy/PiiMasking.php index b08c642..3432ace 100644 --- a/src/Content/ContentSubmitParams/Policy/PiiMasking.php +++ b/src/Content/ContentSubmitParams/Policy/PiiMasking.php @@ -5,14 +5,15 @@ namespace ModerationAPI\Content\ContentSubmitParams\Policy; use ModerationAPI\Content\ContentSubmitParams\Policy\PiiMasking\Entity; -use ModerationAPI\Content\ContentSubmitParams\Policy\PiiMasking\Entity\ID; use ModerationAPI\Core\Attributes\Required; use ModerationAPI\Core\Concerns\SdkModel; use ModerationAPI\Core\Contracts\BaseModel; /** + * @phpstan-import-type EntityShape from \ModerationAPI\Content\ContentSubmitParams\Policy\PiiMasking\Entity + * * @phpstan-type PiiMaskingShape = array{ - * id?: 'pii', entities: array + * id: 'pii', entities: array * } */ final class PiiMasking implements BaseModel @@ -52,13 +53,7 @@ public function __construct() * * You must use named parameters to construct any parameters with a default value. * - * @param array, - * enable: bool, - * flag: bool, - * shouldMask: bool, - * mask?: string|null, - * }> $entities + * @param array $entities */ public static function with(array $entities): self { @@ -70,13 +65,7 @@ public static function with(array $entities): self } /** - * @param array, - * enable: bool, - * flag: bool, - * shouldMask: bool, - * mask?: string|null, - * }> $entities + * @param array $entities */ public function withEntities(array $entities): self { diff --git a/src/Content/ContentSubmitParams/Policy/PiiMasking/Entity.php b/src/Content/ContentSubmitParams/Policy/PiiMasking/Entity.php index 240c287..c3ef156 100644 --- a/src/Content/ContentSubmitParams/Policy/PiiMasking/Entity.php +++ b/src/Content/ContentSubmitParams/Policy/PiiMasking/Entity.php @@ -12,7 +12,7 @@ /** * @phpstan-type EntityShape = array{ - * id: value-of, + * id: ID|value-of, * enable: bool, * flag: bool, * shouldMask: bool, diff --git a/src/Content/ContentSubmitParams/Policy/Political.php b/src/Content/ContentSubmitParams/Policy/Political.php index 53a0ac6..b49d609 100644 --- a/src/Content/ContentSubmitParams/Policy/Political.php +++ b/src/Content/ContentSubmitParams/Policy/Political.php @@ -9,7 +9,7 @@ use ModerationAPI\Core\Contracts\BaseModel; /** - * @phpstan-type PoliticalShape = array{id?: 'political', flag: bool} + * @phpstan-type PoliticalShape = array{id: 'political', flag: bool} */ final class Political implements BaseModel { diff --git a/src/Content/ContentSubmitParams/Policy/Profanity.php b/src/Content/ContentSubmitParams/Policy/Profanity.php index 7200d73..5378add 100644 --- a/src/Content/ContentSubmitParams/Policy/Profanity.php +++ b/src/Content/ContentSubmitParams/Policy/Profanity.php @@ -9,7 +9,7 @@ use ModerationAPI\Core\Contracts\BaseModel; /** - * @phpstan-type ProfanityShape = array{id?: 'profanity', flag: bool} + * @phpstan-type ProfanityShape = array{id: 'profanity', flag: bool} */ final class Profanity implements BaseModel { diff --git a/src/Content/ContentSubmitParams/Policy/Religion.php b/src/Content/ContentSubmitParams/Policy/Religion.php index a1fe729..1161303 100644 --- a/src/Content/ContentSubmitParams/Policy/Religion.php +++ b/src/Content/ContentSubmitParams/Policy/Religion.php @@ -9,7 +9,7 @@ use ModerationAPI\Core\Contracts\BaseModel; /** - * @phpstan-type ReligionShape = array{id?: 'religion', flag: bool} + * @phpstan-type ReligionShape = array{id: 'religion', flag: bool} */ final class Religion implements BaseModel { diff --git a/src/Content/ContentSubmitParams/Policy/SelfHarm.php b/src/Content/ContentSubmitParams/Policy/SelfHarm.php index dab39ce..19064cf 100644 --- a/src/Content/ContentSubmitParams/Policy/SelfHarm.php +++ b/src/Content/ContentSubmitParams/Policy/SelfHarm.php @@ -9,7 +9,7 @@ use ModerationAPI\Core\Contracts\BaseModel; /** - * @phpstan-type SelfHarmShape = array{id?: 'self_harm', flag: bool} + * @phpstan-type SelfHarmShape = array{id: 'self_harm', flag: bool} */ final class SelfHarm implements BaseModel { diff --git a/src/Content/ContentSubmitParams/Policy/SelfPromotion.php b/src/Content/ContentSubmitParams/Policy/SelfPromotion.php index 47a7da4..5780e70 100644 --- a/src/Content/ContentSubmitParams/Policy/SelfPromotion.php +++ b/src/Content/ContentSubmitParams/Policy/SelfPromotion.php @@ -9,7 +9,7 @@ use ModerationAPI\Core\Contracts\BaseModel; /** - * @phpstan-type SelfPromotionShape = array{id?: 'self_promotion', flag: bool} + * @phpstan-type SelfPromotionShape = array{id: 'self_promotion', flag: bool} */ final class SelfPromotion implements BaseModel { diff --git a/src/Content/ContentSubmitParams/Policy/Sexual.php b/src/Content/ContentSubmitParams/Policy/Sexual.php index 73d7786..6f0206d 100644 --- a/src/Content/ContentSubmitParams/Policy/Sexual.php +++ b/src/Content/ContentSubmitParams/Policy/Sexual.php @@ -9,7 +9,7 @@ use ModerationAPI\Core\Contracts\BaseModel; /** - * @phpstan-type SexualShape = array{id?: 'sexual', flag: bool} + * @phpstan-type SexualShape = array{id: 'sexual', flag: bool} */ final class Sexual implements BaseModel { diff --git a/src/Content/ContentSubmitParams/Policy/Spam.php b/src/Content/ContentSubmitParams/Policy/Spam.php index 8981910..52542dc 100644 --- a/src/Content/ContentSubmitParams/Policy/Spam.php +++ b/src/Content/ContentSubmitParams/Policy/Spam.php @@ -9,7 +9,7 @@ use ModerationAPI\Core\Contracts\BaseModel; /** - * @phpstan-type SpamShape = array{id?: 'spam', flag: bool} + * @phpstan-type SpamShape = array{id: 'spam', flag: bool} */ final class Spam implements BaseModel { diff --git a/src/Content/ContentSubmitParams/Policy/Toxicity.php b/src/Content/ContentSubmitParams/Policy/Toxicity.php index 588915b..b3e51e2 100644 --- a/src/Content/ContentSubmitParams/Policy/Toxicity.php +++ b/src/Content/ContentSubmitParams/Policy/Toxicity.php @@ -9,7 +9,7 @@ use ModerationAPI\Core\Contracts\BaseModel; /** - * @phpstan-type ToxicityShape = array{id?: 'toxicity', flag: bool} + * @phpstan-type ToxicityShape = array{id: 'toxicity', flag: bool} */ final class Toxicity implements BaseModel { diff --git a/src/Content/ContentSubmitParams/Policy/ToxicitySevere.php b/src/Content/ContentSubmitParams/Policy/ToxicitySevere.php index e54e9e2..abd4b72 100644 --- a/src/Content/ContentSubmitParams/Policy/ToxicitySevere.php +++ b/src/Content/ContentSubmitParams/Policy/ToxicitySevere.php @@ -9,7 +9,7 @@ use ModerationAPI\Core\Contracts\BaseModel; /** - * @phpstan-type ToxicitySevereShape = array{id?: 'toxicity_severe', flag: bool} + * @phpstan-type ToxicitySevereShape = array{id: 'toxicity_severe', flag: bool} */ final class ToxicitySevere implements BaseModel { diff --git a/src/Content/ContentSubmitParams/Policy/URLMasking.php b/src/Content/ContentSubmitParams/Policy/URLMasking.php index 87d6ca5..c4b928a 100644 --- a/src/Content/ContentSubmitParams/Policy/URLMasking.php +++ b/src/Content/ContentSubmitParams/Policy/URLMasking.php @@ -5,14 +5,15 @@ namespace ModerationAPI\Content\ContentSubmitParams\Policy; use ModerationAPI\Content\ContentSubmitParams\Policy\URLMasking\Entity; -use ModerationAPI\Content\ContentSubmitParams\Policy\URLMasking\Entity\ID; use ModerationAPI\Core\Attributes\Required; use ModerationAPI\Core\Concerns\SdkModel; use ModerationAPI\Core\Contracts\BaseModel; /** + * @phpstan-import-type EntityShape from \ModerationAPI\Content\ContentSubmitParams\Policy\URLMasking\Entity + * * @phpstan-type URLMaskingShape = array{ - * id?: 'url', entities: array + * id: 'url', entities: array * } */ final class URLMasking implements BaseModel @@ -52,13 +53,7 @@ public function __construct() * * You must use named parameters to construct any parameters with a default value. * - * @param array, - * enable: bool, - * flag: bool, - * shouldMask: bool, - * mask?: string|null, - * }> $entities + * @param array $entities */ public static function with(array $entities): self { @@ -70,13 +65,7 @@ public static function with(array $entities): self } /** - * @param array, - * enable: bool, - * flag: bool, - * shouldMask: bool, - * mask?: string|null, - * }> $entities + * @param array $entities */ public function withEntities(array $entities): self { diff --git a/src/Content/ContentSubmitParams/Policy/URLMasking/Entity.php b/src/Content/ContentSubmitParams/Policy/URLMasking/Entity.php index cfe0c83..d35c7eb 100644 --- a/src/Content/ContentSubmitParams/Policy/URLMasking/Entity.php +++ b/src/Content/ContentSubmitParams/Policy/URLMasking/Entity.php @@ -12,7 +12,7 @@ /** * @phpstan-type EntityShape = array{ - * id: value-of, + * id: ID|value-of, * enable: bool, * flag: bool, * shouldMask: bool, diff --git a/src/Content/ContentSubmitParams/Policy/Violence.php b/src/Content/ContentSubmitParams/Policy/Violence.php index a957865..9dd2fa2 100644 --- a/src/Content/ContentSubmitParams/Policy/Violence.php +++ b/src/Content/ContentSubmitParams/Policy/Violence.php @@ -9,7 +9,7 @@ use ModerationAPI\Core\Contracts\BaseModel; /** - * @phpstan-type ViolenceShape = array{id?: 'violence', flag: bool} + * @phpstan-type ViolenceShape = array{id: 'violence', flag: bool} */ final class Violence implements BaseModel { diff --git a/src/Content/ContentSubmitResponse.php b/src/Content/ContentSubmitResponse.php index 7996575..6b0b3c8 100644 --- a/src/Content/ContentSubmitResponse.php +++ b/src/Content/ContentSubmitResponse.php @@ -5,44 +5,41 @@ namespace ModerationAPI\Content; use ModerationAPI\Content\ContentSubmitResponse\Author; -use ModerationAPI\Content\ContentSubmitResponse\Author\Block; -use ModerationAPI\Content\ContentSubmitResponse\Author\Status; -use ModerationAPI\Content\ContentSubmitResponse\Author\TrustLevel; use ModerationAPI\Content\ContentSubmitResponse\Content; -use ModerationAPI\Content\ContentSubmitResponse\Content\Modified\ModifiedNestedObjectContent\Audio; -use ModerationAPI\Content\ContentSubmitResponse\Content\Modified\ModifiedNestedObjectContent\Image; -use ModerationAPI\Content\ContentSubmitResponse\Content\Modified\ModifiedNestedObjectContent\Text; -use ModerationAPI\Content\ContentSubmitResponse\Content\Modified\ModifiedNestedObjectContent\Video; use ModerationAPI\Content\ContentSubmitResponse\Error; use ModerationAPI\Content\ContentSubmitResponse\Evaluation; use ModerationAPI\Content\ContentSubmitResponse\Insight; use ModerationAPI\Content\ContentSubmitResponse\Insight\LanguageInsight; use ModerationAPI\Content\ContentSubmitResponse\Insight\SentimentInsight; -use ModerationAPI\Content\ContentSubmitResponse\Insight\SentimentInsight\Value; use ModerationAPI\Content\ContentSubmitResponse\Meta; use ModerationAPI\Content\ContentSubmitResponse\Policy; use ModerationAPI\Content\ContentSubmitResponse\Policy\ClassifierOutput; -use ModerationAPI\Content\ContentSubmitResponse\Policy\ClassifierOutput\Label; use ModerationAPI\Content\ContentSubmitResponse\Policy\EntityMatcherOutput; -use ModerationAPI\Content\ContentSubmitResponse\Policy\EntityMatcherOutput\Match_; use ModerationAPI\Content\ContentSubmitResponse\Recommendation; -use ModerationAPI\Content\ContentSubmitResponse\Recommendation\Action; -use ModerationAPI\Content\ContentSubmitResponse\Recommendation\ReasonCode; use ModerationAPI\Core\Attributes\Optional; use ModerationAPI\Core\Attributes\Required; use ModerationAPI\Core\Concerns\SdkModel; use ModerationAPI\Core\Contracts\BaseModel; /** + * @phpstan-import-type AuthorShape from \ModerationAPI\Content\ContentSubmitResponse\Author + * @phpstan-import-type ContentShape from \ModerationAPI\Content\ContentSubmitResponse\Content + * @phpstan-import-type EvaluationShape from \ModerationAPI\Content\ContentSubmitResponse\Evaluation + * @phpstan-import-type InsightShape from \ModerationAPI\Content\ContentSubmitResponse\Insight + * @phpstan-import-type MetaShape from \ModerationAPI\Content\ContentSubmitResponse\Meta + * @phpstan-import-type PolicyShape from \ModerationAPI\Content\ContentSubmitResponse\Policy + * @phpstan-import-type RecommendationShape from \ModerationAPI\Content\ContentSubmitResponse\Recommendation + * @phpstan-import-type ErrorShape from \ModerationAPI\Content\ContentSubmitResponse\Error + * * @phpstan-type ContentSubmitResponseShape = array{ - * author: Author|null, - * content: Content, - * evaluation: Evaluation, - * insights: list, - * meta: Meta, - * policies: list, - * recommendation: Recommendation, - * errors?: list|null, + * author: null|Author|AuthorShape, + * content: Content|ContentShape, + * evaluation: Evaluation|EvaluationShape, + * insights: list, + * meta: Meta|MetaShape, + * policies: list, + * recommendation: Recommendation|RecommendationShape, + * errors?: list|null, * } */ final class ContentSubmitResponse implements BaseModel @@ -143,58 +140,14 @@ public function __construct() * * You must use named parameters to construct any parameters with a default value. * - * @param Author|array{ - * id: string, - * block: Block|null, - * status: value-of, - * trustLevel: TrustLevel, - * externalID?: string|null, - * }|null $author - * @param Content|array{ - * id: string, - * masked: bool, - * modified: string|array|array|null, - * } $content - * @param Evaluation|array{ - * flagProbability: float, - * flagged: bool, - * severityScore: float, - * unicodeSpoofed?: bool|null, - * } $evaluation - * @param list|null, - * }|LanguageInsight|array{ - * id?: 'language', probability: float, type?: 'insight', value: string|null - * }> $insights - * @param Meta|array{ - * channelKey: string, - * status: value-of, - * timestamp: float, - * usage: float, - * processingTime?: string|null, - * } $meta - * @param list|null, - * labels?: list