Valinor/tests/Fake/Definition/FakeClassDefinition.php
Romain Canon 396f64a524 feat: initial release
🎉
2021-11-28 18:21:56 +01:00

61 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
namespace CuyZ\Valinor\Tests\Fake\Definition;
use CuyZ\Valinor\Definition\ClassDefinition;
use CuyZ\Valinor\Definition\Methods;
use CuyZ\Valinor\Definition\Properties;
use ReflectionClass;
use ReflectionMethod;
use ReflectionProperty;
use stdClass;
use function array_map;
final class FakeClassDefinition
{
private function __construct()
{
}
/**
* @param class-string $name
*/
public static function new(string $name = stdClass::class): ClassDefinition
{
return new ClassDefinition(
$name,
$name,
new FakeAttributes(),
new Properties(),
new Methods()
);
}
/**
* @param ReflectionClass<object> $reflection
*/
public static function fromReflection(ReflectionClass $reflection): ClassDefinition
{
$properties = array_map(
static fn (ReflectionProperty $reflection) => FakePropertyDefinition::fromReflection($reflection),
$reflection->getProperties()
);
$methods = array_map(
static fn (ReflectionMethod $reflection) => FakeMethodDefinition::fromReflection($reflection),
$reflection->getMethods()
);
return new ClassDefinition(
$reflection->name,
'Signature::' . $reflection->name,
new FakeAttributes(),
new Properties(...$properties),
new Methods(...$methods)
);
}
}