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\Organization\OrganizationRepository; |
18
|
|
|
use Kreta\TaskManager\Domain\Model\Project\ProjectRepository; |
19
|
|
|
use Kreta\TaskManager\Domain\Model\Project\Task\Task; |
20
|
|
|
|
21
|
|
|
class TaskDTODataTransformer implements TaskDataTransformer |
22
|
|
|
{ |
23
|
|
|
private $task; |
24
|
|
|
private $organizationRepository; |
25
|
|
|
private $projectRepository; |
26
|
|
|
|
27
|
|
|
public function __construct(OrganizationRepository $organizationRepository, ProjectRepository $projectRepository) |
28
|
|
|
{ |
29
|
|
|
$this->organizationRepository = $organizationRepository; |
30
|
|
|
$this->projectRepository = $projectRepository; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function write(Task $task) |
34
|
|
|
{ |
35
|
|
|
$this->task = $task; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function read() |
39
|
|
|
{ |
40
|
|
|
if (!$this->task instanceof Task) { |
41
|
|
|
return []; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
$project = $this->projectRepository->projectOfId( |
45
|
|
|
$this->task->projectId() |
46
|
|
|
); |
47
|
|
|
$organization = $this->organizationRepository->organizationOfId( |
48
|
|
|
$project->organizationId() |
49
|
|
|
); |
50
|
|
|
$assigneeId = null; |
51
|
|
|
$creatorId = null; |
52
|
|
View Code Duplication |
foreach ($organization->organizationMembers() as $organizationMember) { |
|
|
|
|
53
|
|
|
if ($organizationMember->id()->equals($this->task->assigneeId())) { |
54
|
|
|
$assigneeId = $organizationMember->userId()->id(); |
55
|
|
|
} |
56
|
|
|
if ($organizationMember->id()->equals($this->task->creatorId())) { |
57
|
|
|
$creatorId = $organizationMember->userId()->id(); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
View Code Duplication |
foreach ($organization->owners() as $owner) { |
|
|
|
|
61
|
|
|
if ($owner->id()->equals($this->task->assigneeId())) { |
62
|
|
|
$assigneeId = $owner->userId()->id(); |
63
|
|
|
} |
64
|
|
|
if ($owner->id()->equals($this->task->creatorId())) { |
65
|
|
|
$creatorId = $owner->userId()->id(); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
return [ |
70
|
|
|
'id' => $this->task->id()->id(), |
71
|
|
|
'numeric_id' => $this->task->numericId()->id(), |
72
|
|
|
'title' => $this->task->title()->title(), |
73
|
|
|
'priority' => $this->task->priority()->priority(), |
74
|
|
|
'progress' => $this->task->progress()->progress(), |
75
|
|
|
'description' => $this->task->description(), |
76
|
|
|
'assignee_id' => $assigneeId, |
77
|
|
|
'creator_id' => $creatorId, |
78
|
|
|
'created_on' => $this->task->createdOn()->format('Y-m-d'), |
79
|
|
|
'updated_on' => $this->task->updatedOn()->format('Y-m-d'), |
80
|
|
|
'project_id' => $this->task->projectId()->id(), |
81
|
|
|
'parent_id' => null === $this->task->parentId() ? null : $this->task->parentId()->id(), |
82
|
|
|
]; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.