From d7165d9f2e0262ccf9856464423dad50ae5ab55b Mon Sep 17 00:00:00 2001 From: francoism90 Date: Sat, 17 Aug 2024 11:06:02 +0200 Subject: [PATCH] Refactor WithSeo trait to improve code readability and maintainability --- src/Views/Concerns/WithSeo.php | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/src/Views/Concerns/WithSeo.php b/src/Views/Concerns/WithSeo.php index a6bb129..72817b1 100644 --- a/src/Views/Concerns/WithSeo.php +++ b/src/Views/Concerns/WithSeo.php @@ -3,29 +3,21 @@ namespace Foxws\WireUse\Views\Concerns; use Artesaos\SEOTools\Facades\SEOMeta; -use Closure; trait WithSeo { public function bootWithSeo(): void { - SEOMeta::setTitle((string) $this->seoValue('getTitle')); - SEOMeta::setDescription((string) $this->seoValue('getDescription')); - SEOMeta::setRobots((string) $this->seoValue('getRobots')); - } - - protected function seoValue(mixed $value, mixed $default = null): mixed - { - if ($value instanceof Closure) { - return value($value); + if (method_exists(static::class, 'getTitle')) { + SEOMeta::setTitle($this->getTitle()); } - if (method_exists(static::class, $value)) { - $value = $this->$value(); - - return is_string($value) ? strip_tags($value) : $value; + if (method_exists(static::class, 'getDescription')) { + SEOMeta::setDescription($this->getDescription()); } - return $default; + if (method_exists(static::class, 'getRobots')) { + SEOMeta::setRobots($this->getRobots()); + } } }