Skip to content

Commit 01c3ea1

Browse files
authored
Update PhpFilesAdapter.php, remove goto statement
The goto statement can make the code's flow difficult to follow. PHP code is typically expected to have a more linear and understandable structure. For example, when using goto, it can jump from one part of the code to another in a non - sequential manner. This can lead to confusion for developers who are trying to understand the program's logic, especially in larger codebases.
1 parent be52235 commit 01c3ea1

File tree

1 file changed

+47
-47
lines changed

1 file changed

+47
-47
lines changed

src/Symfony/Component/Cache/Adapter/PhpFilesAdapter.php

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -104,65 +104,65 @@ protected function doFetch(array $ids): iterable
104104
}
105105
$values = [];
106106

107-
begin:
108-
$getExpiry = false;
109-
110-
foreach ($ids as $id) {
111-
if (null === $value = $this->values[$id] ?? null) {
112-
$missingIds[] = $id;
113-
} elseif ('N;' === $value) {
114-
$values[$id] = null;
115-
} elseif (!\is_object($value)) {
116-
$values[$id] = $value;
117-
} elseif (!$value instanceof LazyValue) {
118-
$values[$id] = $value();
119-
} elseif (false === $values[$id] = include $value->file) {
120-
unset($values[$id], $this->values[$id]);
121-
$missingIds[] = $id;
107+
while (true) {
108+
$getExpiry = false;
109+
110+
foreach ($ids as $id) {
111+
if (null === $value = $this->values[$id] ?? null) {
112+
$missingIds[] = $id;
113+
} elseif ('N;' === $value) {
114+
$values[$id] = null;
115+
} elseif (!\is_object($value)) {
116+
$values[$id] = $value;
117+
} elseif (!$value instanceof LazyValue) {
118+
$values[$id] = $value();
119+
} elseif (false === $values[$id] = include $value->file) {
120+
unset($values[$id], $this->values[$id]);
121+
$missingIds[] = $id;
122+
}
123+
if (!$this->appendOnly) {
124+
unset($this->values[$id]);
125+
}
122126
}
123-
if (!$this->appendOnly) {
124-
unset($this->values[$id]);
127+
128+
if (!$missingIds) {
129+
return $values;
125130
}
126-
}
127131

128-
if (!$missingIds) {
129-
return $values;
130-
}
132+
set_error_handler($this->includeHandler);
133+
try {
134+
$getExpiry = true;
131135

132-
set_error_handler($this->includeHandler);
133-
try {
134-
$getExpiry = true;
136+
foreach ($missingIds as $k => $id) {
137+
try {
138+
$file = $this->files[$id] ??= $this->getFile($id);
135139

136-
foreach ($missingIds as $k => $id) {
137-
try {
138-
$file = $this->files[$id] ??= $this->getFile($id);
140+
if (isset(self::$valuesCache[$file])) {
141+
[$expiresAt, $this->values[$id]] = self::$valuesCache[$file];
142+
} elseif (\is_array($expiresAt = include $file)) {
143+
if ($this->appendOnly) {
144+
self::$valuesCache[$file] = $expiresAt;
145+
}
139146

140-
if (isset(self::$valuesCache[$file])) {
141-
[$expiresAt, $this->values[$id]] = self::$valuesCache[$file];
142-
} elseif (\is_array($expiresAt = include $file)) {
143-
if ($this->appendOnly) {
144-
self::$valuesCache[$file] = $expiresAt;
147+
[$expiresAt, $this->values[$id]] = $expiresAt;
148+
} elseif ($now < $expiresAt) {
149+
$this->values[$id] = new LazyValue($file);
145150
}
146151

147-
[$expiresAt, $this->values[$id]] = $expiresAt;
148-
} elseif ($now < $expiresAt) {
149-
$this->values[$id] = new LazyValue($file);
150-
}
151-
152-
if ($now >= $expiresAt) {
153-
unset($this->values[$id], $missingIds[$k], self::$valuesCache[$file]);
152+
if ($now >= $expiresAt) {
153+
unset($this->values[$id], $missingIds[$k], self::$valuesCache[$file]);
154+
}
155+
} catch (\ErrorException $e) {
156+
unset($missingIds[$k]);
154157
}
155-
} catch (\ErrorException $e) {
156-
unset($missingIds[$k]);
157158
}
159+
} finally {
160+
restore_error_handler();
158161
}
159-
} finally {
160-
restore_error_handler();
161-
}
162162

163-
$ids = $missingIds;
164-
$missingIds = [];
165-
goto begin;
163+
$ids = $missingIds;
164+
$missingIds = [];
165+
}
166166
}
167167

168168
protected function doHave(string $id): bool

0 commit comments

Comments
 (0)