Skip to content

Commit d2f4e82

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

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

Mapping/Loader/YamlFileLoader.php

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -45,48 +45,48 @@ public function loadClassMetadata(ClassMetadataInterface $classMetadata)
4545
return false;
4646
}
4747

48-
if (isset($this->classes[$classMetadata->getName()])) {
49-
$yaml = $this->classes[$classMetadata->getName()];
50-
51-
if (isset($yaml['attributes']) && is_array($yaml['attributes'])) {
52-
$attributesMetadata = $classMetadata->getAttributesMetadata();
53-
54-
foreach ($yaml['attributes'] as $attribute => $data) {
55-
if (isset($attributesMetadata[$attribute])) {
56-
$attributeMetadata = $attributesMetadata[$attribute];
57-
} else {
58-
$attributeMetadata = new AttributeMetadata($attribute);
59-
$classMetadata->addAttributeMetadata($attributeMetadata);
60-
}
48+
if (!isset($this->classes[$classMetadata->getName()])) {
49+
return false;
50+
}
6151

62-
if (isset($data['groups'])) {
63-
if (!is_array($data['groups'])) {
64-
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());
65-
}
52+
$yaml = $this->classes[$classMetadata->getName()];
53+
54+
if (isset($yaml['attributes']) && is_array($yaml['attributes'])) {
55+
$attributesMetadata = $classMetadata->getAttributesMetadata();
6656

67-
foreach ($data['groups'] as $group) {
68-
if (!is_string($group)) {
69-
throw new MappingException('Group names must be strings in "%s" for the attribute "%s" of the class "%s".', $this->file, $attribute, $classMetadata->getName());
70-
}
57+
foreach ($yaml['attributes'] as $attribute => $data) {
58+
if (isset($attributesMetadata[$attribute])) {
59+
$attributeMetadata = $attributesMetadata[$attribute];
60+
} else {
61+
$attributeMetadata = new AttributeMetadata($attribute);
62+
$classMetadata->addAttributeMetadata($attributeMetadata);
63+
}
64+
65+
if (isset($data['groups'])) {
66+
if (!is_array($data['groups'])) {
67+
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()));
68+
}
7169

72-
$attributeMetadata->addGroup($group);
70+
foreach ($data['groups'] as $group) {
71+
if (!is_string($group)) {
72+
throw new MappingException(sprintf('Group names must be strings in "%s" for the attribute "%s" of the class "%s".', $this->file, $attribute, $classMetadata->getName()));
7373
}
74+
75+
$attributeMetadata->addGroup($group);
7476
}
7577

7678
if (isset($data['max_depth'])) {
7779
if (!is_int($data['max_depth'])) {
78-
throw new MappingException('The "max_depth" value must be an integer in "%s" for the attribute "%s" of the class "%s".', $this->file, $attribute, $classMetadata->getName());
80+
throw new MappingException(sprintf('The "max_depth" value must be an integer in "%s" for the attribute "%s" of the class "%s".', $this->file, $attribute, $classMetadata->getName()));
7981
}
8082

8183
$attributeMetadata->setMaxDepth($data['max_depth']);
8284
}
8385
}
8486
}
85-
86-
return true;
8787
}
8888

89-
return false;
89+
return true;
9090
}
9191

9292
/**

0 commit comments

Comments
 (0)