-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTodoItem.php
95 lines (83 loc) · 1.84 KB
/
TodoItem.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
declare(strict_types=1);
namespace N1215\LaraTodo\Impls\POPOAndPDO;
use Carbon\Carbon;
use Carbon\CarbonInterface;
use N1215\LaraTodo\Common\CompletedAt;
use N1215\LaraTodo\Common\Title;
use N1215\LaraTodo\Common\TodoItemId;
use N1215\LaraTodo\Common\TodoItemInterface;
/**
* POPOのTodoItemエンティティ実装
* Class TodoItem
* @package N1215\LaraTodo\Impls\POPOAndPDO
*/
class TodoItem implements TodoItemInterface
{
/**
* @var TodoItemId
*/
private $id;
/**
* @var Title
*/
private $title;
/**
* @var CompletedAt
*/
private $completedAt;
/**
* コンストラクタ
* @param TodoItemId $id
* @param Title $title
* @param CompletedAt $completedAt
*/
public function __construct(TodoItemId $id, Title $title, CompletedAt $completedAt)
{
$this->id = $id;
$this->title = $title;
$this->completedAt = $completedAt;
}
/**
* @inheritDoc
*/
public function getId(): TodoItemId
{
return $this->id;
}
/**
* @inheritDoc
*/
public function getTitle(): Title
{
return $this->title;
}
/**
* @inheritDoc
*/
public function isCompleted(?CarbonInterface $datetime = null): bool
{
if ($datetime === null) {
$datetime = Carbon::now();
}
return $this->completedAt->isPast($datetime);
}
/**
* @inheritDoc
*/
public function markAsCompleted(?CarbonInterface $datetime = null): void
{
if ($datetime === null) {
$datetime = Carbon::now();
}
$this->completedAt = CompletedAt::of($datetime);
}
/**
* 完了日時を取得
* @return CompletedAt
*/
public function getCompletedAt(): CompletedAt
{
return $this->completedAt;
}
}