Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
91.67% |
11 / 12 |
|
80.00% |
4 / 5 |
CRAP | |
0.00% |
0 / 1 |
| JsonLiteralExpression | |
91.67% |
11 / 12 |
|
80.00% |
4 / 5 |
6.02 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toTypescript | |
100.00% |
8 / 8 |
|
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% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | namespace Apie\TypescriptCodeBuilder\Dto\Expressions; |
| 3 | |
| 4 | use Apie\TypescriptCodeBuilder\Lists\JavascriptIdentifierList; |
| 5 | use Apie\TypescriptCodeBuilder\TypescriptFileExpressionInterface; |
| 6 | |
| 7 | class JsonLiteralExpression implements TypescriptFileExpressionInterface |
| 8 | { |
| 9 | public function __construct(public mixed $value, public bool $prettified = false) |
| 10 | { |
| 11 | } |
| 12 | |
| 13 | public function toTypescript(): string |
| 14 | { |
| 15 | if ($this->prettified) { |
| 16 | return json_encode($this->value, JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT); |
| 17 | } |
| 18 | return 'JSON.parse(' |
| 19 | . json_encode( |
| 20 | json_encode($this->value, JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES), |
| 21 | JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES |
| 22 | ) |
| 23 | .')'; |
| 24 | } |
| 25 | public function toJavascript(): string |
| 26 | { |
| 27 | return $this->toTypescript(); |
| 28 | } |
| 29 | public function providesDefinitions(bool $applyBlockScope): JavascriptIdentifierList |
| 30 | { |
| 31 | return new JavascriptIdentifierList(); |
| 32 | } |
| 33 | public function needsDefinitions(): JavascriptIdentifierList |
| 34 | { |
| 35 | return new JavascriptIdentifierList(); |
| 36 | } |
| 37 | } |