Skip to content

Commit 24ce75c

Browse files
Merge branch '2.7' into 2.8
* 2.7: [2.7] Fix issues reported by static analyse [Serializer] Reduce nesting in YamlFileLoader
2 parents 38b3c0f + 979adb9 commit 24ce75c

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

Mapping/Loader/YamlFileLoader.php

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -60,39 +60,39 @@ public function loadClassMetadata(ClassMetadataInterface $classMetadata)
6060
$this->classes = $classes;
6161
}
6262

63-
if (isset($this->classes[$classMetadata->getName()])) {
64-
$yaml = $this->classes[$classMetadata->getName()];
65-
66-
if (isset($yaml['attributes']) && is_array($yaml['attributes'])) {
67-
$attributesMetadata = $classMetadata->getAttributesMetadata();
68-
69-
foreach ($yaml['attributes'] as $attribute => $data) {
70-
if (isset($attributesMetadata[$attribute])) {
71-
$attributeMetadata = $attributesMetadata[$attribute];
72-
} else {
73-
$attributeMetadata = new AttributeMetadata($attribute);
74-
$classMetadata->addAttributeMetadata($attributeMetadata);
75-
}
63+
if (!isset($this->classes[$classMetadata->getName()])) {
64+
return false;
65+
}
7666

77-
if (isset($data['groups'])) {
78-
if (!is_array($data['groups'])) {
79-
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());
80-
}
67+
$yaml = $this->classes[$classMetadata->getName()];
8168

82-
foreach ($data['groups'] as $group) {
83-
if (!is_string($group)) {
84-
throw new MappingException('Group names must be strings in "%s" for the attribute "%s" of the class "%s".', $this->file, $attribute, $classMetadata->getName());
85-
}
69+
if (isset($yaml['attributes']) && is_array($yaml['attributes'])) {
70+
$attributesMetadata = $classMetadata->getAttributesMetadata();
71+
72+
foreach ($yaml['attributes'] as $attribute => $data) {
73+
if (isset($attributesMetadata[$attribute])) {
74+
$attributeMetadata = $attributesMetadata[$attribute];
75+
} else {
76+
$attributeMetadata = new AttributeMetadata($attribute);
77+
$classMetadata->addAttributeMetadata($attributeMetadata);
78+
}
8679

87-
$attributeMetadata->addGroup($group);
80+
if (isset($data['groups'])) {
81+
if (!is_array($data['groups'])) {
82+
throw new MappingException(sprintf('The "groups" key must be an array of strings in "%s" for the attribute "%s" of the class "%s".', $this->file, $attribute, $classMetadata->getName()));
83+
}
84+
85+
foreach ($data['groups'] as $group) {
86+
if (!is_string($group)) {
87+
throw new MappingException(sprintf('Group names must be strings in "%s" for the attribute "%s" of the class "%s".', $this->file, $attribute, $classMetadata->getName()));
8888
}
89+
90+
$attributeMetadata->addGroup($group);
8991
}
9092
}
9193
}
92-
93-
return true;
9494
}
9595

96-
return false;
96+
return true;
9797
}
9898
}

0 commit comments

Comments
 (0)