Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
80.00% |
8 / 10 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| CmsInputOption | |
80.00% |
8 / 10 |
|
50.00% |
1 / 2 |
4.13 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| forType | |
77.78% |
7 / 9 |
|
0.00% |
0 / 1 |
3.10 | |||
| 1 | <?php |
| 2 | namespace Apie\Core\Dto; |
| 3 | |
| 4 | use Apie\Core\Enums\FileStreamType; |
| 5 | use Apie\Core\Lists\ValueOptionList; |
| 6 | use Apie\Core\Utils\ConverterUtils; |
| 7 | use Attribute; |
| 8 | use ReflectionType; |
| 9 | |
| 10 | #[Attribute(Attribute::TARGET_CLASS|Attribute::TARGET_METHOD|Attribute::TARGET_PROPERTY|Attribute::TARGET_PARAMETER)] |
| 11 | class CmsInputOption implements DtoInterface |
| 12 | { |
| 13 | public function __construct( |
| 14 | // for file stream inputs |
| 15 | public readonly ?FileStreamType $streamType = null, |
| 16 | // for date format inputs a php date format string |
| 17 | public readonly ?string $dateFormatMethod = null, |
| 18 | // for dropdowns |
| 19 | public readonly ?ValueOptionList $options = null, |
| 20 | // autocomplete url |
| 21 | public readonly ?string $autocompleteUrl = null, |
| 22 | // image url |
| 23 | public readonly ?string $imageUrl = null, |
| 24 | // forced value |
| 25 | public readonly mixed $forcedValue = null, |
| 26 | ) { |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * @return array<string, mixed> |
| 31 | */ |
| 32 | public function forType(ReflectionType $type): array |
| 33 | { |
| 34 | $data = get_object_vars($this); |
| 35 | $class = ConverterUtils::toReflectionClass($type); |
| 36 | if ($class === null) { |
| 37 | unset($data['dateFormatMethod']); |
| 38 | return $data; |
| 39 | } |
| 40 | if ($this->dateFormatMethod) { |
| 41 | unset($data['dateFormatMethod']); |
| 42 | $data['dateFormat'] = $class->getMethod($this->dateFormatMethod)->invoke(null); |
| 43 | } |
| 44 | return $data; |
| 45 | } |
| 46 | } |