Commit 6b397d00 authored by Guillaume Perréal's avatar Guillaume Perréal

Ne produit plus d'attributs de type "Array" tout seul.

Array doit toujours venir avec un type générique.
parent d19e499b
......@@ -194,7 +194,7 @@ final class ModelGenerator
{
$factory = new TypeFactory();
foreach (['Array', 'Date', 'boolean', 'number', 'null', 'string', 'any', 'never'] as $builtin) {
foreach (['Array', 'Date', 'boolean', 'number', 'null', 'string', 'any', 'never', 'unknown'] as $builtin) {
$factory->add($builtin, BuiltinType::get($builtin));
}
......
......@@ -321,35 +321,37 @@ final class SerializationMapper implements TypeFactoryInterface
return BuiltinType::get('unknown');
}
if (!$type->isCollection()) {
$className = $type->getClassName();
if ($className === null) {
return $this->get($type->getBuiltinType());
}
if ($isLink) {
return $this->createIRI([PHPClass::get($className)]);
}
return $this->get($className);
if ($type->isCollection() || $type->getBuiltinType() === 'array') {
return $this->mapCollection($type, $isLink);
}
$indexType = $type->getCollectionKeyType();
if ($indexType === null && $type->getCollectionValueType() === null && $type->getBuiltinType() === 'array') {
return new ArrayType(BuiltinType::get('unknown'));
$className = $type->getClassName();
if ($className === null) {
return $this->get($type->getBuiltinType());
}
if ($isLink) {
return $this->createIRI([PHPClass::get($className)]);
}
Assertion::notNull($indexType, 'Cannot handle collection with undefined index type');
return $this->get($className);
}
$builtinType = $indexType->getBuiltinType();
if ($builtinType !== 'int') {
throw new \InvalidArgumentException("Cannot handle collection with index type $builtinType");
}
/**
* @param APIType $type
* @param bool $isLink
*
* @return Type
*/
private function mapCollection(?APIType $type, bool $isLink = false): Type
{
$indexType = $type->getCollectionKeyType();
$valueType = $this->mapType($type->getCollectionValueType(), $isLink);
if (!$indexType || $indexType->getBuiltinType() === 'int') {
return new ArrayType($this->mapType($type->getCollectionValueType(), $isLink));
}
return new ArrayType($valueType);
throw new DomainException("Cannot handle collection with non-integer index");
}
/**
* @param ClassName $class
*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment