Skip to content

Commit

Permalink
Replace if blocks with single match expression
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Oct 28, 2023
1 parent b561877 commit 26b727f
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions packages/framework/src/Framework/Features/Metadata/MetadataBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,12 @@ public function get(): array

public function add(MetadataElementContract|string $element): static
{
if ($element instanceof LinkElement) {
return $this->addElement('links', $element);
}

if ($element instanceof MetadataElement) {
return $this->addElement('metadata', $element);
}

if ($element instanceof OpenGraphElement) {
return $this->addElement('properties', $element);
}

return $this->addGenericElement((string) $element);
return match (true) {
$element instanceof LinkElement => $this->addElement('links', $element),
$element instanceof MetadataElement => $this->addElement('metadata', $element),
$element instanceof OpenGraphElement => $this->addElement('properties', $element),
default => $this->addGenericElement((string) $element),
};
}

protected function addElement(string $type, MetadataElementContract $element): static
Expand Down

0 comments on commit 26b727f

Please sign in to comment.