|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace GDCInfo; |
|
4
|
|
|
|
|
5
|
|
|
use Carbon\Carbon; |
|
6
|
|
|
use GDCInfo\Exceptions\GDCInfoException; |
|
7
|
|
|
use Illuminate\Support\Arr; |
|
8
|
|
|
|
|
9
|
|
|
class GDCInfo |
|
10
|
|
|
{ |
|
11
|
|
|
protected int $gdc; |
|
12
|
|
|
protected ?string $firstName = null; |
|
13
|
|
|
protected ?string $lastName = null; |
|
14
|
|
|
protected ?string $status = null; |
|
15
|
|
|
protected ?string $registrantType = null; |
|
16
|
|
|
protected ?Carbon $firstRegisteredOn = null; |
|
17
|
|
|
protected ?Carbon $currentPeriodFrom = null; |
|
18
|
|
|
protected ?Carbon $currentPeriodUntil = null; |
|
19
|
|
|
protected ?string $qualifications = null; |
|
20
|
|
|
protected array $additionalInfo = []; |
|
21
|
|
|
|
|
22
|
3 |
|
public function gdc(): int |
|
23
|
|
|
{ |
|
24
|
3 |
|
return $this->gdc; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
3 |
|
public function firstName(): ?string |
|
28
|
|
|
{ |
|
29
|
3 |
|
return $this->firstName; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
3 |
|
public function lastName(): ?string |
|
33
|
|
|
{ |
|
34
|
3 |
|
return $this->lastName; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
3 |
|
public function status(): ?string |
|
38
|
|
|
{ |
|
39
|
3 |
|
return $this->status; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
3 |
|
public function registrantType(): ?string |
|
43
|
|
|
{ |
|
44
|
3 |
|
return $this->registrantType; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
3 |
|
public function firstRegisteredOn(): ?Carbon |
|
48
|
|
|
{ |
|
49
|
3 |
|
return $this->firstRegisteredOn; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
3 |
|
public function currentPeriodFrom(): ?Carbon |
|
53
|
|
|
{ |
|
54
|
3 |
|
return $this->currentPeriodFrom; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
3 |
|
public function currentPeriodUntil(): ?Carbon |
|
58
|
|
|
{ |
|
59
|
3 |
|
return $this->currentPeriodUntil; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
3 |
|
public function qualifications(): ?string |
|
63
|
|
|
{ |
|
64
|
3 |
|
return $this->qualifications; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
3 |
|
public function additionalInfo(): array |
|
68
|
|
|
{ |
|
69
|
3 |
|
return $this->additionalInfo; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
3 |
|
public static function fromArray(array $data): static |
|
73
|
|
|
{ |
|
74
|
3 |
|
$info = new static(); |
|
75
|
|
|
|
|
76
|
3 |
|
if (!isset($data['registration_number']) || !is_numeric($data['registration_number'])) { |
|
77
|
|
|
throw new GDCInfoException('Incorrect registration_number.'); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
3 |
|
$info->gdc = $data['registration_number']; |
|
81
|
|
|
|
|
82
|
3 |
|
if (!empty($data['first_name'])) { |
|
83
|
3 |
|
$info->firstName = $data['first_name']; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
3 |
|
if (!empty($data['last_name'])) { |
|
87
|
3 |
|
$info->lastName = $data['last_name']; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
3 |
|
if (!empty($data['status'])) { |
|
91
|
3 |
|
$info->status = $data['status']; |
|
92
|
|
|
} |
|
93
|
3 |
|
if (!empty($data['registrant_type'])) { |
|
94
|
3 |
|
$info->registrantType = $data['registrant_type']; |
|
95
|
|
|
} |
|
96
|
3 |
|
if (!empty($data['qualifications'])) { |
|
97
|
3 |
|
$info->qualifications = $data['qualifications']; |
|
98
|
|
|
} |
|
99
|
3 |
|
if (!empty($data['first_registered_on']) && ($data['first_registered_on'] instanceof Carbon)) { |
|
100
|
3 |
|
$info->firstRegisteredOn = $data['first_registered_on']; |
|
101
|
|
|
} |
|
102
|
|
|
if ( |
|
103
|
3 |
|
!empty($data['current_period_from']) && |
|
104
|
3 |
|
!empty($data['current_period_until']) && |
|
105
|
3 |
|
($data['current_period_from'] instanceof Carbon) && |
|
106
|
3 |
|
($data['current_period_until'] instanceof Carbon) |
|
107
|
|
|
) { |
|
108
|
3 |
|
$info->currentPeriodFrom = $data['current_period_from']; |
|
109
|
3 |
|
$info->currentPeriodUntil = $data['current_period_until']; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
3 |
|
$info->additionalInfo = Arr::except($data, [ |
|
113
|
3 |
|
'registration_number', |
|
114
|
3 |
|
'first_name', |
|
115
|
3 |
|
'last_name', |
|
116
|
3 |
|
'status', |
|
117
|
3 |
|
'registrant_type', |
|
118
|
3 |
|
'qualifications', |
|
119
|
3 |
|
'first_registered_on', |
|
120
|
3 |
|
'current_period_from', |
|
121
|
3 |
|
'current_period_until', |
|
122
|
3 |
|
]); |
|
123
|
|
|
|
|
124
|
3 |
|
return $info; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
1 |
|
public function toArray(): array |
|
128
|
|
|
{ |
|
129
|
1 |
|
return array_filter([ |
|
130
|
1 |
|
'registration_number' => $this->gdc(), |
|
131
|
1 |
|
'first_name' => $this->firstName(), |
|
132
|
1 |
|
'last_name' => $this->lastName(), |
|
133
|
1 |
|
'status' => $this->status(), |
|
134
|
1 |
|
'registrant_type' => $this->registrantType(), |
|
135
|
1 |
|
'qualifications' => $this->qualifications(), |
|
136
|
1 |
|
'first_registered_on' => $this->firstRegisteredOn(), |
|
137
|
1 |
|
'current_period_from' => $this->currentPeriodFrom(), |
|
138
|
1 |
|
'current_period_until' => $this->currentPeriodUntil(), |
|
139
|
1 |
|
...$this->additionalInfo(), |
|
140
|
1 |
|
]); |
|
141
|
|
|
} |
|
142
|
|
|
} |
|
143
|
|
|
|