1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Coco\SourceWatcher\Vendors\StackOverflow; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class StackOverflowJob |
7
|
|
|
* @package Coco\SourceWatcher\Vendors\StackOverflow |
8
|
|
|
*/ |
9
|
|
|
class StackOverflowJob |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var string |
13
|
|
|
*/ |
14
|
|
|
private string $baseURL = "https://stackoverflow.com"; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var string|null |
18
|
|
|
*/ |
19
|
|
|
private ?string $jobId = null; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var string|null |
23
|
|
|
*/ |
24
|
|
|
private ?string $resultId = null; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var string|null |
28
|
|
|
*/ |
29
|
|
|
private ?string $previewUrl = null; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var string|null |
33
|
|
|
*/ |
34
|
|
|
private ?string $logo = "https://pbs.twimg.com/profile_images/425274582581264384/X3QXBN8C.jpeg"; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var string|null |
38
|
|
|
*/ |
39
|
|
|
private ?string $title = null; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var string|null |
43
|
|
|
*/ |
44
|
|
|
private ?string $company = null; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var string|null |
48
|
|
|
*/ |
49
|
|
|
private ?string $location = null; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @return string|null |
53
|
|
|
*/ |
54
|
|
|
public function getJobId () : ?string |
55
|
|
|
{ |
56
|
|
|
return $this->jobId; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param string|null $jobId |
61
|
|
|
*/ |
62
|
|
|
public function setJobId ( ?string $jobId ) : void |
63
|
|
|
{ |
64
|
|
|
$this->jobId = $jobId; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return string|null |
69
|
|
|
*/ |
70
|
|
|
public function getResultId () : ?string |
71
|
|
|
{ |
72
|
|
|
return $this->resultId; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param string|null $resultId |
77
|
|
|
*/ |
78
|
|
|
public function setResultId ( ?string $resultId ) : void |
79
|
|
|
{ |
80
|
|
|
$this->resultId = $resultId; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @return string|null |
85
|
|
|
*/ |
86
|
|
|
public function getPreviewUrl () : ?string |
87
|
|
|
{ |
88
|
|
|
return $this->previewUrl; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @param string|null $previewUrl |
93
|
|
|
*/ |
94
|
|
|
public function setPreviewUrl ( ?string $previewUrl ) : void |
95
|
|
|
{ |
96
|
|
|
$this->previewUrl = $previewUrl; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @return string|null |
101
|
|
|
*/ |
102
|
|
|
public function getLogo () : ?string |
103
|
|
|
{ |
104
|
|
|
return $this->logo; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @param string|null $logo |
109
|
|
|
*/ |
110
|
|
|
public function setLogo ( ?string $logo ) : void |
111
|
|
|
{ |
112
|
|
|
$this->logo = $logo; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @return string|null |
117
|
|
|
*/ |
118
|
|
|
public function getTitle () : ?string |
119
|
|
|
{ |
120
|
|
|
return $this->title; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @param string|null $title |
125
|
|
|
*/ |
126
|
|
|
public function setTitle ( ?string $title ) : void |
127
|
|
|
{ |
128
|
|
|
$this->title = $title; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @return string|null |
133
|
|
|
*/ |
134
|
|
|
public function getCompany () : ?string |
135
|
|
|
{ |
136
|
|
|
return $this->company; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @param string|null $company |
141
|
|
|
*/ |
142
|
|
|
public function setCompany ( ?string $company ) : void |
143
|
|
|
{ |
144
|
|
|
$this->company = $company; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @return string|null |
149
|
|
|
*/ |
150
|
|
|
public function getLocation () : ?string |
151
|
|
|
{ |
152
|
|
|
return $this->location; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* @param string|null $location |
157
|
|
|
*/ |
158
|
|
|
public function setLocation ( ?string $location ) : void |
159
|
|
|
{ |
160
|
|
|
$this->location = $location; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* @return string |
165
|
|
|
*/ |
166
|
|
|
public function getRefinedUrl () : string |
167
|
|
|
{ |
168
|
|
|
$currentPreviewUrl = substr( $this->previewUrl, 0, strlen( $this->baseURL ) ) === $this->baseURL ? $this->previewUrl : $this->baseURL . $this->previewUrl; |
169
|
|
|
|
170
|
|
|
$pieces = explode( "?", $currentPreviewUrl ); |
171
|
|
|
|
172
|
|
|
$refinedUrl = ""; |
173
|
|
|
|
174
|
|
|
if ( $pieces != null ) { |
175
|
|
|
if ( sizeof( $pieces ) >= 1 ) { |
176
|
|
|
$refinedUrl = $pieces[0]; |
177
|
|
|
} |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
return $refinedUrl; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* @return bool |
185
|
|
|
*/ |
186
|
|
|
public function allAttributesDefined () : bool |
187
|
|
|
{ |
188
|
|
|
$variablesToValidate = [ $this->jobId, $this->resultId, $this->previewUrl, $this->logo, $this->title, $this->company, $this->location ]; |
189
|
|
|
|
190
|
|
|
foreach ( $variablesToValidate as $currentVariable ) { |
191
|
|
|
if ( empty( $currentVariable ) ) { |
192
|
|
|
return false; |
193
|
|
|
} |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
return true; |
197
|
|
|
} |
198
|
|
|
} |
199
|
|
|
|