From 1d1dd16d48a82290f1e9b065fe446de9ced87e31 Mon Sep 17 00:00:00 2001 From: Abdullah Karam Date: Sat, 29 Jul 2023 11:31:29 +0300 Subject: [PATCH] fix --- src/Services/LaravelSvg.php | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/Services/LaravelSvg.php b/src/Services/LaravelSvg.php index 3052e6a..7b69779 100644 --- a/src/Services/LaravelSvg.php +++ b/src/Services/LaravelSvg.php @@ -16,8 +16,8 @@ class LaravelSvg public function __construct( protected array $settings = [], - protected string $firstName = '', - protected string $lastName = '', + protected string $firstWord = '', + protected string $lastWord = '', protected bool $withLogoText = false, protected string $svgTemplate = '', protected int $wordsCount = 0 @@ -35,16 +35,15 @@ protected function getSetting($key): string } - public function svgFor(string $userFullName): self + public function svgFor(string $words): self { - $this->setCountWords($userFullName); - dd($this->wordsCount); + $this->setCountWords($words); if ($this->wordsCount < self::MENIMUM_WORDS_COUNT) { - throw new \InvalidArgumentException('User full name must be at least 2 words'); + throw new \InvalidArgumentException('Invalid words count passed to svgFor method'); } - $this->firstName = strtoupper(Str::before($userFullName, ' ')); - $this->lastName = strtoupper(Str::after($userFullName, ' ')); + $this->firstWord = strtoupper(Str::before($words, ' ')); + $this->lastWord = strtoupper(Str::after($words, ' ')); return $this; } @@ -92,7 +91,7 @@ protected function saveSvg(): array if ($this->getSetting('hash_svg_name')) { $svgName = uniqid() . '.svg'; } else { - $svgName = $this->firstName . '-' . $this->lastName . '.svg'; + $svgName = $this->firstWord . '-' . $this->lastWord . '.svg'; } Storage::disk($disk)->put($svgPath . '/' . $svgName, $this->svgTemplate); return [ @@ -153,8 +152,8 @@ private function replaceSvgTemplate(): void [ $this->getSetting('avatar_text_color'), $this->getSetting('avatar_background_color'), - $this->firstName[0], - $this->lastName[0], + $this->firstWord[0], + $this->lastWord[0], ($this->withLogoText ? $this->logoText : ''), ($this->withLogoText ? $this->getSetting('logo_text_color') : ''), ],