Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
60.00% |
9 / 15 |
|
66.67% |
4 / 6 |
CRAP | |
0.00% |
0 / 1 |
| IntersectionTypeDefinition | |
60.00% |
9 / 15 |
|
66.67% |
4 / 6 |
12.10 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| createRandom | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| toTypescript | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| toJavascript | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| providesDefinitions | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| needsDefinitions | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | namespace Apie\TypescriptCodeBuilder\Dto\Typehints; |
| 3 | |
| 4 | use Apie\Core\Attributes\FakeMethod; |
| 5 | use Apie\TypescriptCodeBuilder\Enums\TypescriptType; |
| 6 | use Apie\TypescriptCodeBuilder\Lists\JavascriptIdentifierList; |
| 7 | use Apie\TypescriptCodeBuilder\Lists\TypescriptDeclarationList; |
| 8 | use Apie\TypescriptCodeBuilder\TypescriptTypeDeclarationInterface; |
| 9 | |
| 10 | /** |
| 11 | * Typescript definition for an intersection type. |
| 12 | * |
| 13 | * @param array<int, TypescriptTypeDeclarationInterface> $types |
| 14 | */ |
| 15 | #[FakeMethod('createRandom')] |
| 16 | class IntersectionTypeDefinition implements TypescriptTypeDeclarationInterface |
| 17 | { |
| 18 | public function __construct( |
| 19 | public TypescriptDeclarationList $types, |
| 20 | ) { |
| 21 | } |
| 22 | |
| 23 | public static function createRandom(): self |
| 24 | { |
| 25 | return new self( |
| 26 | new TypescriptDeclarationList([TypescriptType::Boolean, TypescriptType::String]) |
| 27 | ); |
| 28 | } |
| 29 | |
| 30 | public function toTypescript(): string |
| 31 | { |
| 32 | return implode(' & ', array_map( |
| 33 | static fn (TypescriptTypeDeclarationInterface $type): string => '(' . $type->toTypescript() . ')', |
| 34 | $this->types->toArray(), |
| 35 | )); |
| 36 | } |
| 37 | |
| 38 | public function toJavascript(): string |
| 39 | { |
| 40 | return ''; |
| 41 | } |
| 42 | |
| 43 | public function providesDefinitions(): JavascriptIdentifierList |
| 44 | { |
| 45 | return new JavascriptIdentifierList(); |
| 46 | } |
| 47 | |
| 48 | public function needsDefinitions(): JavascriptIdentifierList |
| 49 | { |
| 50 | $definitions = new JavascriptIdentifierList(); |
| 51 | foreach ($this->types as $type) { |
| 52 | foreach ($type->needsDefinitions() as $definition) { |
| 53 | $definitions = $definitions->append($definition); |
| 54 | } |
| 55 | } |
| 56 | return $definitions; |
| 57 | } |
| 58 | } |