Passed
Push — master ( d151aa...1c6332 )
by Jean Paul
01:43
created

StackOverflowJob::allAttributesDefined()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 5
c 1
b 0
f 0
nc 3
nop 0
dl 0
loc 11
rs 10
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 = "https://pbs.twimg.com/profile_images/425274582581264384/X3QXBN8C.jpeg"; // https://cdn.sstatic.net/careers/Img/ico-no-company-logo.svg
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
    /**
135
     * @return string
136
     */
137
    public function getRefinedUrl () : string
138
    {
139
        $currentPreviewUrl = substr( $this->previewUrl, 0, strlen( $this->baseURL ) ) === $this->baseURL ? $this->previewUrl : $this->baseURL . $this->previewUrl;
140
141
        $pieces = explode( "?", $currentPreviewUrl );
142
143
        $refinedUrl = "";
144
145
        if ( $pieces != null ) {
146
            if ( sizeof( $pieces ) >= 1 ) {
147
                $refinedUrl = $pieces[0];
148
            }
149
        }
150
151
        return $refinedUrl;
152
    }
153
154
    /**
155
     * @return bool
156
     */
157
    public function allAttributesDefined () : bool
158
    {
159
        $variablesToValidate = [ $this->jobId, $this->resultId, $this->previewUrl, $this->logo, $this->title, $this->company, $this->location ];
160
161
        foreach ( $variablesToValidate as $currentVariable ) {
162
            if ( $currentVariable == null ) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $currentVariable of type null|string against null; this is ambiguous if the string can be empty. Consider using a strict comparison === instead.
Loading history...
163
                return false;
164
            }
165
        }
166
167
        return true;
168
    }
169
170
    /**
171
     * @return string
172
     */
173
    public function __toString () : string
174
    {
175
        $result = "";
176
        $result .= "job id: " . $this->jobId . PHP_EOL;
177
        $result .= "result id: " . $this->resultId . PHP_EOL;
178
        $result .= "preview url: " . $this->previewUrl . PHP_EOL;
179
        $result .= "logo: " . $this->logo . PHP_EOL;
180
        $result .= "title: " . $this->title . PHP_EOL;
181
        $result .= "company: " . $this->company . PHP_EOL;
182
        $result .= "location: " . $this->location . PHP_EOL;
183
        return $result;
184
    }
185
}
186