Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdullahKaram-Dev committed Jul 29, 2023
1 parent cebfe52 commit 1d1dd16
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/Services/LaravelSvg.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
Expand Down Expand Up @@ -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 [
Expand Down Expand Up @@ -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') : ''),
],
Expand Down

0 comments on commit 1d1dd16

Please sign in to comment.