Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
58.33% |
7 / 12 |
|
80.00% |
4 / 5 |
CRAP | |
0.00% |
0 / 1 |
| InterfaceDefinition | |
58.33% |
7 / 12 |
|
80.00% |
4 / 5 |
12.63 | |
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 | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| needsDefinitions | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 | |||
| 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\ValueObjects\JavascriptIdentifier; |
| 9 | |
| 10 | /** |
| 11 | * Typescript definition for an interface. |
| 12 | */ |
| 13 | class InterfaceDefinition implements TypescriptTypeDeclarationInterface |
| 14 | { |
| 15 | public function __construct( |
| 16 | public JavascriptIdentifier $name, |
| 17 | public ArgumentList $properties, |
| 18 | ) { |
| 19 | } |
| 20 | |
| 21 | public function toTypescript(): string |
| 22 | { |
| 23 | $properties = []; |
| 24 | foreach ($this->properties as $property) { |
| 25 | $properties[] = $property->toTypescript() . ';'; |
| 26 | } |
| 27 | return 'interface ' . $this->name->toNative() . ' { ' . implode(' ', $properties) . ' }'; |
| 28 | } |
| 29 | |
| 30 | public function toJavascript(): string |
| 31 | { |
| 32 | return ''; |
| 33 | } |
| 34 | |
| 35 | public function providesDefinitions(): JavascriptIdentifierList |
| 36 | { |
| 37 | return new JavascriptIdentifierList([$this->name]); |
| 38 | } |
| 39 | |
| 40 | public function needsDefinitions(): JavascriptIdentifierList |
| 41 | { |
| 42 | $definitions = new JavascriptIdentifierList(); |
| 43 | foreach ($this->properties as $property) { |
| 44 | /** @var FunctionArgument $property */ |
| 45 | foreach ($property->needsDefinitions() as $definition) { |
| 46 | $definitions = $definitions->append($definition); |
| 47 | } |
| 48 | } |
| 49 | return $definitions; |
| 50 | } |
| 51 | } |