Skip to content

Commit 5b277bc

Browse files
committed
Apply suggestions from code review
1 parent cfdb912 commit 5b277bc

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

wcfsetup/install/files/lib/system/view/component/ContentInteractionTabsComponent.class.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,25 @@
1414
*/
1515
final class ContentInteractionTabsComponent
1616
{
17+
/**
18+
* @var list<ContentInteractionTab>
19+
*/
1720
private array $tabs = [];
1821

1922
public function addTab(string $title, string $link, bool $active = false): void
2023
{
24+
if ($active && $this->getActiveTab() !== null) {
25+
throw new \BadMethodCallException("The tab '{$this->getActiveTab()->link}' is already marked as active");
26+
}
27+
2128
$this->tabs[] = new ContentInteractionTab($title, $link, $active);
2229
}
2330

31+
private function getActiveTab(): ?ContentInteractionTab
32+
{
33+
return \array_find($this->tabs, static fn($tab) => $tab->active);
34+
}
35+
2436
public function render(): string
2537
{
2638
if (!$this->tabs === []) {
@@ -43,6 +55,6 @@ final class ContentInteractionTab
4355
public function __construct(
4456
public readonly string $title,
4557
public readonly string $link,
46-
public readonly bool $active = false,
58+
public readonly bool $active,
4759
) {}
4860
}

0 commit comments

Comments
 (0)