You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
minor #21754 [Serializer] Reduce nesting in YamlFileLoader (gadelat)
This PR was merged into the 2.7 branch.
Discussion
----------
[Serializer] Reduce nesting in YamlFileLoader
| Q | A
| ------------- | ---
| Branch? | 2.7
| Bug fix? | no
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | -
We don't need to check if $this->classes is empty, because isset takes care of it in next call anyway
Diffs on GH are hard to read for this type of change, here is old and new code:
```php
public function loadClassMetadata(ClassMetadataInterface $classMetadata)
{
if (null === $this->classes) {
$this->classes = $this->getClassesFromYaml();
}
if (!$this->classes) {
return false;
}
if (isset($this->classes[$classMetadata->getName()])) {
$yaml = $this->classes[$classMetadata->getName()];
if (isset($yaml['attributes']) && is_array($yaml['attributes'])) {
...
}
return true;
}
return false;
}
```
```php
public function loadClassMetadata(ClassMetadataInterface $classMetadata)
{
if (null === $this->classes) {
$this->classes = $this->getClassesFromYaml();
}
if (!isset($this->classes[$classMetadata->getName()])) {
return false;
}
$yaml = $this->classes[$classMetadata->getName()];
if (isset($yaml['attributes']) && is_array($yaml['attributes'])) {
...
}
return true;
}
```
Commits
-------
45f0b16 [Serializer] Reduce nesting in YamlFileLoader
if (!isset($this->classes[$classMetadata->getName()])) {
64
+
returnfalse;
65
+
}
76
66
77
-
if (isset($data['groups'])) {
78
-
if (!is_array($data['groups'])) {
79
-
thrownewMappingException('The "groups" key must be an array of strings in "%s" for the attribute "%s" of the class "%s".', $this->file, $attribute, $classMetadata->getName());
thrownewMappingException('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'])) {
thrownewMappingException('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
+
thrownewMappingException('Group names must be strings in "%s" for the attribute "%s" of the class "%s".', $this->file, $attribute, $classMetadata->getName());
0 commit comments