Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
7 / 7 |
|
100.00% |
6 / 6 |
CRAP | |
100.00% |
1 / 1 |
| RawJavascript | |
100.00% |
7 / 7 |
|
100.00% |
6 / 6 |
6 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| createRandom | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toTypescript | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toJavascript | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| providesDefinitions | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| needsDefinitions | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | namespace Apie\TypescriptCodeBuilder\Dto; |
| 3 | |
| 4 | use Apie\Core\Attributes\FakeMethod; |
| 5 | use Apie\Core\Attributes\Optional; |
| 6 | use Apie\TypescriptCodeBuilder\Lists\JavascriptIdentifierList; |
| 7 | use Apie\TypescriptCodeBuilder\TypescriptFileExpressionInterface; |
| 8 | use Faker\Generator; |
| 9 | |
| 10 | #[FakeMethod('createRandom')] |
| 11 | class RawJavascript implements TypescriptFileExpressionInterface |
| 12 | { |
| 13 | #[Optional] |
| 14 | public JavascriptIdentifierList $providesDefinition; |
| 15 | |
| 16 | #[Optional] |
| 17 | public JavascriptIdentifierList $needsDefinition; |
| 18 | |
| 19 | public function __construct( |
| 20 | public string $javascriptCode, |
| 21 | public ?string $typescriptCode = null, |
| 22 | array $providesDefinition = [], |
| 23 | array $needsDefinition = [], |
| 24 | ) { |
| 25 | $this->providesDefinition = new JavascriptIdentifierList($providesDefinition); |
| 26 | $this->needsDefinition = new JavascriptIdentifierList($needsDefinition); |
| 27 | } |
| 28 | |
| 29 | public static function createRandom(Generator $faker): self |
| 30 | { |
| 31 | return new RawJavascript('// ' . $faker->text(40)); |
| 32 | } |
| 33 | |
| 34 | public function toTypescript(): string |
| 35 | { |
| 36 | return $this->typescriptCode ?? $this->javascriptCode; |
| 37 | } |
| 38 | public function toJavascript(): string |
| 39 | { |
| 40 | return $this->javascriptCode; |
| 41 | } |
| 42 | public function providesDefinitions(): JavascriptIdentifierList |
| 43 | { |
| 44 | return $this->providesDefinition; |
| 45 | } |
| 46 | public function needsDefinitions(): JavascriptIdentifierList |
| 47 | { |
| 48 | return $this->needsDefinition; |
| 49 | } |
| 50 | } |