From 7556077754dfcceefaf8d848fdd36188d6932aa4 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 17 Jul 2024 18:58:34 +0200 Subject: [PATCH] Refactor to inline the add element method --- .../src/Framework/Features/Metadata/MetadataBag.php | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/packages/framework/src/Framework/Features/Metadata/MetadataBag.php b/packages/framework/src/Framework/Features/Metadata/MetadataBag.php index 346fd8a4357..51e55491691 100644 --- a/packages/framework/src/Framework/Features/Metadata/MetadataBag.php +++ b/packages/framework/src/Framework/Features/Metadata/MetadataBag.php @@ -55,21 +55,15 @@ public function get(): array public function add(MetadataElementContract|string $element): static { match (true) { - $element instanceof LinkElement => $this->addElement('links', $element), - $element instanceof MetadataElement => $this->addElement('metadata', $element), - $element instanceof OpenGraphElement => $this->addElement('properties', $element), + $element instanceof LinkElement => $this->links[$element->uniqueKey()] = $element, + $element instanceof MetadataElement => $this->metadata[$element->uniqueKey()] = $element, + $element instanceof OpenGraphElement => $this->properties[$element->uniqueKey()] = $element, default => $this->addGenericElement((string) $element), }; return $this; } - /** @param 'links'|'metadata'|'properties' $type */ - protected function addElement(string $type, MetadataElementContract $element): void - { - $this->{$type}[$element->uniqueKey()] = $element; - } - protected function addGenericElement(string $element): void { $this->generics[] = $element;