mirror of
https://github.com/danog/Valinor.git
synced 2024-12-03 10:07:48 +01:00
b6b3296638
Using variadic parameters is now handled properly by the library, meaning the following example will run: ```php final class SomeClass { /** @var string[] */ private array $values; public function __construct(string ...$values) { $this->values = $values; } } (new \CuyZ\Valinor\MapperBuilder()) ->mapper() ->map(SomeClass::class, ['foo', 'bar', 'baz']); ```
50 lines
1.3 KiB
PHP
50 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace CuyZ\Valinor\Tests\Fake\Definition;
|
|
|
|
use CuyZ\Valinor\Definition\ParameterDefinition;
|
|
use CuyZ\Valinor\Tests\Fake\Type\FakeType;
|
|
use CuyZ\Valinor\Type\Type;
|
|
use ReflectionParameter;
|
|
|
|
final class FakeParameterDefinition
|
|
{
|
|
private function __construct()
|
|
{
|
|
}
|
|
|
|
public static function new(string $name = 'someParameter', Type $type = null): ParameterDefinition
|
|
{
|
|
return new ParameterDefinition(
|
|
$name,
|
|
$name,
|
|
$type ?? new FakeType(),
|
|
false,
|
|
false,
|
|
null,
|
|
new FakeAttributes()
|
|
);
|
|
}
|
|
|
|
public static function fromReflection(ReflectionParameter $reflection): ParameterDefinition
|
|
{
|
|
$type = new FakeType();
|
|
|
|
if ($reflection->hasType()) {
|
|
$type = FakeType::from($reflection->getType()->getName()); // @phpstan-ignore-line
|
|
}
|
|
|
|
return new ParameterDefinition(
|
|
$reflection->name,
|
|
'Signature::' . $reflection->name,
|
|
$type,
|
|
$reflection->isOptional(),
|
|
$reflection->isVariadic(),
|
|
$reflection->isDefaultValueAvailable() ? $reflection->getDefaultValue() : null,
|
|
new FakeAttributes()
|
|
);
|
|
}
|
|
}
|