Completed
Branch master (cb4e34)
by Rudie
02:36
created
lib/fuelly/src/Client.php 3 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -328,6 +328,7 @@
 block discarded – undo
328 328
 
329 329
 	/**
330 330
 	 * HTTP POST
331
+	 * @param string $uri
331 332
 	 */
332 333
 	public function _post( $uri, $options = array() ) {
333 334
 		return $this->_http($uri, $options + array('method' => 'POST'));
Please login to merge, or discard this patch.
Spacing   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -25,23 +25,23 @@  discard block
 block discarded – undo
25 25
 	/**
26 26
 	 * Dependency constructor
27 27
 	 */
28
-	public function __construct( WebAuth $auth ) {
28
+	public function __construct(WebAuth $auth) {
29 29
 		$this->auth = $auth;
30 30
 	}
31 31
 
32 32
 	/**
33 33
 	 *
34 34
 	 */
35
-	public function getFuelUp( $id ) {
35
+	public function getFuelUp($id) {
36 36
 		$fuelup = compact('id');
37 37
 
38 38
 		$response = $this->_get('fuelups/' . $id . '/edit');
39 39
 
40 40
 		preg_match_all('#<input[\s\S]+?name="([^"]+)"[\s\S]+?>#', $response->body, $matches, PREG_SET_ORDER);
41 41
 		foreach ($matches as $match) {
42
-			if ( in_array($match[1], array('_token', 'miles_last_fuelup', 'price_per_unit', 'amount', 'fuelup_date')) ) {
42
+			if (in_array($match[1], array('_token', 'miles_last_fuelup', 'price_per_unit', 'amount', 'fuelup_date'))) {
43 43
 				preg_match('#value="([^"]+)"#', $match[0], $match2);
44
-				$fuelup[ $match[1] ] = $match2[1];
44
+				$fuelup[$match[1]] = $match2[1];
45 45
 			}
46 46
 		}
47 47
 
@@ -54,11 +54,11 @@  discard block
 block discarded – undo
54 54
 	/**
55 55
 	 *
56 56
 	 */
57
-	public function updateFuelUp( $id, $data ) {
57
+	public function updateFuelUp($id, $data) {
58 58
 		$data = $this->_validateFuelUpData($data);
59 59
 		unset($data['id']);
60 60
 
61
-		if ( !isset($data['_token']) ) {
61
+		if (!isset($data['_token'])) {
62 62
 			$response = $this->_get('fuelups/' . $id . '/edit');
63 63
 			$token = $this->extractFormToken($response->body);
64 64
 		}
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 	/**
74 74
 	 *
75 75
 	 */
76
-	public function _validateFuelUpData( $data ) {
76
+	public function _validateFuelUpData($data) {
77 77
 		$data += array(
78 78
 			'errorlevel' => 2,
79 79
 			'price_per_unit' => '',
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 
91 91
 		$required = array('usercar_id', 'miles_last_fuelup', 'amount');
92 92
 		$missing = array_diff($required, array_keys(array_filter($data)));
93
-		if ( $missing ) {
93
+		if ($missing) {
94 94
 			throw new InvalidArgumentException('Missing params: ' . implode(', ', $missing));
95 95
 		}
96 96
 
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 	/**
101 101
 	 *
102 102
 	 */
103
-	public function getFuelUpsWithIds( Vehicle $vehicle, $limit = 15 ) {
103
+	public function getFuelUpsWithIds(Vehicle $vehicle, $limit = 15) {
104 104
 		$query = http_build_query(array(
105 105
 			'iDisplayStart' => 0,
106 106
 			'iDisplayLength' => $limit,
@@ -108,11 +108,11 @@  discard block
 block discarded – undo
108 108
 			'usercar_id' => $vehicle->id,
109 109
 		));
110 110
 		$response = $this->_get('ajax/fuelup-log?' . $query);
111
-		if ( $response->code == 200 ) {
112
-			if ( $response->response ) {
111
+		if ($response->code == 200) {
112
+			if ($response->response) {
113 113
 				$fuelups = array();
114
-				foreach ( $response->response['aaData'] as $fuelup ) {
115
-					if ( preg_match('#fuelups/(\d+)/edit#', $fuelup[0], $match) ) {
114
+				foreach ($response->response['aaData'] as $fuelup) {
115
+					if (preg_match('#fuelups/(\d+)/edit#', $fuelup[0], $match)) {
116 116
 						$fuelup = array(
117 117
 							'id' => $match[1],
118 118
 							'usercar_id' => $vehicle->id,
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 							'amount' => $fuelup[4][0],
122 122
 						);
123 123
 
124
-						$fuelups[ $fuelup['id'] ] = new FuelUp($vehicle, $fuelup);
124
+						$fuelups[$fuelup['id']] = new FuelUp($vehicle, $fuelup);
125 125
 					}
126 126
 				}
127 127
 
@@ -138,21 +138,21 @@  discard block
 block discarded – undo
138 138
 	/**
139 139
 	 *
140 140
 	 */
141
-	public function getAllFuelups( Vehicle $vehicle ) {
141
+	public function getAllFuelups(Vehicle $vehicle) {
142 142
 		$response = $this->_get('car/make/model/2001/username/' . $vehicle->id . '/export');
143
-		if ( $token = $this->extractFormToken($response->body) ) {
143
+		if ($token = $this->extractFormToken($response->body)) {
144 144
 			$response = $this->_post('exportfuelups', array(
145 145
 				'data' => array(
146 146
 					'_token' => $token,
147 147
 					'usercar_id' => $vehicle->id,
148 148
 				),
149 149
 			));
150
-			if ( $response->code == 200 ) {
150
+			if ($response->code == 200) {
151 151
 				$lines = array_filter(preg_split('#[\r\n]+#', $response->body));
152 152
 				$header = $rows = array();
153 153
 				foreach ($lines as $line) {
154 154
 					$row = array_map('trim', str_getcsv($line));
155
-					if ( !$header ) {
155
+					if (!$header) {
156 156
 						$header = $row;
157 157
 					}
158 158
 					else {
@@ -168,26 +168,26 @@  discard block
 block discarded – undo
168 168
 	/**
169 169
 	 *
170 170
 	 */
171
-	public function addFuelUp( $data ) {
171
+	public function addFuelUp($data) {
172 172
 		$data = $this->_validateFuelUpData($data);
173 173
 
174 174
 		// GET /fuelups/create
175 175
 		$response = $this->_get('fuelups/create');
176 176
 
177
-		if ( $token = $this->extractFormToken($response->body) ) {
177
+		if ($token = $this->extractFormToken($response->body)) {
178 178
 			$data['_token'] = $token;
179 179
 
180 180
 			// POST /fuelups/create
181 181
 			$response = $this->_post('fuelups', array(
182 182
 				'data' => $data,
183 183
 			));
184
-			if ( $response->code == 302 ) {
184
+			if ($response->code == 302) {
185 185
 				$response = $this->_get($response->headers['location'][0]);
186 186
 
187 187
 				// Take new fuelup ID from response and add it
188
-				if ( $response->code == 200 ) {
188
+				if ($response->code == 200) {
189 189
 					$regex = '#' . preg_quote($this->base, '#') . 'fuelups/(\d+)/edit#';
190
-					if ( preg_match($regex, $response->body, $match) ) {
190
+					if (preg_match($regex, $response->body, $match)) {
191 191
 						$response->fuelup_id = $match[1];
192 192
 					}
193 193
 				}
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
 	/**
201 201
 	 *
202 202
 	 */
203
-	public function getVehicle( $id ) {
203
+	public function getVehicle($id) {
204 204
 		$vehicles = $this->getVehicles();
205 205
 		return @$vehicles[$id];
206 206
 	}
@@ -216,11 +216,11 @@  discard block
 block discarded – undo
216 216
 	/**
217 217
 	 *
218 218
 	 */
219
-	protected function extractVehicles( $html ) {
219
+	protected function extractVehicles($html) {
220 220
 		$regex = '#<ul class="dashboard-vehicle" data-clickable="([^"]+)">[\w\W]+?</ul>#';
221 221
 		$vehicles = array();
222
-		if ( preg_match_all($regex, $html, $matches) ) {
223
-			foreach ( $matches[0] as $i => $html ) {
222
+		if (preg_match_all($regex, $html, $matches)) {
223
+			foreach ($matches[0] as $i => $html) {
224 224
 				$url = $matches[1][$i];
225 225
 
226 226
 				preg_match('#/(\d+)$#', $url, $match);
@@ -246,14 +246,14 @@  discard block
 block discarded – undo
246 246
 	 *
247 247
 	 */
248 248
 	public function logIn() {
249
-		if ( !$this->auth->mail || !$this->auth->pass ) {
249
+		if (!$this->auth->mail || !$this->auth->pass) {
250 250
 			return false;
251 251
 		}
252 252
 
253 253
 		// GET /login
254 254
 		$response = $this->_get('login', array('login' => true));
255 255
 
256
-		if ( $token = $this->extractFormToken($response->body) ) {
256
+		if ($token = $this->extractFormToken($response->body)) {
257 257
 			// POST /login
258 258
 			$response = $this->_post('login', array(
259 259
 				'login' => true,
@@ -275,14 +275,14 @@  discard block
 block discarded – undo
275 275
 	 *
276 276
 	 */
277 277
 	public function checkSession() {
278
-		if ( !$this->auth->session ) {
278
+		if (!$this->auth->session) {
279 279
 			return false;
280 280
 		}
281 281
 
282 282
 		$response = $this->_get('dashboard');
283
-		if ( $response->code == 200 ) {
283
+		if ($response->code == 200) {
284 284
 			$regex = '#<a href="' . preg_quote($this->base, '#') . 'driver/([\w\d]+)/edit">Settings</a>#';
285
-			if ( preg_match($regex, $response->body, $match) ) {
285
+			if (preg_match($regex, $response->body, $match)) {
286 286
 				$this->username = $match[1];
287 287
 
288 288
 				// Since we're downloading /dashboard anyway, let's extract our vehicles from it
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
 	 *
300 300
 	 */
301 301
 	public function refreshSession() {
302
-		if ( !$this->checkSession() ) {
302
+		if (!$this->checkSession()) {
303 303
 			return $this->logIn();
304 304
 		}
305 305
 
@@ -309,9 +309,9 @@  discard block
 block discarded – undo
309 309
 	/**
310 310
 	 *
311 311
 	 */
312
-	protected function extractFormToken( $html ) {
313
-		if ( preg_match('#<input.+?name="_token".+?>#i', $html, $match) ) {
314
-			if ( preg_match('#value="([^"]+)"#', $match[0], $match) ) {
312
+	protected function extractFormToken($html) {
313
+		if (preg_match('#<input.+?name="_token".+?>#i', $html, $match)) {
314
+			if (preg_match('#value="([^"]+)"#', $match[0], $match)) {
315 315
 				return $match[1];
316 316
 			}
317 317
 		}
@@ -322,21 +322,21 @@  discard block
 block discarded – undo
322 322
 	/**
323 323
 	 * HTTP GET
324 324
 	 */
325
-	public function _get( $uri, $options = array() ) {
325
+	public function _get($uri, $options = array()) {
326 326
 		return $this->_http($uri, $options + array('method' => 'GET'));
327 327
 	}
328 328
 
329 329
 	/**
330 330
 	 * HTTP POST
331 331
 	 */
332
-	public function _post( $uri, $options = array() ) {
332
+	public function _post($uri, $options = array()) {
333 333
 		return $this->_http($uri, $options + array('method' => 'POST'));
334 334
 	}
335 335
 
336 336
 	/**
337 337
 	 * HTTP URL
338 338
 	 */
339
-	public function _url( $uri, $options = array() ) {
339
+	public function _url($uri, $options = array()) {
340 340
 		$base = !empty($options['login']) ? $this->loginBase : $this->base;
341 341
 		$url = strpos($uri, '://') ? $uri : $base . $uri;
342 342
 		return $url;
@@ -345,7 +345,7 @@  discard block
 block discarded – undo
345 345
 	/**
346 346
 	 * HTTP REQUEST
347 347
 	 */
348
-	public function _http( $uri, $options = array() ) {
348
+	public function _http($uri, $options = array()) {
349 349
 		if ($this->auth->session) {
350 350
 			$options['cookies'][] = array('fuelly_session', $this->auth->session);
351 351
 		}
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -154,8 +154,7 @@
 block discarded – undo
154 154
 					$row = array_map('trim', str_getcsv($line));
155 155
 					if ( !$header ) {
156 156
 						$header = $row;
157
-					}
158
-					else {
157
+					} else {
159 158
 						$rows[] = array_combine($header, $row);
160 159
 					}
161 160
 				}
Please login to merge, or discard this patch.
test.edit.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@
 block discarded – undo
9 9
 
10 10
 echo "Vehicle:\n";
11 11
 $vehicles = $client->vehicles;
12
-$vehicle = $vehicles[ array_rand($vehicles) ];
12
+$vehicle = $vehicles[array_rand($vehicles)];
13 13
 print_r($vehicle);
14 14
 echo "\n\n";
15 15
 
Please login to merge, or discard this patch.
test.fuelup.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 
10 10
 echo "Vehicle:\n";
11 11
 $vehicles = $client->vehicles;
12
-$vehicle = $vehicles[ array_rand($vehicles) ];
12
+$vehicle = $vehicles[array_rand($vehicles)];
13 13
 print_r($vehicle);
14 14
 echo "\n\n";
15 15
 
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
 	'amount' => 10,
21 21
 	'note' => 'TEST TEST TEST',
22 22
 ));
23
-if ( !empty($response->fuelup_id) ) {
23
+if (!empty($response->fuelup_id)) {
24 24
 	var_dump($response->fuelup_id);
25 25
 }
26 26
 else {
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -22,8 +22,7 @@
 block discarded – undo
22 22
 ));
23 23
 if ( !empty($response->fuelup_id) ) {
24 24
 	var_dump($response->fuelup_id);
25
-}
26
-else {
25
+} else {
27 26
 	print_r($response);
28 27
 }
29 28
 echo "\n\n";
Please login to merge, or discard this patch.
test.fuelups.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@
 block discarded – undo
9 9
 
10 10
 echo "Vehicle:\n";
11 11
 $vehicles = $client->vehicles;
12
-$vehicle = $vehicles[ array_rand($vehicles) ];
12
+$vehicle = $vehicles[array_rand($vehicles)];
13 13
 print_r($vehicle);
14 14
 echo "\n\n";
15 15
 
Please login to merge, or discard this patch.
lib/fuelly/autoload.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,10 +1,10 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-spl_autoload_register(function( $class ) {
3
+spl_autoload_register(function($class) {
4 4
 	$ns = explode('\\', $class);
5 5
 	$lib = array_splice($ns, 0, 2);
6
-	if ( $lib == array('rdx', 'fuelly') ) {
7
-		if ( file_exists($file = __DIR__ . '/src/' . implode('/', $ns) . '.php') ) {
6
+	if ($lib == array('rdx', 'fuelly')) {
7
+		if (file_exists($file = __DIR__ . '/src/' . implode('/', $ns) . '.php')) {
8 8
 			include $file;
9 9
 		}
10 10
 	}
Please login to merge, or discard this patch.
lib/fuelly/src/FuelUp.php 1 patch
Spacing   +4 added lines, -5 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 	/**
16 16
 	 *
17 17
 	 */
18
-	public function __construct( Vehicle $vehicle, array $fuelup ) {
18
+	public function __construct(Vehicle $vehicle, array $fuelup) {
19 19
 		// $this->vehicle = $vehicle;
20 20
 
21 21
 		// @todo Parse date correctly
@@ -23,8 +23,7 @@  discard block
 block discarded – undo
23 23
 		// @todo Parse distance correctly
24 24
 
25 25
 		$this->date =
26
-			DateTime::createFromFormat('Y-m-d H:i:s', $fuelup['fuelup_date']) ?:
27
-			DateTime::createFromFormat('d-m-y', $fuelup['fuelup_date']);
26
+			DateTime::createFromFormat('Y-m-d H:i:s', $fuelup['fuelup_date']) ?: DateTime::createFromFormat('d-m-y', $fuelup['fuelup_date']);
28 27
 
29 28
 		$this->amount = self::number(@$fuelup['raw_amount'] ?: $fuelup['amount']);
30 29
 		$this->distance = self::number($fuelup['miles_last_fuelup']);
@@ -37,14 +36,14 @@  discard block
 block discarded – undo
37 36
 	/**
38 37
 	 *
39 38
 	 */
40
-	public static function number( $str ) {
39
+	public static function number($str) {
41 40
 		return (float) str_replace(',', '.', $str);
42 41
 	}
43 42
 
44 43
 	/**
45 44
 	 *
46 45
 	 */
47
-	public static function dateCmp( FuelUp $a, FuelUp $b ) {
46
+	public static function dateCmp(FuelUp $a, FuelUp $b) {
48 47
 		return $b->date->getTimestamp() - $a->date->getTimestamp();
49 48
 	}
50 49
 
Please login to merge, or discard this patch.
lib/fuelly/src/Vehicle.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
 	/**
19 19
 	 *
20 20
 	 */
21
-	public function __construct( Client $client, array $vehicle ) {
21
+	public function __construct(Client $client, array $vehicle) {
22 22
 		// $this->client = $client;
23 23
 
24 24
 		$this->id = $vehicle['id'];
@@ -26,8 +26,8 @@  discard block
 block discarded – undo
26 26
 		$this->name = $vehicle['name'];
27 27
 		$this->image = $vehicle['image'];
28 28
 
29
-		if ( isset($vehicle['trend']) ) {
30
-			foreach ( $vehicle['trend'] as $fuelup) {
29
+		if (isset($vehicle['trend'])) {
30
+			foreach ($vehicle['trend'] as $fuelup) {
31 31
 				$this->trend[] = new FuelUp($this, $fuelup);
32 32
 			}
33 33
 
Please login to merge, or discard this patch.
lib/fuelly/src/WebAuth.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@
 block discarded – undo
11 11
 	/**
12 12
 	 * Dependency constructor
13 13
 	 */
14
-	public function __construct( $mail, $pass, $session = '' ) {
14
+	public function __construct($mail, $pass, $session = '') {
15 15
 		$this->mail = $mail;
16 16
 		$this->pass = $pass;
17 17
 		$this->session = $session;
Please login to merge, or discard this patch.