1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Coco\SourceWatcher\Vendors\StackOverflow; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class StackOverflowJob |
7
|
|
|
* |
8
|
|
|
* @package Coco\SourceWatcher\Vendors\StackOverflow |
9
|
|
|
*/ |
10
|
|
|
class StackOverflowJob |
11
|
|
|
{ |
12
|
|
|
private string $baseURL = "https://stackoverflow.com"; |
13
|
|
|
|
14
|
|
|
private ?string $jobId = null; |
15
|
|
|
|
16
|
|
|
private ?string $resultId = null; |
17
|
|
|
|
18
|
|
|
private ?string $previewUrl = null; |
19
|
|
|
|
20
|
|
|
private ?string $logo = "https://pbs.twimg.com/profile_images/425274582581264384/X3QXBN8C.jpeg"; |
21
|
|
|
|
22
|
|
|
private ?string $title = null; |
23
|
|
|
|
24
|
|
|
private ?string $company = null; |
25
|
|
|
|
26
|
|
|
private ?string $location = null; |
27
|
|
|
|
28
|
|
|
public function getJobId () : ?string |
29
|
|
|
{ |
30
|
|
|
return $this->jobId; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function setJobId ( ?string $jobId ) : void |
34
|
|
|
{ |
35
|
|
|
$this->jobId = $jobId; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function getResultId () : ?string |
39
|
|
|
{ |
40
|
|
|
return $this->resultId; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function setResultId ( ?string $resultId ) : void |
44
|
|
|
{ |
45
|
|
|
$this->resultId = $resultId; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function getPreviewUrl () : ?string |
49
|
|
|
{ |
50
|
|
|
return $this->previewUrl; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function setPreviewUrl ( ?string $previewUrl ) : void |
54
|
|
|
{ |
55
|
|
|
$this->previewUrl = $previewUrl; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function getLogo () : ?string |
59
|
|
|
{ |
60
|
|
|
return $this->logo; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function setLogo ( ?string $logo ) : void |
64
|
|
|
{ |
65
|
|
|
$this->logo = $logo; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function getTitle () : ?string |
69
|
|
|
{ |
70
|
|
|
return $this->title; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function setTitle ( ?string $title ) : void |
74
|
|
|
{ |
75
|
|
|
$this->title = $title; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function getCompany () : ?string |
79
|
|
|
{ |
80
|
|
|
return $this->company; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function setCompany ( ?string $company ) : void |
84
|
|
|
{ |
85
|
|
|
$this->company = $company; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function getLocation () : ?string |
89
|
|
|
{ |
90
|
|
|
return $this->location; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function setLocation ( ?string $location ) : void |
94
|
|
|
{ |
95
|
|
|
$this->location = $location; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function getRefinedUrl () : string |
99
|
|
|
{ |
100
|
|
|
$currentPreviewUrl = substr( $this->previewUrl, 0, |
|
|
|
|
101
|
|
|
strlen( $this->baseURL ) ) === $this->baseURL ? $this->previewUrl : $this->baseURL . $this->previewUrl; |
102
|
|
|
|
103
|
|
|
$pieces = explode( "?", $currentPreviewUrl ); |
|
|
|
|
104
|
|
|
|
105
|
|
|
$refinedUrl = ""; |
106
|
|
|
|
107
|
|
|
if ( !empty( $pieces ) ) { |
108
|
|
|
$refinedUrl = $pieces[0]; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
return $refinedUrl; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public function allAttributesDefined () : bool |
115
|
|
|
{ |
116
|
|
|
$variablesToValidate = [ |
117
|
|
|
$this->jobId, |
118
|
|
|
$this->resultId, |
119
|
|
|
$this->previewUrl, |
120
|
|
|
$this->logo, |
121
|
|
|
$this->title, |
122
|
|
|
$this->company, |
123
|
|
|
$this->location |
124
|
|
|
]; |
125
|
|
|
|
126
|
|
|
foreach ( $variablesToValidate as $currentVariable ) { |
127
|
|
|
if ( empty( $currentVariable ) ) { |
128
|
|
|
return false; |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
return true; |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
|