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