Skip to content

Commit deab30a

Browse files
committed
Refactor TemplateEngine::getSharedTemplateGroupID() to use array_find() and add error handling
1 parent 31f1830 commit deab30a

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

wcfsetup/install/files/lib/system/template/TemplateEngine.class.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,16 +1044,17 @@ protected function getCompileFilePrefix(string $templateName): string
10441044

10451045
private function getSharedTemplateGroupID(): int
10461046
{
1047-
if (!isset($this->sharedTemplateGroupID)) {
1048-
/** @var TemplateGroup $templateGroup */
1049-
foreach (TemplateGroupCacheBuilder::getInstance()->getData() as $templateGroup) {
1050-
if ($templateGroup->templateGroupFolderName === '_wcf_shared/') {
1051-
$this->sharedTemplateGroupID = $templateGroup->templateGroupID;
1052-
break;
1053-
}
1054-
}
1047+
$templateGroup = \array_find(
1048+
TemplateGroupCacheBuilder::getInstance()->getData(),
1049+
static fn (TemplateGroup $group) => $group->templateGroupFolderName === '_wcf_shared/'
1050+
);
1051+
1052+
if ($templateGroup === null) {
1053+
throw new \RuntimeException('Shared template group not found');
10551054
}
10561055

1056+
$this->sharedTemplateGroupID = $templateGroup->templateGroupID;
1057+
10571058
return $this->sharedTemplateGroupID;
10581059
}
10591060
}

0 commit comments

Comments
 (0)