Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
33.33% |
5 / 15 |
|
40.00% |
2 / 5 |
CRAP | |
0.00% |
0 / 1 |
| ObjectExpression | |
33.33% |
5 / 15 |
|
40.00% |
2 / 5 |
33.00 | |
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 | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| 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\Expressions; |
| 3 | |
| 4 | use Apie\TypescriptCodeBuilder\Lists\JavascriptIdentifierList; |
| 5 | use Apie\TypescriptCodeBuilder\Lists\TypescriptExpressionHashmap; |
| 6 | use Apie\TypescriptCodeBuilder\TypescriptFileExpressionInterface; |
| 7 | |
| 8 | class ObjectExpression implements TypescriptFileExpressionInterface |
| 9 | { |
| 10 | public function __construct(public TypescriptExpressionHashmap $properties) |
| 11 | { |
| 12 | } |
| 13 | |
| 14 | public function toTypescript(): string |
| 15 | { |
| 16 | $properties = []; |
| 17 | foreach ($this->properties as $name => $expression) { |
| 18 | $properties[] = $name . ': ' . $expression->toTypescript(); |
| 19 | } |
| 20 | return '{ ' . implode(', ', $properties) . ' }'; |
| 21 | } |
| 22 | |
| 23 | public function toJavascript(): string |
| 24 | { |
| 25 | $properties = []; |
| 26 | foreach ($this->properties as $name => $expression) { |
| 27 | $properties[] = $name . ': ' . $expression->toJavascript(); |
| 28 | } |
| 29 | return '{ ' . implode(', ', $properties) . ' }'; |
| 30 | } |
| 31 | public function providesDefinitions(): JavascriptIdentifierList |
| 32 | { |
| 33 | return new JavascriptIdentifierList(); |
| 34 | } |
| 35 | public function needsDefinitions(): JavascriptIdentifierList |
| 36 | { |
| 37 | $definitions = new JavascriptIdentifierList(); |
| 38 | foreach ($this->properties as $expression) { |
| 39 | foreach ($expression->needsDefinitions() as $definition) { |
| 40 | $definitions = $definitions->append($definition); |
| 41 | } |
| 42 | } |
| 43 | return $definitions; |
| 44 | } |
| 45 | } |