Skip to content

Commit b23badd

Browse files
committed
minor symfony#59266 [Cache] Update PhpFilesAdapter.php, remove goto statement (ywisax)
This PR was merged into the 7.3 branch. Discussion ---------- [Cache] 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. | Q | A | ------------- | --- | Branch? | 7.3 | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? |no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | License | MIT <!-- Replace this notice by a description of your feature/bugfix. This will help reviewers and should be a good start for the documentation. Additionally (see https://symfony.com/releases): - Always add tests and ensure they pass. - Bug fixes must be submitted against the lowest maintained branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too). - Features and deprecations must be submitted against the latest branch. - For new features, provide some code snippets to help understand usage. - Changelog entry should follow https://symfony.com/doc/current/contributing/code/conventions.html#writing-a-changelog-entry - Never break backward compatibility (see https://symfony.com/bc). --> Commits ------- 01c3ea1 Update PhpFilesAdapter.php, remove goto statement
2 parents ca0912f + 01c3ea1 commit b23badd

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
@@ -103,65 +103,65 @@ protected function doFetch(array $ids): iterable
103103
}
104104
$values = [];
105105

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

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

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

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

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

146-
[$expiresAt, $this->values[$id]] = $expiresAt;
147-
} elseif ($now < $expiresAt) {
148-
$this->values[$id] = new LazyValue($file);
149-
}
150-
151-
if ($now >= $expiresAt) {
152-
unset($this->values[$id], $missingIds[$k], self::$valuesCache[$file]);
151+
if ($now >= $expiresAt) {
152+
unset($this->values[$id], $missingIds[$k], self::$valuesCache[$file]);
153+
}
154+
} catch (\ErrorException $e) {
155+
unset($missingIds[$k]);
153156
}
154-
} catch (\ErrorException $e) {
155-
unset($missingIds[$k]);
156157
}
158+
} finally {
159+
restore_error_handler();
157160
}
158-
} finally {
159-
restore_error_handler();
160-
}
161161

162-
$ids = $missingIds;
163-
$missingIds = [];
164-
goto begin;
162+
$ids = $missingIds;
163+
$missingIds = [];
164+
}
165165
}
166166

167167
protected function doHave(string $id): bool

0 commit comments

Comments
 (0)