Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
53.85% covered (warning)
53.85%
7 / 13
60.00% covered (warning)
60.00%
3 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
GenericTypeDefinition
53.85% covered (warning)
53.85%
7 / 13
60.00% covered (warning)
60.00%
3 / 5
11.82
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%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 toJavascript
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 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 / 5
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2namespace Apie\TypescriptCodeBuilder\Dto\Typehints;
3
4use Apie\TypescriptCodeBuilder\Lists\JavascriptIdentifierList;
5use Apie\TypescriptCodeBuilder\Lists\TypescriptDeclarationList;
6use Apie\TypescriptCodeBuilder\TypescriptTypeDeclarationInterface;
7use Apie\TypescriptCodeBuilder\ValueObjects\JavascriptIdentifier;
8
9class GenericTypeDefinition implements TypescriptTypeDeclarationInterface
10{
11    public function __construct(
12        public JavascriptIdentifier $name,
13        public TypescriptDeclarationList $typeArguments,
14    ) {
15    }
16
17    public function toTypescript(): string
18    {
19        $arguments = array_map(
20            static fn (TypescriptTypeDeclarationInterface $type): string => $type->toTypescript(),
21            $this->typeArguments->toArray(),
22        );
23        return $this->name->toNative() . '<' . implode(', ', $arguments) . '>';
24    }
25
26    public function toJavascript(): string
27    {
28        return '';
29    }
30
31    public function providesDefinitions(): JavascriptIdentifierList
32    {
33        return new JavascriptIdentifierList();
34    }
35
36    public function needsDefinitions(): JavascriptIdentifierList
37    {
38        $definitions = new JavascriptIdentifierList([$this->name]);
39        foreach ($this->typeArguments as $type) {
40            foreach ($type->needsDefinitions() as $definition) {
41                $definitions = $definitions->append($definition);
42            }
43        }
44        return $definitions;
45    }
46}