Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
50.00% |
6 / 12 |
|
50.00% |
3 / 6 |
CRAP | |
0.00% |
0 / 1 |
| ForInStatement | |
50.00% |
6 / 12 |
|
50.00% |
3 / 6 |
22.50 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toTypescript | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toJavascript | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| needsDefinitions | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| render | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
4 | |||
| providesDefinitions | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | namespace Apie\TypescriptCodeBuilder\Dto\ControlFlow; |
| 3 | |
| 4 | use Apie\TypescriptCodeBuilder\Lists\JavascriptIdentifierList; |
| 5 | use Apie\TypescriptCodeBuilder\TypescriptFileExpressionInterface; |
| 6 | use Apie\TypescriptCodeBuilder\Utils\ControlFlowUtils; |
| 7 | |
| 8 | class ForInStatement implements TypescriptFileExpressionInterface |
| 9 | { |
| 10 | public function __construct( |
| 11 | public TypescriptFileExpressionInterface $variable, |
| 12 | public TypescriptFileExpressionInterface $iterable, |
| 13 | public BlockStatement $codeList, |
| 14 | ) { |
| 15 | } |
| 16 | |
| 17 | public function toTypescript(): string |
| 18 | { |
| 19 | return $this->render(true); |
| 20 | } |
| 21 | public function toJavascript(): string |
| 22 | { |
| 23 | return $this->render(false); |
| 24 | } |
| 25 | public function needsDefinitions(): JavascriptIdentifierList |
| 26 | { |
| 27 | $definitions = ControlFlowUtils::mergeDefinitions($this->variable, $this->iterable); |
| 28 | foreach ($this->codeList->needsDefinitions() as $definition) { |
| 29 | $definitions = $definitions->append($definition); |
| 30 | } |
| 31 | return $definitions; |
| 32 | } |
| 33 | protected function render(bool $typescript): string |
| 34 | { |
| 35 | $variable = $typescript ? $this->variable->toTypescript() : $this->variable->toJavascript(); |
| 36 | $iterable = $typescript ? $this->iterable->toTypescript() : $this->iterable->toJavascript(); |
| 37 | $body = ControlFlowUtils::renderBlock($this->codeList->codeList, $typescript); |
| 38 | return 'for (' . rtrim($variable, ';') . ' in ' . $iterable . ') {' . ($body === '' ? '' : PHP_EOL . $body) . PHP_EOL . '}'; |
| 39 | } |
| 40 | |
| 41 | public function providesDefinitions(bool $applyBlockScope): JavascriptIdentifierList |
| 42 | { |
| 43 | return $this->codeList->providesDefinitions(true); |
| 44 | } |
| 45 | } |