Skip to content

Commit cf8df28

Browse files
Use ??= more
1 parent f22044d commit cf8df28

File tree

2 files changed

+5
-23
lines changed

2 files changed

+5
-23
lines changed

Mapping/Loader/XmlFileLoader.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,7 @@ class XmlFileLoader extends FileLoader
3535

3636
public function loadClassMetadata(ClassMetadataInterface $classMetadata): bool
3737
{
38-
if (null === $this->classes) {
39-
$this->classes = $this->getClassesFromXml();
40-
}
41-
42-
if (!$this->classes) {
38+
if (!$this->classes ??= $this->getClassesFromXml()) {
4339
return false;
4440
}
4541

@@ -128,11 +124,7 @@ public function loadClassMetadata(ClassMetadataInterface $classMetadata): bool
128124
*/
129125
public function getMappedClasses(): array
130126
{
131-
if (null === $this->classes) {
132-
$this->classes = $this->getClassesFromXml();
133-
}
134-
135-
return array_keys($this->classes);
127+
return array_keys($this->classes ??= $this->getClassesFromXml());
136128
}
137129

138130
/**

Mapping/Loader/YamlFileLoader.php

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,7 @@ class YamlFileLoader extends FileLoader
3838

3939
public function loadClassMetadata(ClassMetadataInterface $classMetadata): bool
4040
{
41-
if (null === $this->classes) {
42-
$this->classes = $this->getClassesFromYaml();
43-
}
44-
45-
if (!$this->classes) {
41+
if (!$this->classes ??= $this->getClassesFromYaml()) {
4642
return false;
4743
}
4844

@@ -153,11 +149,7 @@ public function loadClassMetadata(ClassMetadataInterface $classMetadata): bool
153149
*/
154150
public function getMappedClasses(): array
155151
{
156-
if (null === $this->classes) {
157-
$this->classes = $this->getClassesFromYaml();
158-
}
159-
160-
return array_keys($this->classes);
152+
return array_keys($this->classes ??= $this->getClassesFromYaml());
161153
}
162154

163155
private function getClassesFromYaml(): array
@@ -166,9 +158,7 @@ private function getClassesFromYaml(): array
166158
throw new MappingException(sprintf('This is not a local file "%s".', $this->file));
167159
}
168160

169-
if (null === $this->yamlParser) {
170-
$this->yamlParser = new Parser();
171-
}
161+
$this->yamlParser ??= new Parser();
172162

173163
$classes = $this->yamlParser->parseFile($this->file, Yaml::PARSE_CONSTANT);
174164

0 commit comments

Comments
 (0)