Completed
Push — master ( f571ad...af881e )
by Gorka
10s
created

TaskDTODataTransformer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 28
rs 10
c 1
b 0
f 0
wmc 3
lcom 1
cbo 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A write() 0 4 1
A read() 0 18 2
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