Completed
Pull Request — master (#226)
by Beñat
03:39
created

TaskDTODataTransformer::write()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 1
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the Kreta package.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
7
 * (c) Gorka Laucirica <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
declare(strict_types=1);
14
15
namespace Kreta\TaskManager\Application\DataTransformer\Project\Task;
16
17
use Kreta\TaskManager\Domain\Model\Project\Task\Task;
18
19
class TaskDTODataTransformer implements TaskDataTransformer
20
{
21
    private $task;
22
23
    public function write(Task $task)
24
    {
25
        $this->task = $task;
26
    }
27
28
    public function read()
29
    {
30
        if (!$this->task instanceof Task) {
31
            return [];
32
        }
33
34
        return [
35
            'id'          => $this->task->id()->id(),
36
            'title'       => $this->task->title()->title(),
37
            'priority'    => $this->task->priority()->priority(),
38
            'progress'    => $this->task->progress()->progress(),
39
            'description' => $this->task->description(),
40
            'created_on'  => $this->task->createdOn()->format('Y-m-d'),
41
            'updated_on'  => $this->task->updatedOn()->format('Y-m-d'),
42
            'project_id'  => $this->task->projectId()->id(),
43
            'parent_id'   => $this->task->parentId()->id(),
44
        ];
45
    }
46
}
47