My Project
TaskDetail.php
[詳解]
1 <?php
2 declare(strict_types=1);
3 
4 namespace Todo\Task\ValueObject;
5 
8 
9 final class TaskDetail extends StringValue
10 {
11  const MAX_LENGTH = 1000;
12 
13  public function __construct(string $value)
14  {
15  $this->validate($value);
16  $this->value = $value;
17  }
18 
19  protected function validate(string $value): void
20  {
21  if (mb_strlen($value) > self::MAX_LENGTH) {
22  throw new InvalidArgumentException(sprintf('%s must be %s length.', __CLASS__, self::MAX_LENGTH));
23  }
24  }
25 }