Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
ExampleValue
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
2 / 2
4
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 toExample
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2namespace Apie\Core\Attributes;
3
4use Apie\Serializer\Lists\SerializedHashmap;
5use Apie\Serializer\Lists\SerializedList;
6use Attribute;
7
8/**
9 * This is used on classes, traits or interface to give a class a human readable examples.
10 * This can be used for LLM's or in the OpenAPI specification to describe a field better.
11 */
12#[Attribute(Attribute::IS_REPEATABLE|Attribute::TARGET_CLASS|Attribute::TARGET_METHOD|Attribute::TARGET_PROPERTY|Attribute::TARGET_PARAMETER|Attribute::TARGET_CLASS_CONSTANT)]
13final class ExampleValue
14{
15    public function __construct(
16        public readonly string|int|float|bool|SerializedList|SerializedHashmap|null $example,
17        public readonly ?string $name = null,
18    ) {
19    }
20
21    /**
22     * @return array<string, mixed>|string|int|float|bool|null
23     */
24    public function toExample(): string|int|float|bool|array|null
25    {
26        if ($this->example instanceof SerializedList || $this->example instanceof SerializedHashmap) {
27            return $this->example->toArray();
28        }
29        return $this->example;
30    }
31}