Skip to content

Commit 840fb5c

Browse files
Merge pull request #28 from WordPress/feature/data-transfer-objects
Adds Implementor Data Transfer Objects
2 parents 61362ef + 82e6c8f commit 840fb5c

Some content is hidden

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

43 files changed

+6685
-24
lines changed

phpstan.neon.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ parameters:
22
level: max
33
paths:
44
- src
5+
treatPhpDocTypesAsCertain: false

src/Common/AbstractEnum.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
* $enum->is(PersonEnum::firstName()); // Returns true
3131
* PersonEnum::cases(); // Returns array of all enum instances
3232
*
33+
* @property-read string $value The value of the enum instance.
34+
* @property-read string $name The name of the enum constant.
35+
*
3336
* @since n.e.x.t
3437
*/
3538
abstract class AbstractEnum
@@ -195,11 +198,11 @@ final public function is(self $other): bool
195198
*
196199
* @since n.e.x.t
197200
*
198-
* @return array<string, string> Map of constant names to values.
201+
* @return string[] List of all enum values.
199202
*/
200203
final public static function getValues(): array
201204
{
202-
return self::getConstants();
205+
return array_values(self::getConstants());
203206
}
204207

205208
/**
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace WordPress\AiClient\Common\Contracts;
6+
7+
/**
8+
* Interface for objects that can provide their JSON schema representation.
9+
*
10+
* This interface is implemented by DTOs to provide a consistent way to retrieve
11+
* their JSON schema for validation and serialization purposes.
12+
*
13+
* @since n.e.x.t
14+
*/
15+
interface WithJsonSchemaInterface
16+
{
17+
/**
18+
* Gets the JSON schema representation of the object.
19+
*
20+
* @since n.e.x.t
21+
*
22+
* @return array<string, mixed> The JSON schema as an associative array.
23+
*/
24+
public static function getJsonSchema(): array;
25+
}

0 commit comments

Comments
 (0)