Skip to content

Commit

Permalink
fix(hw19): Добавил проверку на валидные поля.
Browse files Browse the repository at this point in the history
  • Loading branch information
6yJlKaBo3 committed Mar 17, 2024
1 parent 2697086 commit e60c8b6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
4 changes: 2 additions & 2 deletions app/src/Domain/ValueObject/AbstractValueObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function getValue(): string
/**
* @param string $value
* @throws Exception
* @return mixed Возвращаемое значение после валидации
* @return void Возвращаемое значение после валидации
*/
abstract protected function validation(string $value): mixed;
abstract protected function validation(string $value): void;
}
11 changes: 7 additions & 4 deletions app/src/Domain/ValueObject/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@

namespace App\Domain\ValueObject;

use Exception;
use InvalidArgumentException;

class Email extends AbstractValueObject
{
/**
* @param string $value
* @return mixed
* @return void
* @throws InvalidArgumentException
*/
protected function validation(string $value): mixed
protected function validation(string $value): void
{
return;
if (!filter_var($value, FILTER_VALIDATE_EMAIL)) {
throw new InvalidArgumentException('Неверный формат email адреса');
}
}
}
12 changes: 8 additions & 4 deletions app/src/Domain/ValueObject/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@

namespace App\Domain\ValueObject;

use Exception;
use InvalidArgumentException;

class Message extends AbstractValueObject
{
/**
* @param string $value
* @return mixed
* @return void
* @throws InvalidArgumentException
*/
protected function validation(string $value): mixed
protected function validation(string $value): void
{
return;
// Проверяем, что сообщение не пустое
if (empty($value)) {
throw new InvalidArgumentException('Сообщение не может быть пустым');
}
}
}

0 comments on commit e60c8b6

Please sign in to comment.