Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
94.12% |
16 / 17 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
Es6CodeController | |
94.12% |
16 / 17 |
|
50.00% |
1 / 2 |
4.00 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
__invoke | |
93.75% |
15 / 16 |
|
0.00% |
0 / 1 |
3.00 |
1 | <?php |
2 | namespace Apie\TypescriptClientBuilder\Controllers; |
3 | |
4 | use Apie\Core\BoundedContext\BoundedContextHashmap; |
5 | use Apie\TypescriptClientBuilder\CodeGenerators\Es6CodeGenerator; |
6 | use Nyholm\Psr7\Response; |
7 | use Psr\Http\Message\ServerRequestInterface; |
8 | |
9 | class Es6CodeController |
10 | { |
11 | public function __construct( |
12 | private readonly Es6CodeGenerator $codeGenerator, |
13 | private readonly BoundedContextHashmap $boundedContextHashmap, |
14 | private readonly string $apiPrefix |
15 | ) { |
16 | } |
17 | |
18 | public function __invoke(ServerRequestInterface $request): Response |
19 | { |
20 | $uri = $request->getUri(); |
21 | $scheme = $uri->getScheme(); |
22 | $host = $uri->getHost(); |
23 | $port = $uri->getPort(); |
24 | $baseUrl = $scheme . '://' . $host; |
25 | if ($port !== null && !in_array($port, [80, 443])) { |
26 | $baseUrl .= ':' . $port; |
27 | } |
28 | $apiPrefix = $baseUrl . $this->apiPrefix; |
29 | return new Response( |
30 | 200, |
31 | ['Content-Type' => 'application/javascript'], |
32 | $this->codeGenerator->create( |
33 | $this->boundedContextHashmap, |
34 | $apiPrefix |
35 | ) |
36 | ); |
37 | } |
38 | } |