Lines 100.00% 6 / 6
Functions and Methods 100.00% 3 / 3
Classes and Traits 100.00% 1 / 1
Name Lines Functions and Methods CRAP Classes and Traits
NamedArguments 100.00% 6 / 6 100.00% 3 / 3 3 100.00% 1 / 1
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 withArgument 100.00% 1 / 1 100.00% 1 / 1 1
 toBoundArguments 100.00% 4 / 4 100.00% 1 / 1 1
1<?php
2
3declare(strict_types=1);
4
5namespace Stewart\Runtime\Kernel;
6
7use Symfony\Component\DependencyInjection\Argument\BoundArgument;
8
9final readonly class NamedArguments
10{
11    /** @param array<string, mixed> $values */
12    public function __construct(private array $values = []) {}
13
14    public function withArgument(string $name, mixed $value): self
15    {
16        return new self([...$this->values, '$' . $name => $value]);
17    }
18
19    // Tracked, so compiling fails when no service takes a bound name, e.g. after a parameter rename.
20    /** @return array<string, BoundArgument> */
21    public function toBoundArguments(): array
22    {
23        return array_map(
24            static fn(mixed $value): BoundArgument => new BoundArgument($value, true),
25            $this->values,
26        );
27    }
28}