Expression   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 52
ccs 0
cts 19
cp 0
rs 10
c 0
b 0
f 0
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 11 2
A getType() 0 3 1
A getBody() 0 3 1
A __construct() 0 4 1
A toResolver() 0 13 3
1
<?php declare(strict_types=1);
2
3
namespace Diezz\YamlToObjectMapper\Resolver\Parser\AST;
4
5
use Diezz\YamlToObjectMapper\Resolver\ArgumentResolver;
6
use Diezz\YamlToObjectMapper\Resolver\ArgumentResolverFactory;
7
use Diezz\YamlToObjectMapper\Resolver\ConcatArgumentResolver;
8
use JetBrains\PhpStorm\ArrayShape;
9
10
class Expression extends ASTNode
11
{
12
13
    /**
14
     * @param ASTNode[] $body
15
     */
16
    public function __construct(
17
        private array $body
18
    )
19
    {
20
    }
21
22
    public function getType(): string
23
    {
24
        return 'Expression';
25
    }
26
27
    /**
28
     * @return ASTNode[]
29
     */
30
    public function getBody(): array
31
    {
32
        return $this->body;
33
    }
34
35
    #[ArrayShape(['type' => "string", 'body' => "array"])]
36
    public function toArray(): array
37
    {
38
        $body = [];
39
        foreach ($this->body as $value) {
40
            $body[] = $value->toArray();
41
        }
42
43
        return [
44
            'type' => $this->getType(),
45
            'body' => $body,
46
        ];
47
    }
48
49
    public function toResolver(ArgumentResolverFactory $argumentResolverFactory): ArgumentResolver
50
    {
51
        if (count($this->body) === 1) {
52
            return $this->body[0]->toResolver($argumentResolverFactory);
53
        }
54
55
        $arguments = [];
56
57
        foreach ($this->body as $node) {
58
            $arguments[] = $node->toResolver($argumentResolverFactory);
59
        }
60
61
        return new ConcatArgumentResolver($arguments);
62
    }
63
}
64