1
+ <?php
2
+
3
+ /**
4
+ *
5
+ * $$$$$$\ $$\ $$\
6
+ * $$ __$$\ $$ | \__|
7
+ * $$ / \__|$$ | $$$$$$\ $$$$$$$\ $$$$$$$\ $$\
8
+ * $$ | $$ | \____$$\ $$ _____|$$ _____|$$ |
9
+ * $$ | $$ | $$$$$$$ |\$$$$$$\ \$$$$$$\ $$ |
10
+ * $$ | $$\ $$ |$$ __$$ | \____$$\ \____$$\ $$ |
11
+ * \$$$$$$ |$$ |\$$$$$$$ |$$$$$$$ |$$$$$$$ |$$ |
12
+ * \______/ \__| \_______|\_______/ \_______/ \__|
13
+ *
14
+ *
15
+ * @author Nerahikada
16
+ * @link https://twitter.com/Nerahikada
17
+ *
18
+ */
19
+
20
+ declare (strict_types=1 );
21
+
22
+ namespace Classi ;
23
+
24
+ class Challenge{
25
+
26
+ /** @var string */
27
+ private $ url ;
28
+
29
+ /** @var string */
30
+ private $ title ;
31
+
32
+ /** @var string */
33
+ private $ name ;
34
+
35
+ /** @var string */
36
+ private $ teacherName ;
37
+
38
+ /** @var string */
39
+ private $ teacherMessage ;
40
+
41
+ /** @var \DateTimeImmutable */
42
+ private $ deliveryDate ;
43
+
44
+ /** @var ?\DateTimeImmutable */
45
+ private $ deadline = null ;
46
+
47
+ /** @var ?\DateTimeImmutable */
48
+ private $ lastUpdate = null ;
49
+
50
+ /** @var int */
51
+ private $ progress ;
52
+
53
+ /** @var string */
54
+ private $ startUrl ;
55
+
56
+ public function __construct (string $ url , string $ title , string $ name , string $ teacherName , string $ teacherMessage , $ deliveryDate , $ deadline = null , $ lastUpdate = null , int $ progress , string $ startUrl ){
57
+ $ this ->url = $ url ;
58
+ $ this ->title = $ title ;
59
+ $ this ->name = $ name ;
60
+ $ this ->teacherName = $ teacherName ;
61
+ $ this ->teacherMessage = $ teacherMessage ;
62
+ $ this ->deliveryDate = $ this ->convertDate ($ deliveryDate );
63
+ $ this ->deadline = $ this ->convertDate ($ deadline );
64
+ $ this ->lastUpdate = $ this ->convertDate ($ lastUpdate );
65
+ if ($ progress < 0 || $ progress > 100 ){
66
+ throw new \RuntimeException ('Progress must be in the range 1-100 ' );
67
+ }
68
+ $ this ->progress = $ progress ;
69
+ $ this ->startUrl = $ startUrl ;
70
+ }
71
+
72
+ private function convertDate ($ date ) : ?\DateTimeImmutable {
73
+ if ($ date instanceof \DateTimeImmutable){
74
+ return $ date ;
75
+ }
76
+ if ($ date instanceof \DateTime){
77
+ return \DateTimeImmutable::createFromMutable ($ date );
78
+ }
79
+ if (empty ($ date ) || $ date === '- ' ){
80
+ return null ;
81
+ }
82
+ try {
83
+ return new \DateTimeImmutable ($ date , new \DateTimeZone ('Asia/Tokyo ' ));
84
+ }catch (\Exception $ e ){
85
+ throw new \InvalidArgumentException ('Invalid value ' );
86
+ }
87
+ }
88
+
89
+ public function getUrl () : string {
90
+ return $ this ->url ;
91
+ }
92
+
93
+ public function getTitle () : string {
94
+ return $ this ->title ;
95
+ }
96
+
97
+ public function getName () : string {
98
+ return $ this ->name ;
99
+ }
100
+
101
+ public function getTeacherName () : string {
102
+ return $ this ->teacherName ;
103
+ }
104
+
105
+ public function getTeacherMessage () : string {
106
+ return $ this ->teacherMessage ;
107
+ }
108
+
109
+ public function getDeliveryDate () : ?\DateTimeImmutable {
110
+ return $ this ->deliveryDate ;
111
+ }
112
+
113
+ public function getDeadline () : ?\DateTimeImmutable {
114
+ return $ this ->deadline ;
115
+ }
116
+
117
+ public function getLastUpdate () : ?\DateTimeImmutable {
118
+ return $ this ->lastUpdate ;
119
+ }
120
+
121
+ public function getProgress () : int {
122
+ return $ this ->progress ;
123
+ }
124
+
125
+ public function getStartUrl () : string {
126
+ return $ this ->startUrl ;
127
+ }
128
+ }
0 commit comments