Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
47.37% |
9 / 19 |
|
40.00% |
2 / 5 |
CRAP | |
0.00% |
0 / 1 |
| ExpressionList | |
47.37% |
9 / 19 |
|
40.00% |
2 / 5 |
20.81 | |
0.00% |
0 / 1 |
| offsetGet | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| toTypescript | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| toJavascript | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| needsDefinitions | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 | |||
| createRandom | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | namespace Apie\TypescriptCodeBuilder\Lists; |
| 3 | |
| 4 | use Apie\Core\Attributes\FakeMethod; |
| 5 | use Apie\Core\Lists\ItemList; |
| 6 | use Apie\TypescriptCodeBuilder\Dto\Expressions\IdentifierExpression; |
| 7 | use Apie\TypescriptCodeBuilder\Dto\Expressions\StringLiteralExpression; |
| 8 | use Apie\TypescriptCodeBuilder\TypescriptFileExpressionInterface; |
| 9 | use Faker\Generator; |
| 10 | |
| 11 | #[FakeMethod('createRandom')] |
| 12 | class ExpressionList extends ItemList |
| 13 | { |
| 14 | public function offsetGet(mixed $offset): TypescriptFileExpressionInterface |
| 15 | { |
| 16 | return parent::offsetGet($offset); |
| 17 | } |
| 18 | |
| 19 | public function toTypescript(): string |
| 20 | { |
| 21 | return implode(', ', array_map( |
| 22 | static fn (TypescriptFileExpressionInterface $expression): string => $expression->toTypescript(), |
| 23 | $this->toArray(), |
| 24 | )); |
| 25 | } |
| 26 | |
| 27 | public function toJavascript(): string |
| 28 | { |
| 29 | return implode(', ', array_map( |
| 30 | static fn (TypescriptFileExpressionInterface $expression): string => $expression->toJavascript(), |
| 31 | $this->toArray(), |
| 32 | )); |
| 33 | } |
| 34 | |
| 35 | public function needsDefinitions(): JavascriptIdentifierList |
| 36 | { |
| 37 | $definitions = new JavascriptIdentifierList(); |
| 38 | foreach ($this as $expression) { |
| 39 | foreach ($expression->needsDefinitions() as $definition) { |
| 40 | $definitions = $definitions->append($definition); |
| 41 | } |
| 42 | } |
| 43 | return $definitions; |
| 44 | } |
| 45 | |
| 46 | public static function createRandom(Generator $faker): self |
| 47 | { |
| 48 | $list = []; |
| 49 | $count = $faker->numberBetween(0, 3); |
| 50 | for ($i = 0; $i < $count; $i++) { |
| 51 | $list[] = $faker->fakeClass($faker->boolean() ? IdentifierExpression::class : StringLiteralExpression::class); |
| 52 | } |
| 53 | return new ExpressionList($list); |
| 54 | } |
| 55 | } |