diff options
Diffstat (limited to 'src/DTS')
| -rw-r--r-- | src/DTS/Old.php | 1 | ||||
| -rw-r--r-- | src/DTS/Todo.php | 2 | ||||
| -rw-r--r-- | src/DTS/TodoRepository.php | 6 | ||||
| -rw-r--r-- | src/DTS/Validated.php | 2 | ||||
| -rw-r--r-- | src/DTS/Validator.php | 19 | 
5 files changed, 28 insertions, 2 deletions
diff --git a/src/DTS/Old.php b/src/DTS/Old.php index 0641329..6e8cbee 100644 --- a/src/DTS/Old.php +++ b/src/DTS/Old.php @@ -8,6 +8,7 @@ class Old  {      const FIELDS = [          'task', +        'description',          'tag',      ]; diff --git a/src/DTS/Todo.php b/src/DTS/Todo.php index 9b08e56..ca10e1d 100644 --- a/src/DTS/Todo.php +++ b/src/DTS/Todo.php @@ -10,6 +10,8 @@ class Todo      public string $task = ''; +    public string $description = ''; +      public string $tag = '';      public string $addedAt; diff --git a/src/DTS/TodoRepository.php b/src/DTS/TodoRepository.php index 5ec759f..358ac9d 100644 --- a/src/DTS/TodoRepository.php +++ b/src/DTS/TodoRepository.php @@ -124,8 +124,9 @@ class TodoRepository implements \Iterator              $todo->id = $id++;              $todo->task = $data[0]; -            $todo->tag = $data[1]; -            $todo->addedAt = $data[2]; +            $todo->description = $data[1]; +            $todo->tag = $data[2]; +            $todo->addedAt = $data[3];              $this->repository[] = $todo; @@ -150,6 +151,7 @@ class TodoRepository implements \Iterator          foreach ($this->repository as $todo) {              $success = $success && fputcsv($fp, [                  $todo->task, +                $todo->description,                  $todo->tag,                  $todo->addedAt,              ]) !== false; diff --git a/src/DTS/Validated.php b/src/DTS/Validated.php index 9610538..9415a5f 100644 --- a/src/DTS/Validated.php +++ b/src/DTS/Validated.php @@ -8,5 +8,7 @@ class Validated  {      public string $task = ''; +    public string $description = ''; +      public string $tag = '';  } diff --git a/src/DTS/Validator.php b/src/DTS/Validator.php index 2f9c255..a2ab48f 100644 --- a/src/DTS/Validator.php +++ b/src/DTS/Validator.php @@ -21,6 +21,8 @@ class Validator          $this->validateTask($request['task'], 2, 256); +        $this->validateDescription($request['description'], 8, 512); +          $this->validateTag($request['tag'], 2, 16);      } @@ -37,6 +39,23 @@ class Validator          }      } +    private function validateDescription(string $description, int $minLength, int $maxLength): void +    { +        $description = trim($description); + +        if ($description === '') { +            return; +        } + +        if (strlen($description) < $minLength  || strlen($description) > $maxLength) { +            $this->errors->add('description', "Must be between $minLength and $maxLength in characters in length"); +        } + +        if (!$this->errors->has('tite')) { +            $this->validated->description = $description; +        } +    } +      private function validateTag(string $tag, int $minLength, int $maxLength): void      {          $tag = trim($tag);  | 
