[Serializer] Reduce nesting in YamlFileLoader

This commit is contained in:
Gabriel Ostrolucký 2017-02-24 23:07:14 +01:00 committed by Gabriel Ostrolucký
parent 00c61da3c6
commit 45f0b16b78

View File

@ -60,39 +60,39 @@ class YamlFileLoader extends FileLoader
$this->classes = $classes; $this->classes = $classes;
} }
if (isset($this->classes[$classMetadata->getName()])) { if (!isset($this->classes[$classMetadata->getName()])) {
$yaml = $this->classes[$classMetadata->getName()]; return false;
}
if (isset($yaml['attributes']) && is_array($yaml['attributes'])) { $yaml = $this->classes[$classMetadata->getName()];
$attributesMetadata = $classMetadata->getAttributesMetadata();
foreach ($yaml['attributes'] as $attribute => $data) { if (isset($yaml['attributes']) && is_array($yaml['attributes'])) {
if (isset($attributesMetadata[$attribute])) { $attributesMetadata = $classMetadata->getAttributesMetadata();
$attributeMetadata = $attributesMetadata[$attribute];
} else { foreach ($yaml['attributes'] as $attribute => $data) {
$attributeMetadata = new AttributeMetadata($attribute); if (isset($attributesMetadata[$attribute])) {
$classMetadata->addAttributeMetadata($attributeMetadata); $attributeMetadata = $attributesMetadata[$attribute];
} else {
$attributeMetadata = new AttributeMetadata($attribute);
$classMetadata->addAttributeMetadata($attributeMetadata);
}
if (isset($data['groups'])) {
if (!is_array($data['groups'])) {
throw new MappingException('The "groups" key must be an array of strings in "%s" for the attribute "%s" of the class "%s".', $this->file, $attribute, $classMetadata->getName());
} }
if (isset($data['groups'])) { foreach ($data['groups'] as $group) {
if (!is_array($data['groups'])) { if (!is_string($group)) {
throw new MappingException('The "groups" key must be an array of strings in "%s" for the attribute "%s" of the class "%s".', $this->file, $attribute, $classMetadata->getName()); throw new MappingException('Group names must be strings in "%s" for the attribute "%s" of the class "%s".', $this->file, $attribute, $classMetadata->getName());
} }
foreach ($data['groups'] as $group) { $attributeMetadata->addGroup($group);
if (!is_string($group)) {
throw new MappingException('Group names must be strings in "%s" for the attribute "%s" of the class "%s".', $this->file, $attribute, $classMetadata->getName());
}
$attributeMetadata->addGroup($group);
}
} }
} }
} }
return true;
} }
return false; return true;
} }
} }