Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
62.50% covered (warning)
62.50%
5 / 8
50.00% covered (danger)
50.00%
3 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
DoWhileStatement
62.50% covered (warning)
62.50%
5 / 8
50.00% covered (danger)
50.00%
3 / 6
11.38
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%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 toJavascript
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 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 render
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
3
 providesDefinitions
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2namespace Apie\TypescriptCodeBuilder\Dto\ControlFlow;
3
4use Apie\TypescriptCodeBuilder\Lists\JavascriptIdentifierList;
5use Apie\TypescriptCodeBuilder\TypescriptFileExpressionInterface;
6use Apie\TypescriptCodeBuilder\Utils\ControlFlowUtils;
7
8class DoWhileStatement implements TypescriptFileExpressionInterface
9{
10    public function __construct(public BlockStatement $codeList, public TypescriptFileExpressionInterface $condition)
11    {
12    }
13
14    public function toTypescript(): string
15    {
16        return $this->render(true);
17    }
18    public function toJavascript(): string
19    {
20        return $this->render(false);
21    }
22    public function needsDefinitions(): JavascriptIdentifierList
23    {
24        return ControlFlowUtils::mergeDefinitions($this->condition, $this->codeList);
25    }
26    private function render(bool $typescript): string
27    {
28        $body = ControlFlowUtils::renderBlock($this->codeList->codeList, $typescript);
29        $condition = $typescript ? $this->condition->toTypescript() : $this->condition->toJavascript();
30        return 'do {' . ($body === '' ? '' : PHP_EOL . $body) . PHP_EOL . '} while (' . $condition . ');';
31    }
32
33    public function providesDefinitions(bool $applyBlockScope): JavascriptIdentifierList
34    {
35        return $this->codeList->providesDefinitions(true);
36    }
37}