@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | /** |
28 | 28 | * Dependency constructor |
29 | 29 | */ |
30 | - public function __construct( WebAuth $auth, InputConversion $input ) { |
|
30 | + public function __construct(WebAuth $auth, InputConversion $input) { |
|
31 | 31 | $this->auth = $auth; |
32 | 32 | $this->input = $input; |
33 | 33 | } |
@@ -43,16 +43,16 @@ discard block |
||
43 | 43 | /** |
44 | 44 | * |
45 | 45 | */ |
46 | - public function getFuelUp( $id ) { |
|
46 | + public function getFuelUp($id) { |
|
47 | 47 | $fuelup = compact('id'); |
48 | 48 | |
49 | - $response = $this->_get('fuelups/' . $id . '/edit'); |
|
49 | + $response = $this->_get('fuelups/'.$id.'/edit'); |
|
50 | 50 | |
51 | 51 | preg_match_all('#<input[\s\S]+?name="([^"]+)"[\s\S]+?>#', $response->body, $matches, PREG_SET_ORDER); |
52 | - foreach ( $matches as $match ) { |
|
53 | - if ( in_array($match[1], array('_token', 'miles_last_fuelup', 'price_per_unit', 'amount', 'fuelup_date')) ) { |
|
52 | + foreach ($matches as $match) { |
|
53 | + if (in_array($match[1], array('_token', 'miles_last_fuelup', 'price_per_unit', 'amount', 'fuelup_date'))) { |
|
54 | 54 | preg_match('#value="([^"]+)"#', $match[0], $match2); |
55 | - $fuelup[ $match[1] ] = $match2[1]; |
|
55 | + $fuelup[$match[1]] = $match2[1]; |
|
56 | 56 | } |
57 | 57 | } |
58 | 58 | |
@@ -65,17 +65,17 @@ discard block |
||
65 | 65 | /** |
66 | 66 | * |
67 | 67 | */ |
68 | - public function updateFuelUp( $id, $data ) { |
|
68 | + public function updateFuelUp($id, $data) { |
|
69 | 69 | $data = $this->_validateFuelUpData($data); |
70 | 70 | unset($data['id']); |
71 | 71 | |
72 | - if ( !isset($data['_token']) ) { |
|
73 | - $response = $this->_get('fuelups/' . $id . '/edit'); |
|
72 | + if (!isset($data['_token'])) { |
|
73 | + $response = $this->_get('fuelups/'.$id.'/edit'); |
|
74 | 74 | $data['_token'] = $this->extractFormToken($response->body); |
75 | 75 | } |
76 | 76 | |
77 | 77 | $data['_method'] = 'PUT'; |
78 | - $response = $this->_post('fuelups/' . $id, array( |
|
78 | + $response = $this->_post('fuelups/'.$id, array( |
|
79 | 79 | 'data' => $data, |
80 | 80 | )); |
81 | 81 | return $response->code == 302; |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | /** |
85 | 85 | * |
86 | 86 | */ |
87 | - public function _validateFuelUpData( $data ) { |
|
87 | + public function _validateFuelUpData($data) { |
|
88 | 88 | $data += array( |
89 | 89 | 'errorlevel' => 2, |
90 | 90 | 'price_per_unit' => '', |
@@ -101,8 +101,8 @@ discard block |
||
101 | 101 | |
102 | 102 | $required = array('usercar_id', 'miles_last_fuelup', 'amount'); |
103 | 103 | $missing = array_diff($required, array_keys(array_filter($data))); |
104 | - if ( $missing ) { |
|
105 | - throw new InvalidArgumentException('Missing params: ' . implode(', ', $missing)); |
|
104 | + if ($missing) { |
|
105 | + throw new InvalidArgumentException('Missing params: '.implode(', ', $missing)); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | return $data; |
@@ -111,19 +111,19 @@ discard block |
||
111 | 111 | /** |
112 | 112 | * |
113 | 113 | */ |
114 | - public function getFuelUpsWithIds( Vehicle $vehicle, $limit = 15 ) { |
|
114 | + public function getFuelUpsWithIds(Vehicle $vehicle, $limit = 15) { |
|
115 | 115 | $query = http_build_query(array( |
116 | 116 | 'iDisplayStart' => 0, |
117 | 117 | 'iDisplayLength' => $limit, |
118 | 118 | 'sSortDir_0' => 'desc', |
119 | 119 | 'usercar_id' => $vehicle->id, |
120 | 120 | )); |
121 | - $response = $this->_get('ajax/fuelup-log?' . $query); |
|
122 | - if ( $response->code == 200 ) { |
|
123 | - if ( $response->response ) { |
|
121 | + $response = $this->_get('ajax/fuelup-log?'.$query); |
|
122 | + if ($response->code == 200) { |
|
123 | + if ($response->response) { |
|
124 | 124 | $fuelups = array(); |
125 | - foreach ( $response->response['aaData'] as $fuelup ) { |
|
126 | - if ( preg_match('#fuelups/(\d+)/edit#', $fuelup[0], $match) ) { |
|
125 | + foreach ($response->response['aaData'] as $fuelup) { |
|
126 | + if (preg_match('#fuelups/(\d+)/edit#', $fuelup[0], $match)) { |
|
127 | 127 | $fuelup = array( |
128 | 128 | 'id' => $match[1], |
129 | 129 | 'usercar_id' => $vehicle->id, |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | 'amount' => $fuelup[4][0], |
133 | 133 | ); |
134 | 134 | |
135 | - $fuelups[ $fuelup['id'] ] = FuelUp::createFromDetail($vehicle, $fuelup); |
|
135 | + $fuelups[$fuelup['id']] = FuelUp::createFromDetail($vehicle, $fuelup); |
|
136 | 136 | } |
137 | 137 | } |
138 | 138 | |
@@ -149,21 +149,21 @@ discard block |
||
149 | 149 | /** |
150 | 150 | * |
151 | 151 | */ |
152 | - public function getAllFuelups( Vehicle $vehicle ) { |
|
153 | - $response = $this->_get('car/make/model/2001/username/' . $vehicle->id . '/export'); |
|
154 | - if ( $token = $this->extractFormToken($response->body) ) { |
|
152 | + public function getAllFuelups(Vehicle $vehicle) { |
|
153 | + $response = $this->_get('car/make/model/2001/username/'.$vehicle->id.'/export'); |
|
154 | + if ($token = $this->extractFormToken($response->body)) { |
|
155 | 155 | $response = $this->_post('exportfuelups', array( |
156 | 156 | 'data' => array( |
157 | 157 | '_token' => $token, |
158 | 158 | 'usercar_id' => $vehicle->id, |
159 | 159 | ), |
160 | 160 | )); |
161 | - if ( $response->code == 200 ) { |
|
161 | + if ($response->code == 200) { |
|
162 | 162 | $lines = array_filter(preg_split('#[\r\n]+#', $response->body)); |
163 | 163 | $header = $rows = array(); |
164 | - foreach ( $lines as $line ) { |
|
164 | + foreach ($lines as $line) { |
|
165 | 165 | $row = array_map('trim', str_getcsv($line)); |
166 | - if ( !$header ) { |
|
166 | + if (!$header) { |
|
167 | 167 | $header = $row; |
168 | 168 | } |
169 | 169 | else { |
@@ -179,26 +179,26 @@ discard block |
||
179 | 179 | /** |
180 | 180 | * |
181 | 181 | */ |
182 | - public function addFuelUp( $data ) { |
|
182 | + public function addFuelUp($data) { |
|
183 | 183 | $data = $this->_validateFuelUpData($data); |
184 | 184 | |
185 | 185 | // GET /fuelups/create |
186 | 186 | $response = $this->_get('fuelups/create'); |
187 | 187 | |
188 | - if ( $token = $this->extractFormToken($response->body) ) { |
|
188 | + if ($token = $this->extractFormToken($response->body)) { |
|
189 | 189 | $data['_token'] = $token; |
190 | 190 | |
191 | 191 | // POST /fuelups/create |
192 | 192 | $response = $this->_post('fuelups', array( |
193 | 193 | 'data' => $data, |
194 | 194 | )); |
195 | - if ( $response->code == 302 ) { |
|
195 | + if ($response->code == 302) { |
|
196 | 196 | $response = $this->_get($response->headers['location'][0]); |
197 | 197 | |
198 | 198 | // Take new fuelup ID from response and add it |
199 | - if ( $response->code == 200 ) { |
|
200 | - $regex = '#' . preg_quote($this->base, '#') . 'fuelups/(\d+)/edit#'; |
|
201 | - if ( preg_match($regex, $response->body, $match) ) { |
|
199 | + if ($response->code == 200) { |
|
200 | + $regex = '#'.preg_quote($this->base, '#').'fuelups/(\d+)/edit#'; |
|
201 | + if (preg_match($regex, $response->body, $match)) { |
|
202 | 202 | $response->fuelup_id = $match[1]; |
203 | 203 | } |
204 | 204 | } |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | /** |
212 | 212 | * |
213 | 213 | */ |
214 | - public function getVehicle( $id ) { |
|
214 | + public function getVehicle($id) { |
|
215 | 215 | $vehicles = $this->getVehicles(); |
216 | 216 | return @$vehicles[$id]; |
217 | 217 | } |
@@ -227,11 +227,11 @@ discard block |
||
227 | 227 | /** |
228 | 228 | * |
229 | 229 | */ |
230 | - protected function extractVehicles( $html ) { |
|
230 | + protected function extractVehicles($html) { |
|
231 | 231 | $regex = '#<ul class="dashboard-vehicle" data-clickable="([^"]+)">[\w\W]+?</ul>#'; |
232 | 232 | $vehicles = array(); |
233 | - if ( preg_match_all($regex, $html, $matches) ) { |
|
234 | - foreach ( $matches[0] as $i => $html ) { |
|
233 | + if (preg_match_all($regex, $html, $matches)) { |
|
234 | + foreach ($matches[0] as $i => $html) { |
|
235 | 235 | $url = $matches[1][$i]; |
236 | 236 | |
237 | 237 | preg_match('#/(\d+)$#', $url, $match); |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | $name = htmlspecialchars_decode($match[1]); |
242 | 242 | |
243 | 243 | preg_match("#:\s*url\('/([^']+)'\)#", $html, $match); |
244 | - $image = $this->base . $match[1]; |
|
244 | + $image = $this->base.$match[1]; |
|
245 | 245 | |
246 | 246 | preg_match("#data-trend='([^']+)'#", $html, $match); |
247 | 247 | $trend = @json_decode($match[1], true) ?: false; |
@@ -257,14 +257,14 @@ discard block |
||
257 | 257 | * |
258 | 258 | */ |
259 | 259 | public function logIn() { |
260 | - if ( !$this->auth->mail || !$this->auth->pass ) { |
|
260 | + if (!$this->auth->mail || !$this->auth->pass) { |
|
261 | 261 | return false; |
262 | 262 | } |
263 | 263 | |
264 | 264 | // GET /login |
265 | 265 | $response = $this->_get('login', array('login' => true)); |
266 | 266 | |
267 | - if ( $token = $this->extractFormToken($response->body) ) { |
|
267 | + if ($token = $this->extractFormToken($response->body)) { |
|
268 | 268 | // POST /login |
269 | 269 | $response = $this->_post('login', array( |
270 | 270 | 'login' => true, |
@@ -286,14 +286,14 @@ discard block |
||
286 | 286 | * |
287 | 287 | */ |
288 | 288 | public function checkSession() { |
289 | - if ( !$this->auth->session ) { |
|
289 | + if (!$this->auth->session) { |
|
290 | 290 | return false; |
291 | 291 | } |
292 | 292 | |
293 | 293 | $response = $this->_get('dashboard'); |
294 | - if ( $response->code == 200 ) { |
|
295 | - $regex = '#<a href="' . preg_quote($this->base, '#') . 'driver/([\w\d]+)/edit">Settings</a>#'; |
|
296 | - if ( preg_match($regex, $response->body, $match) ) { |
|
294 | + if ($response->code == 200) { |
|
295 | + $regex = '#<a href="'.preg_quote($this->base, '#').'driver/([\w\d]+)/edit">Settings</a>#'; |
|
296 | + if (preg_match($regex, $response->body, $match)) { |
|
297 | 297 | $this->username = $match[1]; |
298 | 298 | |
299 | 299 | // Since we're downloading /dashboard anyway, let's extract our vehicles from it |
@@ -310,7 +310,7 @@ discard block |
||
310 | 310 | * |
311 | 311 | */ |
312 | 312 | public function ensureSession() { |
313 | - if ( !$this->checkSession() ) { |
|
313 | + if (!$this->checkSession()) { |
|
314 | 314 | return $this->logIn(); |
315 | 315 | } |
316 | 316 | |
@@ -320,9 +320,9 @@ discard block |
||
320 | 320 | /** |
321 | 321 | * |
322 | 322 | */ |
323 | - protected function extractFormToken( $html ) { |
|
324 | - if ( preg_match('#<input.+?name="_token".+?>#i', $html, $match) ) { |
|
325 | - if ( preg_match('#value="([^"]+)"#', $match[0], $match) ) { |
|
323 | + protected function extractFormToken($html) { |
|
324 | + if (preg_match('#<input.+?name="_token".+?>#i', $html, $match)) { |
|
325 | + if (preg_match('#value="([^"]+)"#', $match[0], $match)) { |
|
326 | 326 | return $match[1]; |
327 | 327 | } |
328 | 328 | } |
@@ -333,30 +333,30 @@ discard block |
||
333 | 333 | /** |
334 | 334 | * HTTP GET |
335 | 335 | */ |
336 | - public function _get( $uri, $options = array() ) { |
|
336 | + public function _get($uri, $options = array()) { |
|
337 | 337 | return $this->_http($uri, $options + array('method' => 'GET')); |
338 | 338 | } |
339 | 339 | |
340 | 340 | /** |
341 | 341 | * HTTP POST |
342 | 342 | */ |
343 | - public function _post( $uri, $options = array() ) { |
|
343 | + public function _post($uri, $options = array()) { |
|
344 | 344 | return $this->_http($uri, $options + array('method' => 'POST')); |
345 | 345 | } |
346 | 346 | |
347 | 347 | /** |
348 | 348 | * HTTP URL |
349 | 349 | */ |
350 | - public function _url( $uri, $options = array() ) { |
|
350 | + public function _url($uri, $options = array()) { |
|
351 | 351 | $base = !empty($options['login']) ? $this->loginBase : $this->base; |
352 | - $url = strpos($uri, '://') ? $uri : $base . $uri; |
|
352 | + $url = strpos($uri, '://') ? $uri : $base.$uri; |
|
353 | 353 | return $url; |
354 | 354 | } |
355 | 355 | |
356 | 356 | /** |
357 | 357 | * HTTP REQUEST |
358 | 358 | */ |
359 | - public function _http( $uri, $options = array() ) { |
|
359 | + public function _http($uri, $options = array()) { |
|
360 | 360 | if ($this->auth->session) { |
361 | 361 | $options['cookies'][] = array('fuelly_session', $this->auth->session); |
362 | 362 | } |
@@ -364,7 +364,7 @@ discard block |
||
364 | 364 | $url = $this->_url($uri, $options); |
365 | 365 | |
366 | 366 | $log = array(); |
367 | - $log['req'] = $options['method'] . ' ' . $url; |
|
367 | + $log['req'] = $options['method'].' '.$url; |
|
368 | 368 | $this->log[] = &$log; |
369 | 369 | |
370 | 370 | $_start = microtime(1); |
@@ -373,7 +373,7 @@ discard block |
||
373 | 373 | $response = $request->request(); |
374 | 374 | $_time = microtime(1) - $_start; |
375 | 375 | |
376 | - $log['rsp'] = $response->code . ' ' . $response->status; |
|
376 | + $log['rsp'] = $response->code.' '.$response->status; |
|
377 | 377 | $log['time'] = $_time; |
378 | 378 | |
379 | 379 | return $response; |