Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
6 / 6 |
|
100.00% |
6 / 6 |
CRAP | |
100.00% |
1 / 1 |
| TypescriptDeclaration | |
100.00% |
6 / 6 |
|
100.00% |
6 / 6 |
6 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
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\TypescriptCodeBuilder\Dto\Typehints\ObjectTypeDefinition; |
| 6 | use Apie\TypescriptCodeBuilder\Lists\JavascriptIdentifierList; |
| 7 | use Apie\TypescriptCodeBuilder\TypescriptFileExpressionInterface; |
| 8 | use Apie\TypescriptCodeBuilder\TypescriptTypeDeclarationInterface; |
| 9 | use Apie\TypescriptCodeBuilder\ValueObjects\JavascriptIdentifier; |
| 10 | use Faker\Generator; |
| 11 | |
| 12 | #[FakeMethod('createRandom')] |
| 13 | class TypescriptDeclaration implements TypescriptFileExpressionInterface |
| 14 | { |
| 15 | public function __construct( |
| 16 | public JavascriptIdentifier $name, |
| 17 | public TypescriptTypeDeclarationInterface $typehint |
| 18 | ) { |
| 19 | } |
| 20 | |
| 21 | public static function createRandom(Generator $faker): self |
| 22 | { |
| 23 | return new self(JavascriptIdentifier::createRandom($faker), $faker->fakeClass(ObjectTypeDefinition::class)); |
| 24 | } |
| 25 | |
| 26 | public function toTypescript(): string |
| 27 | { |
| 28 | return 'type ' . $this->name . ' = ' . $this->typehint->toTypescript() . ';'; |
| 29 | } |
| 30 | public function toJavascript(): string |
| 31 | { |
| 32 | return ''; |
| 33 | } |
| 34 | public function providesDefinitions(): JavascriptIdentifierList |
| 35 | { |
| 36 | return new JavascriptIdentifierList([$this->name]); |
| 37 | } |
| 38 | public function needsDefinitions(): JavascriptIdentifierList |
| 39 | { |
| 40 | return $this->typehint->needsDefinitions(); |
| 41 | } |
| 42 | } |