Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
91.67% |
11 / 12 |
|
80.00% |
4 / 5 |
CRAP | |
0.00% |
0 / 1 |
| ObjectTypeDefinition | |
91.67% |
11 / 12 |
|
80.00% |
4 / 5 |
8.04 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toTypescript | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| toJavascript | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| providesDefinitions | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| needsDefinitions | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | namespace Apie\TypescriptCodeBuilder\Dto\Typehints; |
| 3 | |
| 4 | use Apie\TypescriptCodeBuilder\Dto\FunctionArgument; |
| 5 | use Apie\TypescriptCodeBuilder\Lists\ArgumentList; |
| 6 | use Apie\TypescriptCodeBuilder\Lists\JavascriptIdentifierList; |
| 7 | use Apie\TypescriptCodeBuilder\TypescriptTypeDeclarationInterface; |
| 8 | use Apie\TypescriptCodeBuilder\Utils\ControlFlowUtils; |
| 9 | |
| 10 | /** |
| 11 | * Typescript definition for an object type. |
| 12 | * |
| 13 | * @param array<int, FunctionArgument> $properties |
| 14 | */ |
| 15 | class ObjectTypeDefinition implements TypescriptTypeDeclarationInterface |
| 16 | { |
| 17 | public function __construct( |
| 18 | public ArgumentList $properties, |
| 19 | ) { |
| 20 | } |
| 21 | |
| 22 | public function toTypescript(): string |
| 23 | { |
| 24 | $properties = []; |
| 25 | foreach ($this->properties as $property) { |
| 26 | $properties[] = $property->toTypescript() . ';'; |
| 27 | } |
| 28 | return '{' . PHP_EOL . ControlFlowUtils::indent(implode(PHP_EOL, $properties)) . PHP_EOL . '}'; |
| 29 | } |
| 30 | |
| 31 | public function toJavascript(): string |
| 32 | { |
| 33 | return ''; |
| 34 | } |
| 35 | |
| 36 | public function providesDefinitions(bool $applyBlockScope): JavascriptIdentifierList |
| 37 | { |
| 38 | return new JavascriptIdentifierList(); |
| 39 | } |
| 40 | |
| 41 | public function needsDefinitions(): JavascriptIdentifierList |
| 42 | { |
| 43 | $definitions = new JavascriptIdentifierList(); |
| 44 | foreach ($this->properties as $property) { |
| 45 | /** @var FunctionArgument $property */ |
| 46 | foreach ($property->needsDefinitions() as $definition) { |
| 47 | $definitions = $definitions->append($definition); |
| 48 | } |
| 49 | } |
| 50 | return $definitions; |
| 51 | } |
| 52 | } |