diff --git a/src/Metadata/RepresentationMetadata.php b/src/Metadata/RepresentationMetadata.php index 72fdbee2cf65b4926e3bcc6db29e050728bfa0ef..e13877a4e52ffe224786feb8c2d05b2847d31d24 100644 --- a/src/Metadata/RepresentationMetadata.php +++ b/src/Metadata/RepresentationMetadata.php @@ -19,6 +19,7 @@ namespace Irstea\NgModelGeneratorBundle\Metadata; +use Irstea\NgModelGeneratorBundle\Exceptions\DomainException; use Irstea\NgModelGeneratorBundle\Models\ClassName; use Irstea\NgModelGeneratorBundle\Models\HasName; @@ -62,6 +63,10 @@ final class RepresentationMetadata implements ClassName, HasName */ public function __construct(string $name, ClassName $class, ?ClassName $parent, array $properties, bool $abstract) { + if ($parent && $class->getFullName() === $parent->getFullName()) { + throw new DomainException("$class cannot be its own parent"); + } + $this->class = $class; $this->parent = $parent; diff --git a/src/Models/PHPClass.php b/src/Models/PHPClass.php index e6ff765c10b85d4a92889c1b97ac97b39e93ac13..69fbee81806d28435a9a90bc3074bdd4896e457c 100644 --- a/src/Models/PHPClass.php +++ b/src/Models/PHPClass.php @@ -100,14 +100,18 @@ final class PHPClass implements ClassName } /** - * @param ClassName|string $name + * @param ClassName|\ReflectionClass|string $name * * @return ClassName */ public static function get($name): ClassName { if ($name instanceof ClassName) { - return $name; + $name = $name->getFullName(); + } elseif ($name instanceof \ReflectionClass) { + $name = $name->getName(); + } elseif (!\is_string($name)) { + throw new InvalidArgumentException(__METHOD__ . " argument should be a string, ClassName or ReflectionClass, not $name"); } static $instances = []; diff --git a/src/SerializationMapper.php b/src/SerializationMapper.php index d2b0fc0e7005d903ed46b4c88cec679ab0bfa7b1..a699c31b7702ed5175e7de9a7fa687c9ad115ebf 100644 --- a/src/SerializationMapper.php +++ b/src/SerializationMapper.php @@ -160,6 +160,10 @@ final class SerializationMapper implements TypeFactoryInterface { $classInfo = $this->getClassInfo($repr); + if ($classInfo->isUndefined()) { + throw new DomainException(sprintf('%s has not been rearranged', $repr)); + } + if ($classInfo->isUnion()) { $types = []; foreach ($classInfo->iterateInterfaceDescendants() as $child) { @@ -180,10 +184,6 @@ final class SerializationMapper implements TypeFactoryInterface return new IRI([$repr]); } - if (!$classInfo->isInterface()) { - throw new DomainException(sprintf('Cannot map %s', $repr)); - } - $parent = null; $parentInfo = $classInfo->getParent(); if ($parentInfo !== null && $parentInfo->isInterface()) {