Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
92.31% |
12 / 13 |
|
83.33% |
5 / 6 |
CRAP | |
0.00% |
0 / 1 |
| CallbackTypeDefinition | |
92.31% |
12 / 13 |
|
83.33% |
5 / 6 |
8.03 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| createRandom | |
100.00% |
4 / 4 |
|
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 | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| needsDefinitions | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | namespace Apie\TypescriptCodeBuilder\Dto\Typehints; |
| 3 | |
| 4 | use Apie\Core\Attributes\FakeMethod; |
| 5 | use Apie\TypescriptCodeBuilder\Dto\FunctionArgument; |
| 6 | use Apie\TypescriptCodeBuilder\Enums\TypescriptType; |
| 7 | use Apie\TypescriptCodeBuilder\Lists\ArgumentList; |
| 8 | use Apie\TypescriptCodeBuilder\Lists\JavascriptIdentifierList; |
| 9 | use Apie\TypescriptCodeBuilder\TypescriptTypeDeclarationInterface; |
| 10 | use Faker\Generator; |
| 11 | |
| 12 | /** |
| 13 | * Typescript definition for a callback type. |
| 14 | */ |
| 15 | #[FakeMethod('createRandom')] |
| 16 | class CallbackTypeDefinition implements TypescriptTypeDeclarationInterface |
| 17 | { |
| 18 | public function __construct( |
| 19 | public ArgumentList $arguments, |
| 20 | public TypescriptTypeDeclarationInterface $returnType, |
| 21 | ) { |
| 22 | } |
| 23 | |
| 24 | public static function createRandom(Generator $faker) |
| 25 | { |
| 26 | return new self( |
| 27 | $faker->fakeClass(ArgumentList::class), |
| 28 | $faker->fakeClass(TypescriptType::class), |
| 29 | ); |
| 30 | } |
| 31 | |
| 32 | public function toTypescript(): string |
| 33 | { |
| 34 | return '(' . $this->arguments->toTypescript() . ') => ' . $this->returnType->toTypescript(); |
| 35 | } |
| 36 | |
| 37 | public function toJavascript(): string |
| 38 | { |
| 39 | return ''; |
| 40 | } |
| 41 | |
| 42 | public function providesDefinitions(): JavascriptIdentifierList |
| 43 | { |
| 44 | return new JavascriptIdentifierList(); |
| 45 | } |
| 46 | |
| 47 | public function needsDefinitions(): JavascriptIdentifierList |
| 48 | { |
| 49 | $definitions = $this->returnType->needsDefinitions(); |
| 50 | foreach ($this->arguments as $argument) { |
| 51 | /** @var FunctionArgument $argument */ |
| 52 | foreach ($argument->needsDefinitions() as $definition) { |
| 53 | $definitions = $definitions->append($definition); |
| 54 | } |
| 55 | } |
| 56 | return $definitions; |
| 57 | } |
| 58 | } |