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

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,7 +321,10 @@ final class SerializationMapper implements TypeFactoryInterface
return BuiltinType::get('unknown');
}
if (!$type->isCollection()) {
if ($type->isCollection() || $type->getBuiltinType() === 'array') {
return $this->mapCollection($type, $isLink);
}
$className = $type->getClassName();
if ($className === null) {
return $this->get($type->getBuiltinType());
......@@ -333,23 +336,22 @@ final class SerializationMapper implements TypeFactoryInterface
return $this->get($className);
}
/**
* @param APIType $type
* @param bool $isLink
*
* @return Type
*/
private function mapCollection(?APIType $type, bool $isLink = false): Type
{
$indexType = $type->getCollectionKeyType();
if ($indexType === null && $type->getCollectionValueType() === null && $type->getBuiltinType() === 'array') {
return new ArrayType(BuiltinType::get('unknown'));
}
Assertion::notNull($indexType, 'Cannot handle collection with undefined index type');
$builtinType = $indexType->getBuiltinType();
if ($builtinType !== 'int') {
throw new \InvalidArgumentException("Cannot handle collection with index type $builtinType");
if (!$indexType || $indexType->getBuiltinType() === 'int') {
return new ArrayType($this->mapType($type->getCollectionValueType(), $isLink));
}
$valueType = $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