ArrayExpression::getType()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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\ListArgumentResolver;
8
use JetBrains\PhpStorm\ArrayShape;
9
10
class ArrayExpression extends ASTNode
11
{
12
    /**
13
     * @param ASTNode[] $values
14
     */
15 3
    public function __construct(
16
        private array $values
17
    )
18
    {
19 3
    }
20
21 3
    public function getType(): string
22
    {
23 3
        return 'ArrayExpression';
24
    }
25
26
    /**
27
     * @return ASTNode[]
28
     */
29 3
    public function getValues(): array
30
    {
31 3
        return $this->values;
32
    }
33
34 3
    #[ArrayShape(['type' => "string", 'values' => "array"])]
35
    public function toArray(): array
36
    {
37 3
        $values = [];
38 3
        foreach ($this->getValues() as $value) {
39 3
            $values[] = $value->toArray();
40
        }
41
42
        return [
43 3
            'type'   => $this->getType(),
44 3
            'values' => $values,
45
        ];
46
    }
47
48
    public function toResolver(ArgumentResolverFactory $argumentResolverFactory): ArgumentResolver
49
    {
50
        $result = [];
51
52
        foreach ($this->values as $value) {
53
            $result[] = $value->toResolver($argumentResolverFactory);
54
        }
55
56
        return new ListArgumentResolver($result);
57
    }
58
}
59