Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
40.00% covered (danger)
40.00%
2 / 5
40.00% covered (danger)
40.00%
2 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
LiteralTypeDefinition
40.00% covered (danger)
40.00%
2 / 5
40.00% covered (danger)
40.00%
2 / 5
10.40
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 toTypescript
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 toJavascript
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 providesDefinitions
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 needsDefinitions
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2namespace Apie\TypescriptCodeBuilder\Dto\Typehints;
3
4use Apie\TypescriptCodeBuilder\Lists\JavascriptIdentifierList;
5use Apie\TypescriptCodeBuilder\TypescriptTypeDeclarationInterface;
6
7/**
8 * Typescript definition for a string, number, boolean, or null literal type.
9 */
10class LiteralTypeDefinition implements TypescriptTypeDeclarationInterface
11{
12    public function __construct(
13        public string|int|float|bool|null $value,
14    ) {
15    }
16
17    public function toTypescript(): string
18    {
19        return json_encode($this->value, JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES);
20    }
21
22    public function toJavascript(): string
23    {
24        return '';
25    }
26
27    public function providesDefinitions(): JavascriptIdentifierList
28    {
29        return new JavascriptIdentifierList();
30    }
31
32    public function needsDefinitions(): JavascriptIdentifierList
33    {
34        return new JavascriptIdentifierList();
35    }
36}