From f1d1fb322864ffab081dd3f5c39a1aec38e4255a Mon Sep 17 00:00:00 2001 From: Tycho Engberink Date: Thu, 22 Jan 2026 13:29:34 +0100 Subject: [PATCH 1/3] feat: add Comment resource with get, list, and create methods --- src/Comment.php | 113 ++++++++++++++++++ src/Langfuse.php | 10 +- src/Responses/CommentListResponse.php | 44 +++++++ src/Responses/CommentResponse.php | 45 +++++++ .../Responses/GetCommentListResponse.php | 55 +++++++++ src/Testing/Responses/GetCommentResponse.php | 37 ++++++ src/Testing/Responses/PostCommentResponse.php | 37 ++++++ tests/Feature/CommentTest.php | 106 ++++++++++++++++ 8 files changed, 445 insertions(+), 2 deletions(-) create mode 100644 src/Comment.php create mode 100644 src/Responses/CommentListResponse.php create mode 100644 src/Responses/CommentResponse.php create mode 100644 src/Testing/Responses/GetCommentListResponse.php create mode 100644 src/Testing/Responses/GetCommentResponse.php create mode 100644 src/Testing/Responses/PostCommentResponse.php create mode 100644 tests/Feature/CommentTest.php diff --git a/src/Comment.php b/src/Comment.php new file mode 100644 index 0000000..f1b65e1 --- /dev/null +++ b/src/Comment.php @@ -0,0 +1,113 @@ +transporter->get( + uri: sprintf('/api/public/comments/%s', urlencode($commentId)), + ); + + /** @var array{ + * id: string, + * content: string, + * objectType: string, + * objectId: string, + * authorUserId: string|null, + * createdAt: string, + * updatedAt: string, + * projectId: string + * } $data + */ + $data = json_decode($response->getBody()->getContents(), true, flags: JSON_THROW_ON_ERROR); + + return CommentResponse::fromArray($data); + } + + /** + * @throws JsonException + */ + public function list( + ?int $page = null, + ?int $limit = null, + ?string $objectType = null, + ?string $objectId = null, + ?string $authorUserId = null, + ): CommentListResponse { + $response = $this->transporter->get( + uri: '/api/public/comments', + options: ['query' => array_filter([ + 'page' => $page, + 'limit' => $limit, + 'objectType' => $objectType, + 'objectId' => $objectId, + 'authorUserId' => $authorUserId, + ])] + ); + + /** @var array{ + * data: array, + * meta: array{page: int, limit: int, totalPages: int, totalItems: int} + * } $data + */ + $data = json_decode($response->getBody()->getContents(), true, flags: JSON_THROW_ON_ERROR); + + return CommentListResponse::fromArray($data); + } + + /** + * @throws JsonException + */ + public function create( + string $content, + string $objectType, + string $objectId, + ): CommentResponse { + $response = $this->transporter->postJson( + uri: '/api/public/comments', + data: [ + 'content' => $content, + 'objectType' => $objectType, + 'objectId' => $objectId, + ], + ); + + /** @var array{ + * id: string, + * content: string, + * objectType: string, + * objectId: string, + * authorUserId: string|null, + * createdAt: string, + * updatedAt: string, + * projectId: string + * } $data + */ + $data = json_decode($response->getBody()->getContents(), true, flags: JSON_THROW_ON_ERROR); + + return CommentResponse::fromArray($data); + } +} diff --git a/src/Langfuse.php b/src/Langfuse.php index ebe96f9..60ac9d5 100644 --- a/src/Langfuse.php +++ b/src/Langfuse.php @@ -12,8 +12,7 @@ public function __construct( private readonly TransporterInterface $transporter, private readonly string $environment = 'default', private readonly string $label = 'latest', - ) { - } + ) {} public function prompt(): Prompt { @@ -37,4 +36,11 @@ public function score(): Score transporter: $this->transporter, ); } + + public function comment(): Comment + { + return new Comment( + transporter: $this->transporter, + ); + } } diff --git a/src/Responses/CommentListResponse.php b/src/Responses/CommentListResponse.php new file mode 100644 index 0000000..3eda0ee --- /dev/null +++ b/src/Responses/CommentListResponse.php @@ -0,0 +1,44 @@ + $data + */ + public function __construct( + public array $data, + public MetaData $meta, + ) {} + + /** + * @param array{ + * data: array, + * meta: array{page: int, limit: int, totalPages: int, totalItems: int} + * } $data + */ + public static function fromArray(array $data): self + { + return new self( + data: array_map( + fn (array $item): CommentResponse => CommentResponse::fromArray($item), + $data['data'] + ), + meta: MetaData::fromArray($data['meta']), + ); + } +} diff --git a/src/Responses/CommentResponse.php b/src/Responses/CommentResponse.php new file mode 100644 index 0000000..f4371d1 --- /dev/null +++ b/src/Responses/CommentResponse.php @@ -0,0 +1,45 @@ +|string> $headers + */ + public function __construct(int $status = 200, array $headers = [], string $version = '1.1', ?string $reason = null) + { + parent::__construct($status, $headers, (string) json_encode($this->payload()), $version, $reason); + } + + /** + * @return array + */ + public function payload(): array + { + return [ + 'data' => [ + [ + 'id' => 'comment-abc123', + 'content' => 'First comment', + 'objectType' => 'trace', + 'objectId' => 'trace-123', + 'authorUserId' => 'user-456', + 'createdAt' => '2025-01-22T10:00:00.000Z', + 'updatedAt' => '2025-01-22T10:00:00.000Z', + 'projectId' => 'proj-abc123', + ], + [ + 'id' => 'comment-def456', + 'content' => 'Second comment', + 'objectType' => 'observation', + 'objectId' => 'obs-789', + 'authorUserId' => null, + 'createdAt' => '2025-01-22T09:00:00.000Z', + 'updatedAt' => '2025-01-22T09:00:00.000Z', + 'projectId' => 'proj-abc123', + ], + ], + 'meta' => [ + 'page' => 1, + 'limit' => 10, + 'totalPages' => 1, + 'totalItems' => 2, + ], + ]; + } +} diff --git a/src/Testing/Responses/GetCommentResponse.php b/src/Testing/Responses/GetCommentResponse.php new file mode 100644 index 0000000..fa3146c --- /dev/null +++ b/src/Testing/Responses/GetCommentResponse.php @@ -0,0 +1,37 @@ +|string> $headers + * @param array $data + */ + public function __construct(int $status = 200, array $headers = [], string $version = '1.1', ?string $reason = null, array $data = []) + { + parent::__construct($status, $headers, (string) json_encode($this->payload($data)), $version, $reason); + } + + /** + * @param array $data + * @return array + */ + public function payload(array $data = []): array + { + return array_merge([ + 'id' => 'comment-abc123', + 'content' => 'This is a test comment', + 'objectType' => 'trace', + 'objectId' => 'trace-123', + 'authorUserId' => 'user-456', + 'createdAt' => '2025-01-22T10:00:00.000Z', + 'updatedAt' => '2025-01-22T10:00:00.000Z', + 'projectId' => 'proj-abc123', + ], $data); + } +} diff --git a/src/Testing/Responses/PostCommentResponse.php b/src/Testing/Responses/PostCommentResponse.php new file mode 100644 index 0000000..b10500c --- /dev/null +++ b/src/Testing/Responses/PostCommentResponse.php @@ -0,0 +1,37 @@ +|string> $headers + * @param array $data + */ + public function __construct(int $status = 200, array $headers = [], string $version = '1.1', ?string $reason = null, array $data = []) + { + parent::__construct($status, $headers, (string) json_encode($this->payload($data)), $version, $reason); + } + + /** + * @param array $data + * @return array + */ + public function payload(array $data = []): array + { + return array_merge([ + 'id' => 'comment-new123', + 'content' => 'New comment content', + 'objectType' => 'trace', + 'objectId' => 'trace-123', + 'authorUserId' => 'user-456', + 'createdAt' => '2025-01-22T11:00:00.000Z', + 'updatedAt' => '2025-01-22T11:00:00.000Z', + 'projectId' => 'proj-abc123', + ], $data); + } +} diff --git a/tests/Feature/CommentTest.php b/tests/Feature/CommentTest.php new file mode 100644 index 0000000..46bdaa8 --- /dev/null +++ b/tests/Feature/CommentTest.php @@ -0,0 +1,106 @@ + $handlerStack]); + + $comment = (new Langfuse(new HttpTransporter($client))) + ->comment() + ->get('comment-abc123'); + + expect($comment)->toBeInstanceOf(CommentResponse::class) + ->and($comment->id)->toBe('comment-abc123') + ->and($comment->content)->toBe('This is a test comment') + ->and($comment->objectType)->toBe('trace') + ->and($comment->objectId)->toBe('trace-123') + ->and($comment->authorUserId)->toBe('user-456') + ->and($comment->projectId)->toBe('proj-abc123'); +}); + +it('can list comments', function (): void { + $mock = new MockHandler([ + new GetCommentListResponse, + ]); + + $handlerStack = HandlerStack::create($mock); + $client = new Client(['handler' => $handlerStack]); + + $comments = (new Langfuse(new HttpTransporter($client))) + ->comment() + ->list(); + + expect($comments)->toBeInstanceOf(CommentListResponse::class) + ->and($comments->data)->toBeArray() + ->and($comments->data)->toHaveCount(2) + ->and($comments->data[0])->toBeInstanceOf(CommentResponse::class) + ->and($comments->data[0]->content)->toBe('First comment') + ->and($comments->data[0]->objectType)->toBe('trace') + ->and($comments->data[1]->content)->toBe('Second comment') + ->and($comments->data[1]->objectType)->toBe('observation') + ->and($comments->data[1]->authorUserId)->toBeNull() + ->and($comments->meta)->toBeInstanceOf(MetaData::class) + ->and($comments->meta->totalItems)->toBe(2); +}); + +it('can create a comment', function (): void { + $mock = new MockHandler([ + new PostCommentResponse, + ]); + + $handlerStack = HandlerStack::create($mock); + $client = new Client(['handler' => $handlerStack]); + + $comment = (new Langfuse(new HttpTransporter($client))) + ->comment() + ->create( + content: 'New comment content', + objectType: 'trace', + objectId: 'trace-123', + ); + + expect($comment)->toBeInstanceOf(CommentResponse::class) + ->and($comment->id)->toBe('comment-new123') + ->and($comment->content)->toBe('New comment content') + ->and($comment->objectType)->toBe('trace') + ->and($comment->objectId)->toBe('trace-123'); +}); + +it('can list comments with filters', function (): void { + $mock = new MockHandler([ + new GetCommentListResponse, + ]); + + $handlerStack = HandlerStack::create($mock); + $client = new Client(['handler' => $handlerStack]); + + $comments = (new Langfuse(new HttpTransporter($client))) + ->comment() + ->list( + page: 1, + limit: 10, + objectType: 'trace', + objectId: 'trace-123', + authorUserId: 'user-456', + ); + + expect($comments)->toBeInstanceOf(CommentListResponse::class) + ->and($comments->data)->toHaveCount(2); +}); From 15c73456eef4966e50ff434352ed9e7109d692ae Mon Sep 17 00:00:00 2001 From: Tycho Engberink Date: Thu, 22 Jan 2026 13:29:40 +0100 Subject: [PATCH 2/3] style: apply Pint formatting fixes --- rector.php | 4 +-- src/Concerns/IsCompilable.php | 10 +++---- src/Contracts/TransporterInterface.php | 10 +++---- src/Exceptions/ForbiddenException.php | 4 +-- .../InternalServerErrorException.php | 4 +-- src/Exceptions/MethodNotAllowedException.php | 4 +-- src/Exceptions/NotFoundException.php | 4 +-- src/Exceptions/UnauthorizedException.php | 4 +-- src/Ingestion.php | 29 +++++++++---------- src/Responses/BasePromptResponse.php | 13 ++++----- src/Responses/ChatPromptResponse.php | 10 +++---- src/Responses/FallbackPrompt.php | 4 +-- src/Responses/PromptListResponse.php | 5 ++-- src/Responses/TextPromptResponse.php | 8 ++--- .../Responses/GetChatPromptResponse.php | 6 ++-- src/Testing/Responses/GetPromptResponse.php | 6 ++-- .../Responses/PostChatPromptResponse.php | 4 +-- src/Testing/Responses/PostPromptResponse.php | 4 +-- src/Transporters/HttpTransporter.php | 7 ++--- src/ValueObjects/MetaData.php | 5 ++-- src/ValueObjects/PaginationData.php | 5 ++-- src/ValueObjects/PromptListItem.php | 13 ++++----- tests/Feature/PromptTest.php | 28 +++++++++--------- 23 files changed, 87 insertions(+), 104 deletions(-) diff --git a/rector.php b/rector.php index a3b3e14..0c54648 100644 --- a/rector.php +++ b/rector.php @@ -7,8 +7,8 @@ return RectorConfig::configure() ->withPaths([ - __DIR__ . '/src', - __DIR__ . '/tests', + __DIR__.'/src', + __DIR__.'/tests', ]) ->withSkip([ AddOverrideAttributeToOverriddenMethodsRector::class, diff --git a/src/Concerns/IsCompilable.php b/src/Concerns/IsCompilable.php index d32399a..f736994 100644 --- a/src/Concerns/IsCompilable.php +++ b/src/Concerns/IsCompilable.php @@ -7,7 +7,7 @@ trait IsCompilable { /** - * @param array $param + * @param array $param * @return array|string */ public function compile(array $param = []): array|string @@ -16,8 +16,8 @@ public function compile(array $param = []): array|string } /** - * @param array $data - * @param array $prompt + * @param array $data + * @param array $prompt * @return array */ private function compileArray(array $prompt, array $data = []): array @@ -30,7 +30,7 @@ private function compileArray(array $prompt, array $data = []): array } /** - * @param array $data + * @param array $data */ private function compileString(string $prompt, array $data = []): string { @@ -38,7 +38,7 @@ private function compileString(string $prompt, array $data = []): string $values = array_values($data); return str_replace( - array_map(fn ($i): string => '{{' . $i . '}}', array_keys($data)), + array_map(fn ($i): string => '{{'.$i.'}}', array_keys($data)), $values, $prompt ); diff --git a/src/Contracts/TransporterInterface.php b/src/Contracts/TransporterInterface.php index 8234ade..274ee6d 100644 --- a/src/Contracts/TransporterInterface.php +++ b/src/Contracts/TransporterInterface.php @@ -9,23 +9,23 @@ interface TransporterInterface { /** - * @param array $options + * @param array $options */ public function request(string $method, string $uri, array $options = []): ResponseInterface; /** - * @param array $options + * @param array $options */ public function get(string $uri, array $options = []): ResponseInterface; /** - * @param array $options + * @param array $options */ public function post(string $uri, array $options = []): ResponseInterface; /** - * @param array $data - * @param array $options + * @param array $data + * @param array $options */ public function postJson(string $uri, array $data = [], array $options = []): ResponseInterface; diff --git a/src/Exceptions/ForbiddenException.php b/src/Exceptions/ForbiddenException.php index 9bab0b8..1816c7e 100644 --- a/src/Exceptions/ForbiddenException.php +++ b/src/Exceptions/ForbiddenException.php @@ -4,6 +4,4 @@ namespace DIJ\Langfuse\PHP\Exceptions; -class ForbiddenException extends LangfuseException -{ -} +class ForbiddenException extends LangfuseException {} diff --git a/src/Exceptions/InternalServerErrorException.php b/src/Exceptions/InternalServerErrorException.php index f69f0e3..5477364 100644 --- a/src/Exceptions/InternalServerErrorException.php +++ b/src/Exceptions/InternalServerErrorException.php @@ -4,6 +4,4 @@ namespace DIJ\Langfuse\PHP\Exceptions; -class InternalServerErrorException extends LangfuseException -{ -} +class InternalServerErrorException extends LangfuseException {} diff --git a/src/Exceptions/MethodNotAllowedException.php b/src/Exceptions/MethodNotAllowedException.php index 3af4082..429eeb3 100644 --- a/src/Exceptions/MethodNotAllowedException.php +++ b/src/Exceptions/MethodNotAllowedException.php @@ -4,6 +4,4 @@ namespace DIJ\Langfuse\PHP\Exceptions; -class MethodNotAllowedException extends LangfuseException -{ -} +class MethodNotAllowedException extends LangfuseException {} diff --git a/src/Exceptions/NotFoundException.php b/src/Exceptions/NotFoundException.php index be99639..d24b476 100644 --- a/src/Exceptions/NotFoundException.php +++ b/src/Exceptions/NotFoundException.php @@ -4,6 +4,4 @@ namespace DIJ\Langfuse\PHP\Exceptions; -class NotFoundException extends LangfuseException -{ -} +class NotFoundException extends LangfuseException {} diff --git a/src/Exceptions/UnauthorizedException.php b/src/Exceptions/UnauthorizedException.php index 8f04d9a..cb9a893 100644 --- a/src/Exceptions/UnauthorizedException.php +++ b/src/Exceptions/UnauthorizedException.php @@ -4,6 +4,4 @@ namespace DIJ\Langfuse\PHP\Exceptions; -class UnauthorizedException extends LangfuseException -{ -} +class UnauthorizedException extends LangfuseException {} diff --git a/src/Ingestion.php b/src/Ingestion.php index d581c87..d041b89 100644 --- a/src/Ingestion.php +++ b/src/Ingestion.php @@ -16,8 +16,7 @@ class Ingestion public function __construct( private readonly TransporterInterface $transporter, private readonly string $environment = 'default', - ) { - } + ) {} public static function uuid(): string { @@ -30,16 +29,16 @@ public static function uuid(): string public static function now(): string { - return gmdate('Y-m-d\TH:i:s.') . sprintf('%03d', (int) (microtime(true) * 1000) % 1000) . 'Z'; + return gmdate('Y-m-d\TH:i:s.').sprintf('%03d', (int) (microtime(true) * 1000) % 1000).'Z'; } /** * Create a trace. * - * @param array|string|null $input - * @param array|string|null $output - * @param array|null $metadata - * @param list|null $tags + * @param array|string|null $input + * @param array|string|null $output + * @param array|null $metadata + * @param list|null $tags */ public function trace( string $name, @@ -77,9 +76,9 @@ public function trace( /** * Create a span. * - * @param array|string|null $input - * @param array|string|null $output - * @param array|null $metadata + * @param array|string|null $input + * @param array|string|null $output + * @param array|null $metadata */ public function span( string $traceId, @@ -119,10 +118,10 @@ public function span( /** * Create a generation. * - * @param array|string $input - * @param array|string $output - * @param array|null $modelParameters - * @param array|null $metadata + * @param array|string $input + * @param array|string $output + * @param array|null $modelParameters + * @param array|null $metadata */ public function generation( string $traceId, @@ -170,7 +169,7 @@ public function generation( /** * Send a single ingestion event to the Langfuse API. * - * @param array $body + * @param array $body */ public function send(string $type, array $body): void { diff --git a/src/Responses/BasePromptResponse.php b/src/Responses/BasePromptResponse.php index 79eff3a..9ddedf4 100644 --- a/src/Responses/BasePromptResponse.php +++ b/src/Responses/BasePromptResponse.php @@ -11,11 +11,11 @@ use IsCompilable; /** - * @param ($type is 'text' ? string : array) $prompt - * @param array $config - * @param array $tags - * @param array $labels - * @param array $resolutionGraph + * @param ($type is 'text' ? string : array) $prompt + * @param array $config + * @param array $tags + * @param array $labels + * @param array $resolutionGraph */ public function __construct( public string|array $prompt, @@ -33,6 +33,5 @@ public function __construct( public ?bool $isActive = null, public ?string $commitMessage = null, public array $resolutionGraph = [], - ) { - } + ) {} } diff --git a/src/Responses/ChatPromptResponse.php b/src/Responses/ChatPromptResponse.php index f4df205..8bfa34d 100644 --- a/src/Responses/ChatPromptResponse.php +++ b/src/Responses/ChatPromptResponse.php @@ -7,11 +7,11 @@ readonly class ChatPromptResponse extends BasePromptResponse { /** - * @param array $prompt - * @param array $config - * @param array $tags - * @param array $labels - * @param array $resolutionGraph + * @param array $prompt + * @param array $config + * @param array $tags + * @param array $labels + * @param array $resolutionGraph */ public function __construct( string $id, diff --git a/src/Responses/FallbackPrompt.php b/src/Responses/FallbackPrompt.php index acb3153..2083dbe 100644 --- a/src/Responses/FallbackPrompt.php +++ b/src/Responses/FallbackPrompt.php @@ -12,7 +12,7 @@ use IsCompilable; /** - * @param ($type is "text" ? string : array) $prompt + * @param ($type is "text" ? string : array) $prompt */ public function __construct( string|array $prompt, @@ -39,7 +39,7 @@ public static function text( /** * Create a chat fallback prompt * - * @param array $content + * @param array $content */ public static function chat( array $content, diff --git a/src/Responses/PromptListResponse.php b/src/Responses/PromptListResponse.php index afd1b00..0decde6 100644 --- a/src/Responses/PromptListResponse.php +++ b/src/Responses/PromptListResponse.php @@ -11,14 +11,13 @@ readonly class PromptListResponse { /** - * @param array $data + * @param array $data */ public function __construct( public array $data, public MetaData $meta, public PaginationData $pagination, - ) { - } + ) {} /** * @param array{ diff --git a/src/Responses/TextPromptResponse.php b/src/Responses/TextPromptResponse.php index c6d3ccf..f43ab0a 100644 --- a/src/Responses/TextPromptResponse.php +++ b/src/Responses/TextPromptResponse.php @@ -7,10 +7,10 @@ readonly class TextPromptResponse extends BasePromptResponse { /** - * @param array $config - * @param array $tags - * @param array $labels - * @param array $resolutionGraph + * @param array $config + * @param array $tags + * @param array $labels + * @param array $resolutionGraph */ public function __construct( string $id, diff --git a/src/Testing/Responses/GetChatPromptResponse.php b/src/Testing/Responses/GetChatPromptResponse.php index c3a815b..3374142 100644 --- a/src/Testing/Responses/GetChatPromptResponse.php +++ b/src/Testing/Responses/GetChatPromptResponse.php @@ -9,8 +9,8 @@ class GetChatPromptResponse extends Response { /** - * @param array|string> $headers - * @param array $data + * @param array|string> $headers + * @param array $data */ public function __construct(int $status = 200, array $headers = [], string $version = '1.1', ?string $reason = null, array $data = []) { @@ -18,7 +18,7 @@ public function __construct(int $status = 200, array $headers = [], string $vers } /** - * @param array $data + * @param array $data * @return array */ public function payload(array $data = []): array diff --git a/src/Testing/Responses/GetPromptResponse.php b/src/Testing/Responses/GetPromptResponse.php index e668d92..02a1577 100644 --- a/src/Testing/Responses/GetPromptResponse.php +++ b/src/Testing/Responses/GetPromptResponse.php @@ -9,8 +9,8 @@ class GetPromptResponse extends Response { /** - * @param array|string> $headers - * @param array $data + * @param array|string> $headers + * @param array $data */ public function __construct(int $status = 200, array $headers = [], string $version = '1.1', ?string $reason = null, array $data = []) { @@ -18,7 +18,7 @@ public function __construct(int $status = 200, array $headers = [], string $vers } /** - * @param array $data + * @param array $data * @return array */ public function payload(array $data = []): array diff --git a/src/Testing/Responses/PostChatPromptResponse.php b/src/Testing/Responses/PostChatPromptResponse.php index 071a9eb..7328581 100644 --- a/src/Testing/Responses/PostChatPromptResponse.php +++ b/src/Testing/Responses/PostChatPromptResponse.php @@ -9,7 +9,7 @@ class PostChatPromptResponse extends Response { /** - * @param array $data + * @param array $data */ public function __construct(int $status = 201, array $headers = [], string $version = '1.1', ?string $reason = null, array $data = []) { @@ -17,7 +17,7 @@ public function __construct(int $status = 201, array $headers = [], string $vers } /** - * @param array $data + * @param array $data * @return array */ public function payload(array $data = []): array diff --git a/src/Testing/Responses/PostPromptResponse.php b/src/Testing/Responses/PostPromptResponse.php index 5ed663c..3352b3f 100644 --- a/src/Testing/Responses/PostPromptResponse.php +++ b/src/Testing/Responses/PostPromptResponse.php @@ -9,7 +9,7 @@ class PostPromptResponse extends Response { /** - * @param array $data + * @param array $data */ public function __construct(int $status = 201, array $headers = [], string $version = '1.1', ?string $reason = null, array $data = []) { @@ -17,7 +17,7 @@ public function __construct(int $status = 201, array $headers = [], string $vers } /** - * @param array $data + * @param array $data * @return array */ public function payload(array $data = []): array diff --git a/src/Transporters/HttpTransporter.php b/src/Transporters/HttpTransporter.php index 319cf49..e3da1d6 100644 --- a/src/Transporters/HttpTransporter.php +++ b/src/Transporters/HttpTransporter.php @@ -21,8 +21,7 @@ class HttpTransporter implements TransporterInterface { public function __construct( public readonly ClientInterface $client - ) { - } + ) {} /** * @throws BadRequestException @@ -45,7 +44,7 @@ public function request(string $method, string $uri, array $options = []): Respo } /** - * @param array $options + * @param array $options * * @throws BadRequestException * @throws ForbiddenException @@ -61,7 +60,7 @@ public function get(string $uri, array $options = []): ResponseInterface } /** - * @param array $options + * @param array $options * * @throws BadRequestException * @throws ForbiddenException diff --git a/src/ValueObjects/MetaData.php b/src/ValueObjects/MetaData.php index b46ff25..5e83f3b 100644 --- a/src/ValueObjects/MetaData.php +++ b/src/ValueObjects/MetaData.php @@ -11,11 +11,10 @@ public function __construct( public int $limit, public int $totalPages, public int $totalItems, - ) { - } + ) {} /** - * @param array{page: int, limit: int, totalPages: int, totalItems: int} $data + * @param array{page: int, limit: int, totalPages: int, totalItems: int} $data */ public static function fromArray(array $data): self { diff --git a/src/ValueObjects/PaginationData.php b/src/ValueObjects/PaginationData.php index ab3fabc..16beca7 100644 --- a/src/ValueObjects/PaginationData.php +++ b/src/ValueObjects/PaginationData.php @@ -11,11 +11,10 @@ public function __construct( public int $limit, public int $totalPages, public int $totalItems, - ) { - } + ) {} /** - * @param array{page: int, limit: int, totalPages: int, totalItems: int} $data + * @param array{page: int, limit: int, totalPages: int, totalItems: int} $data */ public static function fromArray(array $data): self { diff --git a/src/ValueObjects/PromptListItem.php b/src/ValueObjects/PromptListItem.php index 34ee8a8..e79e45f 100644 --- a/src/ValueObjects/PromptListItem.php +++ b/src/ValueObjects/PromptListItem.php @@ -7,10 +7,10 @@ readonly class PromptListItem { /** - * @param array $tags - * @param array $versions - * @param array $labels - * @param array $lastConfig + * @param array $tags + * @param array $versions + * @param array $labels + * @param array $lastConfig */ public function __construct( public string $name, @@ -19,11 +19,10 @@ public function __construct( public array $versions, public array $labels, public array $lastConfig, - ) { - } + ) {} /** - * @param array{name: string, tags: array, lastUpdatedAt: string, versions: array, labels: array, lastConfig: array} $data + * @param array{name: string, tags: array, lastUpdatedAt: string, versions: array, labels: array, lastConfig: array} $data */ public static function fromArray(array $data): self { diff --git a/tests/Feature/PromptTest.php b/tests/Feature/PromptTest.php index a7df9fc..0c44432 100644 --- a/tests/Feature/PromptTest.php +++ b/tests/Feature/PromptTest.php @@ -25,7 +25,7 @@ it('can get a text prompt', function (): void { $mock = new MockHandler([ - new GetPromptResponse(), + new GetPromptResponse, ]); $handlerStack = HandlerStack::create($mock); @@ -45,7 +45,7 @@ it('returns an error when chat prompt is provided when using text type', function (): void { $mock = new MockHandler([ - new GetChatPromptResponse(), + new GetChatPromptResponse, ]); $handlerStack = HandlerStack::create($mock); @@ -60,7 +60,7 @@ it('can list prompts', function (): void { $mock = new MockHandler([ - new GetPromptListResponse(), + new GetPromptListResponse, ]); $handlerStack = HandlerStack::create($mock); @@ -76,7 +76,7 @@ it('returns null when prompt not found and no fallback is provided', function (): void { $mock = new MockHandler([ - new NoPromptFoundResponse(), + new NoPromptFoundResponse, ]); $handlerStack = HandlerStack::create($mock); @@ -88,7 +88,7 @@ it('can get a chat prompt', function (): void { $mock = new MockHandler([ - new GetChatPromptResponse(), + new GetChatPromptResponse, ]); $handlerStack = HandlerStack::create($mock); @@ -108,7 +108,7 @@ it('can compile a text prompt', function (): void { $mock = new MockHandler([ - new GetPromptResponse(), + new GetPromptResponse, ]); $handlerStack = HandlerStack::create($mock); @@ -129,7 +129,7 @@ it('returns an error when text prompt is provided when using text chat', function (): void { $mock = new MockHandler([ - new GetPromptResponse(), + new GetPromptResponse, ]); $handlerStack = HandlerStack::create($mock); @@ -144,7 +144,7 @@ it('can compile a chat prompt', function (): void { $mock = new MockHandler([ - new GetChatPromptResponse(), + new GetChatPromptResponse, ]); $handlerStack = HandlerStack::create($mock); @@ -168,7 +168,7 @@ it('can create a text prompt', function (): void { $mock = new MockHandler([ - new PostPromptResponse(), + new PostPromptResponse, ]); $handlerStack = HandlerStack::create($mock); @@ -188,7 +188,7 @@ it('can create a chat prompt', function (): void { $mock = new MockHandler([ - new PostChatPromptResponse(), + new PostChatPromptResponse, ]); $handlerStack = HandlerStack::create($mock); @@ -211,7 +211,7 @@ it('uses fallback text prompt when prompt not found', function (): void { $mock = new MockHandler([ - new NoPromptFoundResponse(), + new NoPromptFoundResponse, ]); $handlerStack = HandlerStack::create($mock); @@ -232,7 +232,7 @@ it('uses fallback chat prompt when prompt not found', function (): void { $mock = new MockHandler([ - new NoPromptFoundResponse(), + new NoPromptFoundResponse, ]); $handlerStack = HandlerStack::create($mock); @@ -277,7 +277,7 @@ it('can compile fallback text prompt', function (): void { $mock = new MockHandler([ - new NoPromptFoundResponse(), + new NoPromptFoundResponse, ]); $handlerStack = HandlerStack::create($mock); @@ -298,7 +298,7 @@ it('can compile fallback chat prompt', function (): void { $mock = new MockHandler([ - new NoPromptFoundResponse(), + new NoPromptFoundResponse, ]); $handlerStack = HandlerStack::create($mock); From 68678c15ee2e33e4c0fa0d7b1405515bb35920ba Mon Sep 17 00:00:00 2001 From: Tycho Engberink Date: Fri, 20 Feb 2026 13:37:03 +0100 Subject: [PATCH 3/3] chore: apply rector refactoring and remove test:refactor dry-run --- composer.json | 2 +- rector.php | 4 +-- src/Comment.php | 4 ++- src/Concerns/IsCompilable.php | 10 +++---- src/Contracts/TransporterInterface.php | 10 +++---- src/Exceptions/ForbiddenException.php | 4 ++- .../InternalServerErrorException.php | 4 ++- src/Exceptions/MethodNotAllowedException.php | 4 ++- src/Exceptions/NotFoundException.php | 4 ++- src/Exceptions/UnauthorizedException.php | 4 ++- src/Ingestion.php | 29 ++++++++++--------- src/Langfuse.php | 3 +- src/Prompt.php | 15 +++++----- src/Responses/BasePromptResponse.php | 13 +++++---- src/Responses/ChatPromptResponse.php | 10 +++---- src/Responses/CommentListResponse.php | 7 +++-- src/Responses/CommentResponse.php | 3 +- src/Responses/FallbackPrompt.php | 15 +--------- src/Responses/PromptListResponse.php | 7 +++-- src/Responses/ScoreListResponse.php | 2 +- src/Responses/TextPromptResponse.php | 8 ++--- .../Responses/GetChatPromptResponse.php | 6 ++-- .../Responses/GetCommentListResponse.php | 2 +- src/Testing/Responses/GetCommentResponse.php | 6 ++-- src/Testing/Responses/GetPromptResponse.php | 6 ++-- .../Responses/PostChatPromptResponse.php | 4 +-- src/Testing/Responses/PostCommentResponse.php | 6 ++-- src/Testing/Responses/PostPromptResponse.php | 4 +-- src/Transporters/HttpTransporter.php | 7 +++-- src/ValueObjects/MetaData.php | 5 ++-- src/ValueObjects/PaginationData.php | 5 ++-- src/ValueObjects/PromptListItem.php | 13 +++++---- tests/Feature/CommentTest.php | 8 ++--- tests/Feature/IngestionTest.php | 8 ++--- tests/Feature/PromptTest.php | 28 +++++++++--------- tests/Feature/ScoreTest.php | 10 +++---- 36 files changed, 145 insertions(+), 135 deletions(-) diff --git a/composer.json b/composer.json index 9651b02..98892f9 100644 --- a/composer.json +++ b/composer.json @@ -54,7 +54,7 @@ "test:lint": "@php vendor/bin/pint --config https://raw.githubusercontent.com/DIJ-digital/pint-config/main/pint.json", "test:unit": "pest", "test:types": "phpstan", - "test:refactor": "rector --dry-run", + "test:refactor": "rector", "test": [ "@test:lint", "@test:type-coverage", diff --git a/rector.php b/rector.php index 0c54648..a3b3e14 100644 --- a/rector.php +++ b/rector.php @@ -7,8 +7,8 @@ return RectorConfig::configure() ->withPaths([ - __DIR__.'/src', - __DIR__.'/tests', + __DIR__ . '/src', + __DIR__ . '/tests', ]) ->withSkip([ AddOverrideAttributeToOverriddenMethodsRector::class, diff --git a/src/Comment.php b/src/Comment.php index f1b65e1..ecc89b1 100644 --- a/src/Comment.php +++ b/src/Comment.php @@ -11,7 +11,9 @@ class Comment { - public function __construct(private readonly TransporterInterface $transporter) {} + public function __construct(private readonly TransporterInterface $transporter) + { + } /** * @throws JsonException diff --git a/src/Concerns/IsCompilable.php b/src/Concerns/IsCompilable.php index f736994..f6b988c 100644 --- a/src/Concerns/IsCompilable.php +++ b/src/Concerns/IsCompilable.php @@ -7,7 +7,7 @@ trait IsCompilable { /** - * @param array $param + * @param array $param * @return array|string */ public function compile(array $param = []): array|string @@ -16,8 +16,8 @@ public function compile(array $param = []): array|string } /** - * @param array $data - * @param array $prompt + * @param array $data + * @param array $prompt * @return array */ private function compileArray(array $prompt, array $data = []): array @@ -30,7 +30,7 @@ private function compileArray(array $prompt, array $data = []): array } /** - * @param array $data + * @param array $data */ private function compileString(string $prompt, array $data = []): string { @@ -38,7 +38,7 @@ private function compileString(string $prompt, array $data = []): string $values = array_values($data); return str_replace( - array_map(fn ($i): string => '{{'.$i.'}}', array_keys($data)), + array_map(fn (string $i): string => '{{' . $i . '}}', array_keys($data)), $values, $prompt ); diff --git a/src/Contracts/TransporterInterface.php b/src/Contracts/TransporterInterface.php index 274ee6d..8234ade 100644 --- a/src/Contracts/TransporterInterface.php +++ b/src/Contracts/TransporterInterface.php @@ -9,23 +9,23 @@ interface TransporterInterface { /** - * @param array $options + * @param array $options */ public function request(string $method, string $uri, array $options = []): ResponseInterface; /** - * @param array $options + * @param array $options */ public function get(string $uri, array $options = []): ResponseInterface; /** - * @param array $options + * @param array $options */ public function post(string $uri, array $options = []): ResponseInterface; /** - * @param array $data - * @param array $options + * @param array $data + * @param array $options */ public function postJson(string $uri, array $data = [], array $options = []): ResponseInterface; diff --git a/src/Exceptions/ForbiddenException.php b/src/Exceptions/ForbiddenException.php index 1816c7e..9bab0b8 100644 --- a/src/Exceptions/ForbiddenException.php +++ b/src/Exceptions/ForbiddenException.php @@ -4,4 +4,6 @@ namespace DIJ\Langfuse\PHP\Exceptions; -class ForbiddenException extends LangfuseException {} +class ForbiddenException extends LangfuseException +{ +} diff --git a/src/Exceptions/InternalServerErrorException.php b/src/Exceptions/InternalServerErrorException.php index 5477364..f69f0e3 100644 --- a/src/Exceptions/InternalServerErrorException.php +++ b/src/Exceptions/InternalServerErrorException.php @@ -4,4 +4,6 @@ namespace DIJ\Langfuse\PHP\Exceptions; -class InternalServerErrorException extends LangfuseException {} +class InternalServerErrorException extends LangfuseException +{ +} diff --git a/src/Exceptions/MethodNotAllowedException.php b/src/Exceptions/MethodNotAllowedException.php index 429eeb3..3af4082 100644 --- a/src/Exceptions/MethodNotAllowedException.php +++ b/src/Exceptions/MethodNotAllowedException.php @@ -4,4 +4,6 @@ namespace DIJ\Langfuse\PHP\Exceptions; -class MethodNotAllowedException extends LangfuseException {} +class MethodNotAllowedException extends LangfuseException +{ +} diff --git a/src/Exceptions/NotFoundException.php b/src/Exceptions/NotFoundException.php index d24b476..be99639 100644 --- a/src/Exceptions/NotFoundException.php +++ b/src/Exceptions/NotFoundException.php @@ -4,4 +4,6 @@ namespace DIJ\Langfuse\PHP\Exceptions; -class NotFoundException extends LangfuseException {} +class NotFoundException extends LangfuseException +{ +} diff --git a/src/Exceptions/UnauthorizedException.php b/src/Exceptions/UnauthorizedException.php index cb9a893..8f04d9a 100644 --- a/src/Exceptions/UnauthorizedException.php +++ b/src/Exceptions/UnauthorizedException.php @@ -4,4 +4,6 @@ namespace DIJ\Langfuse\PHP\Exceptions; -class UnauthorizedException extends LangfuseException {} +class UnauthorizedException extends LangfuseException +{ +} diff --git a/src/Ingestion.php b/src/Ingestion.php index d041b89..d581c87 100644 --- a/src/Ingestion.php +++ b/src/Ingestion.php @@ -16,7 +16,8 @@ class Ingestion public function __construct( private readonly TransporterInterface $transporter, private readonly string $environment = 'default', - ) {} + ) { + } public static function uuid(): string { @@ -29,16 +30,16 @@ public static function uuid(): string public static function now(): string { - return gmdate('Y-m-d\TH:i:s.').sprintf('%03d', (int) (microtime(true) * 1000) % 1000).'Z'; + return gmdate('Y-m-d\TH:i:s.') . sprintf('%03d', (int) (microtime(true) * 1000) % 1000) . 'Z'; } /** * Create a trace. * - * @param array|string|null $input - * @param array|string|null $output - * @param array|null $metadata - * @param list|null $tags + * @param array|string|null $input + * @param array|string|null $output + * @param array|null $metadata + * @param list|null $tags */ public function trace( string $name, @@ -76,9 +77,9 @@ public function trace( /** * Create a span. * - * @param array|string|null $input - * @param array|string|null $output - * @param array|null $metadata + * @param array|string|null $input + * @param array|string|null $output + * @param array|null $metadata */ public function span( string $traceId, @@ -118,10 +119,10 @@ public function span( /** * Create a generation. * - * @param array|string $input - * @param array|string $output - * @param array|null $modelParameters - * @param array|null $metadata + * @param array|string $input + * @param array|string $output + * @param array|null $modelParameters + * @param array|null $metadata */ public function generation( string $traceId, @@ -169,7 +170,7 @@ public function generation( /** * Send a single ingestion event to the Langfuse API. * - * @param array $body + * @param array $body */ public function send(string $type, array $body): void { diff --git a/src/Langfuse.php b/src/Langfuse.php index 60ac9d5..044404e 100644 --- a/src/Langfuse.php +++ b/src/Langfuse.php @@ -12,7 +12,8 @@ public function __construct( private readonly TransporterInterface $transporter, private readonly string $environment = 'default', private readonly string $label = 'latest', - ) {} + ) { + } public function prompt(): Prompt { diff --git a/src/Prompt.php b/src/Prompt.php index 42c6e4b..3edee52 100644 --- a/src/Prompt.php +++ b/src/Prompt.php @@ -21,7 +21,8 @@ class Prompt public function __construct( private readonly TransporterInterface $transporter, private readonly string $defaultLabel, - ) {} + ) { + } /** * Retrieve a text prompt by name. Uses default label if no version or label provided. @@ -49,7 +50,7 @@ public function text(string $promptName, ?int $version = null, ?string $label = /** * Retrieve a chat prompt by name. Uses default label if no version or label provided. * - * @param array|null $fallback + * @param array|null $fallback * * @throws InvalidPromptTypeException */ @@ -96,10 +97,10 @@ public function list(?string $name = null, ?int $version = null, ?string $label /** * Create a new prompt. * - * @param ($type is PromptType::TEXT ? string : array) $prompt - * @param array|null $labels - * @param array|null $config - * @param array|null $tags + * @param ($type is PromptType::TEXT ? string : array) $prompt + * @param array|null $labels + * @param array|null $config + * @param array|null $tags * @return ($type is PromptType::TEXT ? TextPromptResponse : ChatPromptResponse) * * @throws JsonException @@ -164,7 +165,7 @@ public function create(string $promptName, string|array $prompt, PromptType $typ /** * Update labels for a specific prompt version. * - * @param array $labels + * @param array $labels * * @throws JsonException */ diff --git a/src/Responses/BasePromptResponse.php b/src/Responses/BasePromptResponse.php index 9ddedf4..79eff3a 100644 --- a/src/Responses/BasePromptResponse.php +++ b/src/Responses/BasePromptResponse.php @@ -11,11 +11,11 @@ use IsCompilable; /** - * @param ($type is 'text' ? string : array) $prompt - * @param array $config - * @param array $tags - * @param array $labels - * @param array $resolutionGraph + * @param ($type is 'text' ? string : array) $prompt + * @param array $config + * @param array $tags + * @param array $labels + * @param array $resolutionGraph */ public function __construct( public string|array $prompt, @@ -33,5 +33,6 @@ public function __construct( public ?bool $isActive = null, public ?string $commitMessage = null, public array $resolutionGraph = [], - ) {} + ) { + } } diff --git a/src/Responses/ChatPromptResponse.php b/src/Responses/ChatPromptResponse.php index 8bfa34d..f4df205 100644 --- a/src/Responses/ChatPromptResponse.php +++ b/src/Responses/ChatPromptResponse.php @@ -7,11 +7,11 @@ readonly class ChatPromptResponse extends BasePromptResponse { /** - * @param array $prompt - * @param array $config - * @param array $tags - * @param array $labels - * @param array $resolutionGraph + * @param array $prompt + * @param array $config + * @param array $tags + * @param array $labels + * @param array $resolutionGraph */ public function __construct( string $id, diff --git a/src/Responses/CommentListResponse.php b/src/Responses/CommentListResponse.php index 3eda0ee..a9ae37b 100644 --- a/src/Responses/CommentListResponse.php +++ b/src/Responses/CommentListResponse.php @@ -9,12 +9,13 @@ readonly class CommentListResponse { /** - * @param array $data + * @param array $data */ public function __construct( public array $data, public MetaData $meta, - ) {} + ) { + } /** * @param array{ @@ -35,7 +36,7 @@ public static function fromArray(array $data): self { return new self( data: array_map( - fn (array $item): CommentResponse => CommentResponse::fromArray($item), + CommentResponse::fromArray(...), $data['data'] ), meta: MetaData::fromArray($data['meta']), diff --git a/src/Responses/CommentResponse.php b/src/Responses/CommentResponse.php index f4371d1..5d4c4df 100644 --- a/src/Responses/CommentResponse.php +++ b/src/Responses/CommentResponse.php @@ -15,7 +15,8 @@ public function __construct( public string $createdAt, public string $updatedAt, public string $projectId, - ) {} + ) { + } /** * @param array{ diff --git a/src/Responses/FallbackPrompt.php b/src/Responses/FallbackPrompt.php index 2083dbe..2d72e38 100644 --- a/src/Responses/FallbackPrompt.php +++ b/src/Responses/FallbackPrompt.php @@ -11,19 +11,6 @@ { use IsCompilable; - /** - * @param ($type is "text" ? string : array) $prompt - */ - public function __construct( - string|array $prompt, - string $type, - ) { - parent::__construct( - prompt: $prompt, - type: $type, - ); - } - /** * Create a text fallback prompt */ @@ -39,7 +26,7 @@ public static function text( /** * Create a chat fallback prompt * - * @param array $content + * @param array $content */ public static function chat( array $content, diff --git a/src/Responses/PromptListResponse.php b/src/Responses/PromptListResponse.php index 0decde6..dc4e983 100644 --- a/src/Responses/PromptListResponse.php +++ b/src/Responses/PromptListResponse.php @@ -11,13 +11,14 @@ readonly class PromptListResponse { /** - * @param array $data + * @param array $data */ public function __construct( public array $data, public MetaData $meta, public PaginationData $pagination, - ) {} + ) { + } /** * @param array{ @@ -29,7 +30,7 @@ public function __construct( public static function fromArray(array $data): self { return new self( - data: array_map(fn (array $data): PromptListItem => PromptListItem::fromArray($data), $data['data']), + data: array_map(PromptListItem::fromArray(...), $data['data']), meta: MetaData::fromArray($data['meta']), pagination: PaginationData::fromArray($data['pagination']), ); diff --git a/src/Responses/ScoreListResponse.php b/src/Responses/ScoreListResponse.php index dd3c1c5..58680dc 100644 --- a/src/Responses/ScoreListResponse.php +++ b/src/Responses/ScoreListResponse.php @@ -26,7 +26,7 @@ public function __construct( public static function fromArray(array $data): self { return new self( - data: array_map(fn (array $item): ScoreResponse => ScoreResponse::fromArray($item), $data['data']), + data: array_map(ScoreResponse::fromArray(...), $data['data']), meta: MetaData::fromArray($data['meta']), ); } diff --git a/src/Responses/TextPromptResponse.php b/src/Responses/TextPromptResponse.php index f43ab0a..c6d3ccf 100644 --- a/src/Responses/TextPromptResponse.php +++ b/src/Responses/TextPromptResponse.php @@ -7,10 +7,10 @@ readonly class TextPromptResponse extends BasePromptResponse { /** - * @param array $config - * @param array $tags - * @param array $labels - * @param array $resolutionGraph + * @param array $config + * @param array $tags + * @param array $labels + * @param array $resolutionGraph */ public function __construct( string $id, diff --git a/src/Testing/Responses/GetChatPromptResponse.php b/src/Testing/Responses/GetChatPromptResponse.php index 3374142..c3a815b 100644 --- a/src/Testing/Responses/GetChatPromptResponse.php +++ b/src/Testing/Responses/GetChatPromptResponse.php @@ -9,8 +9,8 @@ class GetChatPromptResponse extends Response { /** - * @param array|string> $headers - * @param array $data + * @param array|string> $headers + * @param array $data */ public function __construct(int $status = 200, array $headers = [], string $version = '1.1', ?string $reason = null, array $data = []) { @@ -18,7 +18,7 @@ public function __construct(int $status = 200, array $headers = [], string $vers } /** - * @param array $data + * @param array $data * @return array */ public function payload(array $data = []): array diff --git a/src/Testing/Responses/GetCommentListResponse.php b/src/Testing/Responses/GetCommentListResponse.php index b2fa3ca..8ef8ebe 100644 --- a/src/Testing/Responses/GetCommentListResponse.php +++ b/src/Testing/Responses/GetCommentListResponse.php @@ -9,7 +9,7 @@ class GetCommentListResponse extends Response { /** - * @param array|string> $headers + * @param array|string> $headers */ public function __construct(int $status = 200, array $headers = [], string $version = '1.1', ?string $reason = null) { diff --git a/src/Testing/Responses/GetCommentResponse.php b/src/Testing/Responses/GetCommentResponse.php index fa3146c..8789a95 100644 --- a/src/Testing/Responses/GetCommentResponse.php +++ b/src/Testing/Responses/GetCommentResponse.php @@ -9,8 +9,8 @@ class GetCommentResponse extends Response { /** - * @param array|string> $headers - * @param array $data + * @param array|string> $headers + * @param array $data */ public function __construct(int $status = 200, array $headers = [], string $version = '1.1', ?string $reason = null, array $data = []) { @@ -18,7 +18,7 @@ public function __construct(int $status = 200, array $headers = [], string $vers } /** - * @param array $data + * @param array $data * @return array */ public function payload(array $data = []): array diff --git a/src/Testing/Responses/GetPromptResponse.php b/src/Testing/Responses/GetPromptResponse.php index 02a1577..e668d92 100644 --- a/src/Testing/Responses/GetPromptResponse.php +++ b/src/Testing/Responses/GetPromptResponse.php @@ -9,8 +9,8 @@ class GetPromptResponse extends Response { /** - * @param array|string> $headers - * @param array $data + * @param array|string> $headers + * @param array $data */ public function __construct(int $status = 200, array $headers = [], string $version = '1.1', ?string $reason = null, array $data = []) { @@ -18,7 +18,7 @@ public function __construct(int $status = 200, array $headers = [], string $vers } /** - * @param array $data + * @param array $data * @return array */ public function payload(array $data = []): array diff --git a/src/Testing/Responses/PostChatPromptResponse.php b/src/Testing/Responses/PostChatPromptResponse.php index 7328581..071a9eb 100644 --- a/src/Testing/Responses/PostChatPromptResponse.php +++ b/src/Testing/Responses/PostChatPromptResponse.php @@ -9,7 +9,7 @@ class PostChatPromptResponse extends Response { /** - * @param array $data + * @param array $data */ public function __construct(int $status = 201, array $headers = [], string $version = '1.1', ?string $reason = null, array $data = []) { @@ -17,7 +17,7 @@ public function __construct(int $status = 201, array $headers = [], string $vers } /** - * @param array $data + * @param array $data * @return array */ public function payload(array $data = []): array diff --git a/src/Testing/Responses/PostCommentResponse.php b/src/Testing/Responses/PostCommentResponse.php index b10500c..403729d 100644 --- a/src/Testing/Responses/PostCommentResponse.php +++ b/src/Testing/Responses/PostCommentResponse.php @@ -9,8 +9,8 @@ class PostCommentResponse extends Response { /** - * @param array|string> $headers - * @param array $data + * @param array|string> $headers + * @param array $data */ public function __construct(int $status = 200, array $headers = [], string $version = '1.1', ?string $reason = null, array $data = []) { @@ -18,7 +18,7 @@ public function __construct(int $status = 200, array $headers = [], string $vers } /** - * @param array $data + * @param array $data * @return array */ public function payload(array $data = []): array diff --git a/src/Testing/Responses/PostPromptResponse.php b/src/Testing/Responses/PostPromptResponse.php index 3352b3f..5ed663c 100644 --- a/src/Testing/Responses/PostPromptResponse.php +++ b/src/Testing/Responses/PostPromptResponse.php @@ -9,7 +9,7 @@ class PostPromptResponse extends Response { /** - * @param array $data + * @param array $data */ public function __construct(int $status = 201, array $headers = [], string $version = '1.1', ?string $reason = null, array $data = []) { @@ -17,7 +17,7 @@ public function __construct(int $status = 201, array $headers = [], string $vers } /** - * @param array $data + * @param array $data * @return array */ public function payload(array $data = []): array diff --git a/src/Transporters/HttpTransporter.php b/src/Transporters/HttpTransporter.php index e3da1d6..319cf49 100644 --- a/src/Transporters/HttpTransporter.php +++ b/src/Transporters/HttpTransporter.php @@ -21,7 +21,8 @@ class HttpTransporter implements TransporterInterface { public function __construct( public readonly ClientInterface $client - ) {} + ) { + } /** * @throws BadRequestException @@ -44,7 +45,7 @@ public function request(string $method, string $uri, array $options = []): Respo } /** - * @param array $options + * @param array $options * * @throws BadRequestException * @throws ForbiddenException @@ -60,7 +61,7 @@ public function get(string $uri, array $options = []): ResponseInterface } /** - * @param array $options + * @param array $options * * @throws BadRequestException * @throws ForbiddenException diff --git a/src/ValueObjects/MetaData.php b/src/ValueObjects/MetaData.php index 5e83f3b..b46ff25 100644 --- a/src/ValueObjects/MetaData.php +++ b/src/ValueObjects/MetaData.php @@ -11,10 +11,11 @@ public function __construct( public int $limit, public int $totalPages, public int $totalItems, - ) {} + ) { + } /** - * @param array{page: int, limit: int, totalPages: int, totalItems: int} $data + * @param array{page: int, limit: int, totalPages: int, totalItems: int} $data */ public static function fromArray(array $data): self { diff --git a/src/ValueObjects/PaginationData.php b/src/ValueObjects/PaginationData.php index 16beca7..ab3fabc 100644 --- a/src/ValueObjects/PaginationData.php +++ b/src/ValueObjects/PaginationData.php @@ -11,10 +11,11 @@ public function __construct( public int $limit, public int $totalPages, public int $totalItems, - ) {} + ) { + } /** - * @param array{page: int, limit: int, totalPages: int, totalItems: int} $data + * @param array{page: int, limit: int, totalPages: int, totalItems: int} $data */ public static function fromArray(array $data): self { diff --git a/src/ValueObjects/PromptListItem.php b/src/ValueObjects/PromptListItem.php index e79e45f..34ee8a8 100644 --- a/src/ValueObjects/PromptListItem.php +++ b/src/ValueObjects/PromptListItem.php @@ -7,10 +7,10 @@ readonly class PromptListItem { /** - * @param array $tags - * @param array $versions - * @param array $labels - * @param array $lastConfig + * @param array $tags + * @param array $versions + * @param array $labels + * @param array $lastConfig */ public function __construct( public string $name, @@ -19,10 +19,11 @@ public function __construct( public array $versions, public array $labels, public array $lastConfig, - ) {} + ) { + } /** - * @param array{name: string, tags: array, lastUpdatedAt: string, versions: array, labels: array, lastConfig: array} $data + * @param array{name: string, tags: array, lastUpdatedAt: string, versions: array, labels: array, lastConfig: array} $data */ public static function fromArray(array $data): self { diff --git a/tests/Feature/CommentTest.php b/tests/Feature/CommentTest.php index 46bdaa8..3c42720 100644 --- a/tests/Feature/CommentTest.php +++ b/tests/Feature/CommentTest.php @@ -16,7 +16,7 @@ it('can get a comment by id', function (): void { $mock = new MockHandler([ - new GetCommentResponse, + new GetCommentResponse(), ]); $handlerStack = HandlerStack::create($mock); @@ -37,7 +37,7 @@ it('can list comments', function (): void { $mock = new MockHandler([ - new GetCommentListResponse, + new GetCommentListResponse(), ]); $handlerStack = HandlerStack::create($mock); @@ -62,7 +62,7 @@ it('can create a comment', function (): void { $mock = new MockHandler([ - new PostCommentResponse, + new PostCommentResponse(), ]); $handlerStack = HandlerStack::create($mock); @@ -85,7 +85,7 @@ it('can list comments with filters', function (): void { $mock = new MockHandler([ - new GetCommentListResponse, + new GetCommentListResponse(), ]); $handlerStack = HandlerStack::create($mock); diff --git a/tests/Feature/IngestionTest.php b/tests/Feature/IngestionTest.php index e61ca1a..61969d9 100644 --- a/tests/Feature/IngestionTest.php +++ b/tests/Feature/IngestionTest.php @@ -113,7 +113,7 @@ function getEventType(array $history, int $index = 0): string $ingestion = makeIngestion($history); // Act - $ingestion->trace(name: 'test-trace', userId: 'user-123', sessionId: 'sess-456'); + $ingestion->trace(name: 'test-trace', sessionId: 'sess-456', userId: 'user-123'); // Assert $body = getEventBody($history); @@ -166,7 +166,7 @@ function getEventType(array $history, int $index = 0): string // Act $trace = $ingestion->trace(name: 'my-trace', input: 'start'); - $result = $trace->update(output: 'final result', userId: 'user-456'); + $result = $trace->update(userId: 'user-456', output: 'final result'); // Assert expect($result)->toBe($trace) @@ -259,10 +259,10 @@ function getEventType(array $history, int $index = 0): string name: 'test-generation', input: ['messages' => [['role' => 'user', 'content' => 'Hi']]], output: 'Hello', - promptName: 'prompt-x', - promptVersion: 3, model: 'gpt-4o', modelParameters: ['temperature' => 0.2], + promptName: 'prompt-x', + promptVersion: 3, metadata: ['source' => 'test'], ); diff --git a/tests/Feature/PromptTest.php b/tests/Feature/PromptTest.php index 0c44432..a7df9fc 100644 --- a/tests/Feature/PromptTest.php +++ b/tests/Feature/PromptTest.php @@ -25,7 +25,7 @@ it('can get a text prompt', function (): void { $mock = new MockHandler([ - new GetPromptResponse, + new GetPromptResponse(), ]); $handlerStack = HandlerStack::create($mock); @@ -45,7 +45,7 @@ it('returns an error when chat prompt is provided when using text type', function (): void { $mock = new MockHandler([ - new GetChatPromptResponse, + new GetChatPromptResponse(), ]); $handlerStack = HandlerStack::create($mock); @@ -60,7 +60,7 @@ it('can list prompts', function (): void { $mock = new MockHandler([ - new GetPromptListResponse, + new GetPromptListResponse(), ]); $handlerStack = HandlerStack::create($mock); @@ -76,7 +76,7 @@ it('returns null when prompt not found and no fallback is provided', function (): void { $mock = new MockHandler([ - new NoPromptFoundResponse, + new NoPromptFoundResponse(), ]); $handlerStack = HandlerStack::create($mock); @@ -88,7 +88,7 @@ it('can get a chat prompt', function (): void { $mock = new MockHandler([ - new GetChatPromptResponse, + new GetChatPromptResponse(), ]); $handlerStack = HandlerStack::create($mock); @@ -108,7 +108,7 @@ it('can compile a text prompt', function (): void { $mock = new MockHandler([ - new GetPromptResponse, + new GetPromptResponse(), ]); $handlerStack = HandlerStack::create($mock); @@ -129,7 +129,7 @@ it('returns an error when text prompt is provided when using text chat', function (): void { $mock = new MockHandler([ - new GetPromptResponse, + new GetPromptResponse(), ]); $handlerStack = HandlerStack::create($mock); @@ -144,7 +144,7 @@ it('can compile a chat prompt', function (): void { $mock = new MockHandler([ - new GetChatPromptResponse, + new GetChatPromptResponse(), ]); $handlerStack = HandlerStack::create($mock); @@ -168,7 +168,7 @@ it('can create a text prompt', function (): void { $mock = new MockHandler([ - new PostPromptResponse, + new PostPromptResponse(), ]); $handlerStack = HandlerStack::create($mock); @@ -188,7 +188,7 @@ it('can create a chat prompt', function (): void { $mock = new MockHandler([ - new PostChatPromptResponse, + new PostChatPromptResponse(), ]); $handlerStack = HandlerStack::create($mock); @@ -211,7 +211,7 @@ it('uses fallback text prompt when prompt not found', function (): void { $mock = new MockHandler([ - new NoPromptFoundResponse, + new NoPromptFoundResponse(), ]); $handlerStack = HandlerStack::create($mock); @@ -232,7 +232,7 @@ it('uses fallback chat prompt when prompt not found', function (): void { $mock = new MockHandler([ - new NoPromptFoundResponse, + new NoPromptFoundResponse(), ]); $handlerStack = HandlerStack::create($mock); @@ -277,7 +277,7 @@ it('can compile fallback text prompt', function (): void { $mock = new MockHandler([ - new NoPromptFoundResponse, + new NoPromptFoundResponse(), ]); $handlerStack = HandlerStack::create($mock); @@ -298,7 +298,7 @@ it('can compile fallback chat prompt', function (): void { $mock = new MockHandler([ - new NoPromptFoundResponse, + new NoPromptFoundResponse(), ]); $handlerStack = HandlerStack::create($mock); diff --git a/tests/Feature/ScoreTest.php b/tests/Feature/ScoreTest.php index aa9b510..da4ada0 100644 --- a/tests/Feature/ScoreTest.php +++ b/tests/Feature/ScoreTest.php @@ -29,9 +29,9 @@ $score = (new Langfuse(new HttpTransporter($client))) ->score() ->create( - traceId: 'trace-456', name: 'accuracy', value: 0.95, + traceId: 'trace-456', dataType: ScoreDataType::NUMERIC, ); @@ -59,9 +59,9 @@ $score = (new Langfuse(new HttpTransporter($client))) ->score() ->create( - traceId: 'trace-456', name: 'helpfulness', value: 'helpful', + traceId: 'trace-456', dataType: ScoreDataType::CATEGORICAL, ); @@ -86,9 +86,9 @@ $score = (new Langfuse(new HttpTransporter($client))) ->score() ->create( - traceId: 'trace-456', name: 'is_correct', value: 1, + traceId: 'trace-456', dataType: ScoreDataType::BOOLEAN, ); @@ -154,8 +154,8 @@ page: 1, limit: 10, name: 'accuracy', - dataType: ScoreDataType::NUMERIC, traceId: 'trace-123', + dataType: ScoreDataType::NUMERIC, ); expect($history)->toHaveCount(1); @@ -217,9 +217,9 @@ (new Langfuse(new HttpTransporter($client))) ->score() ->create( - traceId: 'trace-456', name: 'accuracy', value: 0.95, + traceId: 'trace-456', dataType: ScoreDataType::NUMERIC, id: 'custom-score-id', observationId: 'obs-789',