J2cQuery   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 224
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 1
dl 0
loc 224
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getBaseUrl() 0 4 1
A getKeyword() 0 4 1
A defaultAttributes() 0 7 1
A requiredAttributes() 0 9 1
A userIp() 0 4 2
1
<?php namespace JobApis\Jobs\Client\Queries;
2
3
class J2cQuery extends AbstractQuery
4
{
5
    /**
6
     * id
7
     *
8
     * Publisher ID
9
     *
10
     * @var string
11
     */
12
    protected $id;
13
14
    /**
15
     * pass
16
     *
17
     * Publisher Password
18
     *
19
     * @var string
20
     */
21
    protected $pass;
22
23
    /**
24
     * ip
25
     *
26
     * IP Address
27
     *
28
     * @var string
29
     */
30
    protected $ip;
31
32
    /**
33
     * q
34
     *
35
     * Keyword/search query
36
     *
37
     * @var string
38
     */
39
    protected $q;
40
41
    /**
42
     * l
43
     *
44
     * Location
45
     *
46
     * @var string
47
     */
48
    protected $l;
49
50
    /**
51
     * start
52
     *
53
     * Starting result #
54
     *
55
     * @var integer
56
     */
57
    protected $start;
58
59
    /**
60
     * limit
61
     *
62
     * Max # of results to return
63
     *
64
     * @var integer
65
     */
66
    protected $limit;
67
68
    /**
69
     * sort
70
     *
71
     * Sort by:
72
     *  d - by date
73
     *  r - by relevance
74
     *
75
     * @var string
76
     */
77
    protected $sort;
78
79
    /**
80
     * industry
81
     *
82
     * Industry code to search by
83
     *
84
     * @var string
85
     */
86
    protected $industry;
87
88
    /**
89
     * industryEx
90
     *
91
     * Industry code to exclude
92
     *
93
     * @var string
94
     */
95
    protected $industryEx;
96
97
    /**
98
     * format
99
     *
100
     * Must be `json`
101
     *
102
     * @var string
103
     */
104
    protected $format;
105
106
    /**
107
     * m
108
     *
109
     * Mobile-optimized jobs only
110
     *
111
     * @var boolean
112
     */
113
    protected $m;
114
115
    /**
116
     * link
117
     *
118
     * Bypass the JavaScript function to expose a direct link. Default = 0
119
     *
120
     * @var boolean
121
     */
122
    protected $link;
123
124
    /**
125
     * full_desc
126
     *
127
     * Full job description
128
     *
129
     * @var boolean
130
     */
131
    protected $full_desc;
132
133
    /**
134
     * jobid
135
     *
136
     * Job ID to search for
137
     *
138
     * @var string
139
     */
140
    protected $jobid;
141
142
    /**
143
     * jobtype
144
     *
145
     * Job type to search for
146
     *
147
     * @var string
148
     */
149
    protected $jobtype;
150
151
    /**
152
     * d
153
     *
154
     * Radius to search
155
     *
156
     * @var integer
157
     */
158
    protected $d;
159
160
    /**
161
     * useragent
162
     *
163
     * Pass in the user agent to prioritize mobile jobs
164
     *
165
     * @var string
166
     */
167
    protected $useragent;
168
169
    /**
170
     * Get baseUrl
171
     *
172
     * @return  string Value of the base url to this api
173
     */
174 6
    public function getBaseUrl()
175
    {
176 6
        return 'http://api.jobs2careers.com/api/search.php';
177
    }
178
179
    /**
180
     * Get keyword
181
     *
182
     * @return  string Attribute being used as the search keyword
183
     */
184 4
    public function getKeyword()
185
    {
186 4
        return $this->q;
187
    }
188
189
    /**
190
     * Default parameters
191
     *
192
     * @var array
193
     */
194 20
    protected function defaultAttributes()
195
    {
196
        return [
197 20
            'format' => 'json',
198 20
            'ip' => $this->userIp(),
199 20
        ];
200
    }
201
202
    /**
203
     * Required parameters
204
     *
205
     * @return array
206
     */
207 6
    protected function requiredAttributes()
208
    {
209
        return [
210 6
            'id',
211 6
            'pass',
212 6
            'ip',
213 6
            'q',
214 6
        ];
215
    }
216
217
    /**
218
     * Return the IP address from server
219
     *
220
     * @return  string
221
     */
222 20
    protected function userIp()
0 ignored issues
show
Coding Style introduced by
userIp uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
223
    {
224 20
        return isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : getHostByName(getHostName());
225
    }
226
}
227