Skip to content

Commit

Permalink
Customer: Fix algorithm for duplicare firstName and lastName.
Browse files Browse the repository at this point in the history
  • Loading branch information
janbarasek committed Feb 24, 2022
1 parent 84f9aec commit 568eb49
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/Entity/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,7 @@ public function getFirstName(): string

public function setFirstName(string $firstName): void
{
if (trim($firstName) === '') {
throw new \InvalidArgumentException('First name can not be empty.');
}
$this->firstName = $this->formatName($firstName);
$this->setName($firstName, $this->lastName);
}


Expand All @@ -166,10 +163,7 @@ public function getLastName(): string

public function setLastName(string $lastName): void
{
if (trim($lastName) === '') {
throw new \InvalidArgumentException('Last name can not be empty.');
}
$this->lastName = $this->formatName($lastName);
$this->setName($this->firstName, $lastName);
}


Expand Down Expand Up @@ -410,8 +404,15 @@ private function setName(string $firstName, string $lastName): void
if ($firstName === $lastName && isset($parts[0], $parts[1])) {
[$firstName, $lastName] = $parts;
}
$this->setFirstName($firstName);
$this->setLastName($lastName);
$validator = static function(string $name): void {
if (trim($name) === '') {
throw new \InvalidArgumentException('Name can not be empty.');
}
};
$validator($firstName);
$validator($lastName);
$this->firstName = $this->formatName($firstName);
$this->lastName = $this->formatName($lastName);
}


Expand Down

0 comments on commit 568eb49

Please sign in to comment.