Passed
Branch master (52717f)
by John
02:35
created
exampleHTTP.php 1 patch
Braces   +10 added lines, -4 removed lines patch added patch discarded remove patch
@@ -28,7 +28,9 @@  discard block
 block discarded – undo
28 28
 			// Define the folder in which to store the challenge. For the purpose of this example, a fictitious path is set.
29 29
 			$folder = '/path/to/' . $challenge['identifier'] . '/.well-known/acme-challenge/';
30 30
 			// Check if that directory yet exists. If not, create it.
31
-			if(!file_exists($folder)) mkdir($folder, 0777, true);
31
+			if(!file_exists($folder)) {
32
+				mkdir($folder, 0777, true);
33
+			}
32 34
 			// Store the challenge file for this domain.
33 35
 			file_put_contents($folder . $challenge['filename'], $challenge['content']);
34 36
 			// Let LetsEncrypt verify this challenge.
@@ -40,8 +42,12 @@  discard block
 block discarded – undo
40 42
 if($order->allAuthorizationsValid())
41 43
 {
42 44
 	// Finalize the order first, if that is not yet done.
43
-	if(!$order->isFinalized()) $order->finalizeOrder();
45
+	if(!$order->isFinalized()) {
46
+		$order->finalizeOrder();
47
+	}
44 48
 	// Check whether the order has been finalized before we can get the certificate. If finalized, get the certificate.
45
-	if($order->isFinalized()) $order->getCertificate();
46
-}
49
+	if($order->isFinalized()) {
50
+		$order->getCertificate();
51
+	}
52
+	}
47 53
 ?>
48 54
\ No newline at end of file
Please login to merge, or discard this patch.
LEClient/LEClient.php 1 patch
Braces   +44 added lines, -24 removed lines patch added patch discarded remove patch
@@ -78,17 +78,23 @@  discard block
 block discarded – undo
78 78
 
79 79
 		if (is_bool($acmeURL))
80 80
 		{
81
-			if ($acmeURL === true) $this->baseURL = LEClient::LE_STAGING;
82
-			elseif ($acmeURL === false) $this->baseURL = LEClient::LE_PRODUCTION;
83
-		}
84
-		elseif (is_string($acmeURL))
81
+			if ($acmeURL === true) {
82
+				$this->baseURL = LEClient::LE_STAGING;
83
+			} elseif ($acmeURL === false) {
84
+				$this->baseURL = LEClient::LE_PRODUCTION;
85
+			}
86
+		} elseif (is_string($acmeURL))
85 87
 		{
86 88
 			$this->baseURL = $acmeURL;
89
+		} else {
90
+			throw new \RuntimeException('acmeURL must be set to string or bool (legacy)');
87 91
 		}
88
-		else throw new \RuntimeException('acmeURL must be set to string or bool (legacy)');
89 92
 
90
-		if (is_array($certificateKeys) && is_string($accountKeys)) throw new \RuntimeException('when certificateKeys is array, accountKeys must be array also');
91
-		elseif (is_array($accountKeys) && is_string($certificateKeys)) throw new \RuntimeException('when accountKeys is array, certificateKeys must be array also');
93
+		if (is_array($certificateKeys) && is_string($accountKeys)) {
94
+			throw new \RuntimeException('when certificateKeys is array, accountKeys must be array also');
95
+		} elseif (is_array($accountKeys) && is_string($certificateKeys)) {
96
+			throw new \RuntimeException('when accountKeys is array, certificateKeys must be array also');
97
+		}
92 98
 
93 99
 		if (is_string($certificateKeys))
94 100
 		{
@@ -109,24 +115,32 @@  discard block
 block discarded – undo
109 115
 				"order" => $certificateKeys.'/order'
110 116
 			);
111 117
 
112
-		}
113
-		elseif (is_array($certificateKeys))
118
+		} elseif (is_array($certificateKeys))
114 119
 		{
115 120
 
116
-			if (!isset($certificateKeys['certificate']) && !isset($certificateKeys['fullchain_certificate'])) throw new \RuntimeException('certificateKeys[certificate] or certificateKeys[fullchain_certificate] file path must be set');
117
-			if (!isset($certificateKeys['private_key'])) throw new \RuntimeException('certificateKeys[private_key] file path must be set');
118
-			if (!isset($certificateKeys['order'])) $certificateKeys['order'] = dirname($certificateKeys['private_key']).'/order';
119
-			if (!isset($certificateKeys['public_key'])) $certificateKeys['public_key'] = dirname($certificateKeys['private_key']).'/public.pem';
121
+			if (!isset($certificateKeys['certificate']) && !isset($certificateKeys['fullchain_certificate'])) {
122
+				throw new \RuntimeException('certificateKeys[certificate] or certificateKeys[fullchain_certificate] file path must be set');
123
+			}
124
+			if (!isset($certificateKeys['private_key'])) {
125
+				throw new \RuntimeException('certificateKeys[private_key] file path must be set');
126
+			}
127
+			if (!isset($certificateKeys['order'])) {
128
+				$certificateKeys['order'] = dirname($certificateKeys['private_key']).'/order';
129
+			}
130
+			if (!isset($certificateKeys['public_key'])) {
131
+				$certificateKeys['public_key'] = dirname($certificateKeys['private_key']).'/public.pem';
132
+			}
120 133
 
121 134
 			foreach ($certificateKeys as $param => $file) {
122 135
 				$parentDir = dirname($file);
123
-				if (!is_dir($parentDir)) throw new \RuntimeException($parentDir.' directory not found');
136
+				if (!is_dir($parentDir)) {
137
+					throw new \RuntimeException($parentDir.' directory not found');
138
+				}
124 139
 			}
125 140
 
126 141
 			$this->certificateKeys = $certificateKeys;
127 142
 
128
-		}
129
-		else
143
+		} else
130 144
 		{
131 145
 			throw new \RuntimeException('certificateKeys must be string or array');
132 146
 		}
@@ -146,20 +160,24 @@  discard block
 block discarded – undo
146 160
 				"private_key" => $accountKeys.'/private.pem',
147 161
 				"public_key" => $accountKeys.'/public.pem'
148 162
 			);
149
-		}
150
-		elseif (is_array($accountKeys))
163
+		} elseif (is_array($accountKeys))
151 164
 		{
152
-			if (!isset($accountKeys['private_key'])) throw new \RuntimeException('accountKeys[private_key] file path must be set');
153
-			if (!isset($accountKeys['public_key'])) throw new \RuntimeException('accountKeys[public_key] file path must be set');
165
+			if (!isset($accountKeys['private_key'])) {
166
+				throw new \RuntimeException('accountKeys[private_key] file path must be set');
167
+			}
168
+			if (!isset($accountKeys['public_key'])) {
169
+				throw new \RuntimeException('accountKeys[public_key] file path must be set');
170
+			}
154 171
 
155 172
 			foreach ($accountKeys as $param => $file) {
156 173
 				$parentDir = dirname($file);
157
-				if (!is_dir($parentDir)) throw new \RuntimeException($parentDir.' directory not found');
174
+				if (!is_dir($parentDir)) {
175
+					throw new \RuntimeException($parentDir.' directory not found');
176
+				}
158 177
 			}
159 178
 
160 179
 			$this->accountKeys = $accountKeys;
161
-		}
162
-		else
180
+		} else
163 181
 		{
164 182
 			throw new \RuntimeException('accountKeys must be string or array');
165 183
 		}
@@ -167,7 +185,9 @@  discard block
 block discarded – undo
167 185
 
168 186
 		$this->connector = new LEConnector($this->log, $this->baseURL, $this->accountKeys);
169 187
 		$this->account = new LEAccount($this->connector, $this->log, $email, $this->accountKeys);
170
-		if($this->log) LEFunctions::log('LEClient finished constructing', 'function LEClient __construct');
188
+		if($this->log) {
189
+			LEFunctions::log('LEClient finished constructing', 'function LEClient __construct');
190
+		}
171 191
 	}
172 192
 
173 193
 
Please login to merge, or discard this patch.
LEClient/src/LEOrder.php 1 patch
Braces   +144 added lines, -89 removed lines patch added patch discarded remove patch
@@ -80,13 +80,11 @@  discard block
 block discarded – undo
80 80
 		{
81 81
 			$this->keyType = 'rsa';
82 82
 			$this->keySize = 4096;
83
-		}
84
-		elseif ($keyType == 'ec')
83
+		} elseif ($keyType == 'ec')
85 84
 		{
86 85
 			$this->keyType = 'ec';
87 86
 			$this->keySize = 256;
88
-		}
89
-		else
87
+		} else
90 88
 		{
91 89
 			preg_match_all('/^(rsa|ec)\-([0-9]{3,4})$/', $keyType, $keyTypeParts, PREG_SET_ORDER, 0);
92 90
 
@@ -94,8 +92,9 @@  discard block
 block discarded – undo
94 92
 			{
95 93
 				$this->keyType = $keyTypeParts[0][1];
96 94
 				$this->keySize = intval($keyTypeParts[0][2]);
95
+			} else {
96
+				throw new \RuntimeException('Key type \'' . $keyType . '\' not supported.');
97 97
 			}
98
-			else throw new \RuntimeException('Key type \'' . $keyType . '\' not supported.');
99 98
 		}
100 99
 
101 100
 		$this->certificateKeys = $certificateKeys;
@@ -114,47 +113,59 @@  discard block
 block discarded – undo
114 113
 					{
115 114
 						foreach ($this->certificateKeys as $file)
116 115
 						{
117
-							if (is_file($file)) rename($file, $file.'.old');
116
+							if (is_file($file)) {
117
+								rename($file, $file.'.old');
118
+							}
119
+						}
120
+						if($this->log >= LECLient::LOG_STATUS) {
121
+							LEFunctions::log('Domains do not match order data. Renaming current files and creating new order.', 'function LEOrder __construct');
118 122
 						}
119
-						if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Domains do not match order data. Renaming current files and creating new order.', 'function LEOrder __construct');
120 123
 						$this->createOrder($domains, $notBefore, $notAfter, $keyType);
121
-					}
122
-					else
124
+					} else
123 125
 					{
124 126
 						$this->status = $get['body']['status'];
125 127
 						$this->expires = $get['body']['expires'];
126 128
 						$this->identifiers = $get['body']['identifiers'];
127 129
 						$this->authorizationURLs = $get['body']['authorizations'];
128 130
 						$this->finalizeURL = $get['body']['finalize'];
129
-						if(array_key_exists('certificate', $get['body'])) $this->certificateURL = $get['body']['certificate'];
131
+						if(array_key_exists('certificate', $get['body'])) {
132
+							$this->certificateURL = $get['body']['certificate'];
133
+						}
130 134
 						$this->updateAuthorizations();
131 135
 					}
132
-				}
133
-				else
136
+				} else
134 137
 				{
135 138
 					foreach ($this->certificateKeys as $file)
136 139
 					{
137
-						if (is_file($file)) unlink($file);
140
+						if (is_file($file)) {
141
+							unlink($file);
142
+						}
143
+					}
144
+					if($this->log >= LECLient::LOG_STATUS) {
145
+						LEFunctions::log('Order data for \'' . $this->basename . '\' invalid. Deleting order data and creating new order.', 'function LEOrder __construct');
138 146
 					}
139
-					if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Order data for \'' . $this->basename . '\' invalid. Deleting order data and creating new order.', 'function LEOrder __construct');
140 147
 					$this->createOrder($domains, $notBefore, $notAfter);
141 148
 				}
142
-			}
143
-			else
149
+			} else
144 150
 			{
145 151
 
146 152
 				foreach ($this->certificateKeys as $file)
147 153
 				{
148
-					if (is_file($file)) unlink($file);
154
+					if (is_file($file)) {
155
+						unlink($file);
156
+					}
157
+				}
158
+				if($this->log >= LECLient::LOG_STATUS) {
159
+					LEFunctions::log('Order data for \'' . $this->basename . '\' invalid. Deleting order data and creating new order.', 'function LEOrder __construct');
149 160
 				}
150
-				if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Order data for \'' . $this->basename . '\' invalid. Deleting order data and creating new order.', 'function LEOrder __construct');
151 161
 
152 162
 				$this->createOrder($domains, $notBefore, $notAfter);
153 163
 			}
154
-		}
155
-		else
164
+		} else
156 165
 		{
157
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('No order found for \'' . $this->basename . '\'. Creating new order.', 'function LEOrder __construct');
166
+			if($this->log >= LECLient::LOG_STATUS) {
167
+				LEFunctions::log('No order found for \'' . $this->basename . '\'. Creating new order.', 'function LEOrder __construct');
168
+			}
158 169
 			$this->createOrder($domains, $notBefore, $notAfter);
159 170
 		}
160 171
 	}
@@ -174,7 +185,9 @@  discard block
 block discarded – undo
174 185
 			$dns = array();
175 186
 			foreach($domains as $domain)
176 187
 			{
177
-				if(preg_match_all('~(\*\.)~', $domain) > 1) throw new \RuntimeException('Cannot create orders with multiple wildcards in one domain.');
188
+				if(preg_match_all('~(\*\.)~', $domain) > 1) {
189
+					throw new \RuntimeException('Cannot create orders with multiple wildcards in one domain.');
190
+				}
178 191
 				$dns[] = array('type' => 'dns', 'value' => $domain);
179 192
 			}
180 193
 			$payload = array("identifiers" => $dns, 'notBefore' => $notBefore, 'notAfter' => $notAfter);
@@ -190,12 +203,10 @@  discard block
 block discarded – undo
190 203
 					if ($this->keyType == "rsa")
191 204
 					{
192 205
 						LEFunctions::RSAgenerateKeys(null, $this->certificateKeys['private_key'], $this->certificateKeys['public_key'], $this->keySize);
193
-					}
194
-					elseif ($this->keyType == "ec")
206
+					} elseif ($this->keyType == "ec")
195 207
 					{
196 208
 						LEFunctions::ECgenerateKeys(null, $this->certificateKeys['private_key'], $this->certificateKeys['public_key'], $this->keySize);
197
-					}
198
-					else
209
+					} else
199 210
 					{
200 211
 						throw new \RuntimeException('Key type \'' . $this->keyType . '\' not supported.');
201 212
 					}
@@ -205,22 +216,23 @@  discard block
 block discarded – undo
205 216
 					$this->identifiers = $post['body']['identifiers'];
206 217
 					$this->authorizationURLs = $post['body']['authorizations'];
207 218
 					$this->finalizeURL = $post['body']['finalize'];
208
-					if(array_key_exists('certificate', $post['body'])) $this->certificateURL = $post['body']['certificate'];
219
+					if(array_key_exists('certificate', $post['body'])) {
220
+						$this->certificateURL = $post['body']['certificate'];
221
+					}
209 222
 					$this->updateAuthorizations();
210 223
 
211
-					if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Created order for \'' . $this->basename . '\'.', 'function createOrder (function LEOrder __construct)');
212
-				}
213
-				else
224
+					if($this->log >= LECLient::LOG_STATUS) {
225
+						LEFunctions::log('Created order for \'' . $this->basename . '\'.', 'function createOrder (function LEOrder __construct)');
226
+					}
227
+				} else
214 228
 				{
215 229
 					throw new \RuntimeException('New-order returned invalid response.');
216 230
 				}
217
-			}
218
-			else
231
+			} else
219 232
 			{
220 233
 				throw new \RuntimeException('Creating new order failed.');
221 234
 			}
222
-		}
223
-		else
235
+		} else
224 236
 		{
225 237
 			throw new \RuntimeException('notBefore and notAfter fields must be empty or be a string similar to 0000-00-00T00:00:00Z');
226 238
 		}
@@ -239,12 +251,15 @@  discard block
 block discarded – undo
239 251
 			$this->identifiers = $get['body']['identifiers'];
240 252
 			$this->authorizationURLs = $get['body']['authorizations'];
241 253
 			$this->finalizeURL = $get['body']['finalize'];
242
-			if(array_key_exists('certificate', $get['body'])) $this->certificateURL = $get['body']['certificate'];
254
+			if(array_key_exists('certificate', $get['body'])) {
255
+				$this->certificateURL = $get['body']['certificate'];
256
+			}
243 257
 			$this->updateAuthorizations();
244
-		}
245
-		else
258
+		} else
246 259
 		{
247
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Cannot update data for order \'' . $this->basename . '\'.', 'function updateOrderData');
260
+			if($this->log >= LECLient::LOG_STATUS) {
261
+				LEFunctions::log('Cannot update data for order \'' . $this->basename . '\'.', 'function updateOrderData');
262
+			}
248 263
 		}
249 264
 	}
250 265
 
@@ -259,7 +274,9 @@  discard block
 block discarded – undo
259 274
 			if (filter_var($authURL, FILTER_VALIDATE_URL))
260 275
 			{
261 276
 				$auth = new LEAuthorization($this->connector, $this->log, $authURL);
262
-				if($auth != false) $this->authorizations[] = $auth;
277
+				if($auth != false) {
278
+					$this->authorizations[] = $auth;
279
+				}
263 280
 			}
264 281
 		}
265 282
 	}
@@ -275,7 +292,9 @@  discard block
 block discarded – undo
275 292
 		{
276 293
 			foreach($this->authorizations as $auth)
277 294
 			{
278
-				if($auth->status != 'valid') return false;
295
+				if($auth->status != 'valid') {
296
+					return false;
297
+				}
279 298
 			}
280 299
 			return true;
281 300
 		}
@@ -374,7 +393,9 @@  discard block
 block discarded – undo
374 393
 									$post = $this->connector->post($challenge['url'], $sign);
375 394
 									if(strpos($post['header'], "200 OK") !== false)
376 395
 									{
377
-										if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('HTTP challenge for \'' . $identifier . '\' valid.', 'function verifyPendingOrderAuthorization');
396
+										if($this->log >= LECLient::LOG_STATUS) {
397
+											LEFunctions::log('HTTP challenge for \'' . $identifier . '\' valid.', 'function verifyPendingOrderAuthorization');
398
+										}
378 399
 										while($auth->status == 'pending')
379 400
 										{
380 401
 											sleep(1);
@@ -382,10 +403,11 @@  discard block
 block discarded – undo
382 403
 										}
383 404
 										return true;
384 405
 									}
385
-								}
386
-								else
406
+								} else
387 407
 								{
388
-									if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('HTTP challenge for \'' . $identifier . '\' tested, found invalid.', 'function verifyPendingOrderAuthorization');
408
+									if($this->log >= LECLient::LOG_STATUS) {
409
+										LEFunctions::log('HTTP challenge for \'' . $identifier . '\' tested, found invalid.', 'function verifyPendingOrderAuthorization');
410
+									}
389 411
 								}
390 412
 								break;
391 413
 							case LEOrder::CHALLENGE_TYPE_DNS:
@@ -396,7 +418,9 @@  discard block
 block discarded – undo
396 418
 									$post = $this->connector->post($challenge['url'], $sign);
397 419
 									if(strpos($post['header'], "200 OK") !== false)
398 420
 									{
399
-										if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('DNS challenge for \'' . $identifier . '\' valid.', 'function verifyPendingOrderAuthorization');
421
+										if($this->log >= LECLient::LOG_STATUS) {
422
+											LEFunctions::log('DNS challenge for \'' . $identifier . '\' valid.', 'function verifyPendingOrderAuthorization');
423
+										}
400 424
 										while($auth->status == 'pending')
401 425
 										{
402 426
 											sleep(1);
@@ -404,10 +428,11 @@  discard block
 block discarded – undo
404 428
 										}
405 429
 										return true;
406 430
 									}
407
-								}
408
-								else
431
+								} else
409 432
 								{
410
-									if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('DNS challenge for \'' . $identifier . '\' tested, found invalid.', 'function verifyPendingOrderAuthorization');
433
+									if($this->log >= LECLient::LOG_STATUS) {
434
+										LEFunctions::log('DNS challenge for \'' . $identifier . '\' tested, found invalid.', 'function verifyPendingOrderAuthorization');
435
+									}
411 436
 								}
412 437
 								break;
413 438
 						}
@@ -435,13 +460,17 @@  discard block
 block discarded – undo
435 460
 				$post = $this->connector->post($auth->authorizationURL, $sign);
436 461
 				if(strpos($post['header'], "200 OK") !== false)
437 462
 				{
438
-					if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Authorization for \'' . $identifier . '\' deactivated.', 'function deactivateOrderAuthorization');
463
+					if($this->log >= LECLient::LOG_STATUS) {
464
+						LEFunctions::log('Authorization for \'' . $identifier . '\' deactivated.', 'function deactivateOrderAuthorization');
465
+					}
439 466
 					$this->updateAuthorizations();
440 467
 					return true;
441 468
 				}
442 469
 			}
443 470
 		}
444
-		if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('No authorization found for \'' . $identifier . '\', cannot deactivate.', 'function deactivateOrderAuthorization');
471
+		if($this->log >= LECLient::LOG_STATUS) {
472
+			LEFunctions::log('No authorization found for \'' . $identifier . '\', cannot deactivate.', 'function deactivateOrderAuthorization');
473
+		}
445 474
 		return false;
446 475
 	}
447 476
 
@@ -457,12 +486,10 @@  discard block
 block discarded – undo
457 486
 		if(in_array($this->basename, $domains))
458 487
 		{
459 488
 			$CN = $this->basename;
460
-		}
461
-		elseif(in_array('*.' . $this->basename, $domains))
489
+		} elseif(in_array('*.' . $this->basename, $domains))
462 490
 		{
463 491
 			$CN = '*.' . $this->basename;
464
-		}
465
-		else
492
+		} else
466 493
 		{
467 494
 			$CN = $domains[0];
468 495
 		}
@@ -512,8 +539,12 @@  discard block
 block discarded – undo
512 539
 		{
513 540
 			if($this->allAuthorizationsValid())
514 541
 			{
515
-				if(empty($csr)) $csr = $this->generateCSR();
516
-				if(preg_match('~-----BEGIN\sCERTIFICATE\sREQUEST-----(.*)-----END\sCERTIFICATE\sREQUEST-----~s', $csr, $matches)) $csr = $matches[1];
542
+				if(empty($csr)) {
543
+					$csr = $this->generateCSR();
544
+				}
545
+				if(preg_match('~-----BEGIN\sCERTIFICATE\sREQUEST-----(.*)-----END\sCERTIFICATE\sREQUEST-----~s', $csr, $matches)) {
546
+					$csr = $matches[1];
547
+				}
517 548
 				$csr = trim(LEFunctions::Base64UrlSafeEncode(base64_decode($csr)));
518 549
 				$sign = $this->connector->signRequestKid(array('csr' => $csr), $this->connector->accountURL, $this->finalizeURL);
519 550
 				$post = $this->connector->post($this->finalizeURL, $sign);
@@ -524,20 +555,26 @@  discard block
 block discarded – undo
524 555
 					$this->identifiers = $post['body']['identifiers'];
525 556
 					$this->authorizationURLs = $post['body']['authorizations'];
526 557
 					$this->finalizeURL = $post['body']['finalize'];
527
-					if(array_key_exists('certificate', $post['body'])) $this->certificateURL = $post['body']['certificate'];
558
+					if(array_key_exists('certificate', $post['body'])) {
559
+						$this->certificateURL = $post['body']['certificate'];
560
+					}
528 561
 					$this->updateAuthorizations();
529
-					if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Order for \'' . $this->basename . '\' finalized.', 'function finalizeOrder');
562
+					if($this->log >= LECLient::LOG_STATUS) {
563
+						LEFunctions::log('Order for \'' . $this->basename . '\' finalized.', 'function finalizeOrder');
564
+					}
530 565
 					return true;
531 566
 				}
532
-			}
533
-			else
567
+			} else
534 568
 			{
535
-				if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Not all authorizations are valid for \'' . $this->basename . '\'. Cannot finalize order.', 'function finalizeOrder');
569
+				if($this->log >= LECLient::LOG_STATUS) {
570
+					LEFunctions::log('Not all authorizations are valid for \'' . $this->basename . '\'. Cannot finalize order.', 'function finalizeOrder');
571
+				}
536 572
 			}
537
-		}
538
-		else
573
+		} else
539 574
 		{
540
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Order status for \'' . $this->basename . '\' is \'' . $this->status . '\'. Cannot finalize order.', 'function finalizeOrder');
575
+			if($this->log >= LECLient::LOG_STATUS) {
576
+				LEFunctions::log('Order status for \'' . $this->basename . '\' is \'' . $this->status . '\'. Cannot finalize order.', 'function finalizeOrder');
577
+			}
541 578
 		}
542 579
 		return false;
543 580
 	}
@@ -563,7 +600,9 @@  discard block
 block discarded – undo
563 600
 		$polling = 0;
564 601
 		while($this->status == 'processing' && $polling < 4)
565 602
 		{
566
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Certificate for \'' . $this->basename . '\' being processed. Retrying in 5 seconds...', 'function getCertificate');
603
+			if($this->log >= LECLient::LOG_STATUS) {
604
+				LEFunctions::log('Certificate for \'' . $this->basename . '\' being processed. Retrying in 5 seconds...', 'function getCertificate');
605
+			}
567 606
 			sleep(5);
568 607
 			$this->updateOrderData();
569 608
 			$polling++;
@@ -575,7 +614,9 @@  discard block
 block discarded – undo
575 614
 			{
576 615
 				if(preg_match_all('~(-----BEGIN\sCERTIFICATE-----[\s\S]+?-----END\sCERTIFICATE-----)~i', $get['body'], $matches))
577 616
 				{
578
-					if (isset($this->certificateKeys['certificate'])) file_put_contents($this->certificateKeys['certificate'],  $matches[0][0]);
617
+					if (isset($this->certificateKeys['certificate'])) {
618
+						file_put_contents($this->certificateKeys['certificate'],  $matches[0][0]);
619
+					}
579 620
 
580 621
 					if(count($matches[0]) > 1 && isset($this->certificateKeys['fullchain_certificate']))
581 622
 					{
@@ -587,22 +628,27 @@  discard block
 block discarded – undo
587 628
 						}
588 629
 						file_put_contents(trim($this->certificateKeys['fullchain_certificate']), $fullchain);
589 630
 					}
590
-					if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Certificate for \'' . $this->basename . '\' saved', 'function getCertificate');
631
+					if($this->log >= LECLient::LOG_STATUS) {
632
+						LEFunctions::log('Certificate for \'' . $this->basename . '\' saved', 'function getCertificate');
633
+					}
591 634
 					return true;
592
-				}
593
-				else
635
+				} else
594 636
 				{
595
-					if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Received invalid certificate for \'' . $this->basename . '\'. Cannot save certificate.', 'function getCertificate');
637
+					if($this->log >= LECLient::LOG_STATUS) {
638
+						LEFunctions::log('Received invalid certificate for \'' . $this->basename . '\'. Cannot save certificate.', 'function getCertificate');
639
+					}
596 640
 				}
597
-			}
598
-			else
641
+			} else
599 642
 			{
600
-				if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Invalid response for certificate request for \'' . $this->basename . '\'. Cannot save certificate.', 'function getCertificate');
643
+				if($this->log >= LECLient::LOG_STATUS) {
644
+					LEFunctions::log('Invalid response for certificate request for \'' . $this->basename . '\'. Cannot save certificate.', 'function getCertificate');
645
+				}
601 646
 			}
602
-		}
603
-		else
647
+		} else
604 648
 		{
605
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Order for \'' . $this->basename . '\' not valid. Cannot retrieve certificate.', 'function getCertificate');
649
+			if($this->log >= LECLient::LOG_STATUS) {
650
+				LEFunctions::log('Order for \'' . $this->basename . '\' not valid. Cannot retrieve certificate.', 'function getCertificate');
651
+			}
606 652
 		}
607 653
 		return false;
608 654
 	}
@@ -619,9 +665,13 @@  discard block
 block discarded – undo
619 665
 	{
620 666
 		if($this->status == 'valid')
621 667
 		{
622
-			if (isset($this->certificateKeys['certificate'])) $certFile = $this->certificateKeys['certificate'];
623
-			elseif (isset($this->certificateKeys['fullchain_certificate']))  $certFile = $this->certificateKeys['fullchain_certificate'];
624
-			else throw new \RuntimeException('certificateKeys[certificate] or certificateKeys[fullchain_certificate] required');
668
+			if (isset($this->certificateKeys['certificate'])) {
669
+				$certFile = $this->certificateKeys['certificate'];
670
+			} elseif (isset($this->certificateKeys['fullchain_certificate'])) {
671
+				$certFile = $this->certificateKeys['fullchain_certificate'];
672
+			} else {
673
+				throw new \RuntimeException('certificateKeys[certificate] or certificateKeys[fullchain_certificate] required');
674
+			}
625 675
 
626 676
 			if(file_exists($certFile) && file_exists($this->certificateKeys['private_key']))
627 677
 			{
@@ -633,22 +683,27 @@  discard block
 block discarded – undo
633 683
 				$post = $this->connector->post($this->connector->revokeCert, $sign);
634 684
 				if(strpos($post['header'], "200 OK") !== false)
635 685
 				{
636
-					if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Certificate for order \'' . $this->basename . '\' revoked.', 'function revokeCertificate');
686
+					if($this->log >= LECLient::LOG_STATUS) {
687
+						LEFunctions::log('Certificate for order \'' . $this->basename . '\' revoked.', 'function revokeCertificate');
688
+					}
637 689
 					return true;
638
-				}
639
-				else
690
+				} else
640 691
 				{
641
-					if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Certificate for order \'' . $this->basename . '\' cannot be revoked.', 'function revokeCertificate');
692
+					if($this->log >= LECLient::LOG_STATUS) {
693
+						LEFunctions::log('Certificate for order \'' . $this->basename . '\' cannot be revoked.', 'function revokeCertificate');
694
+					}
642 695
 				}
643
-			}
644
-			else
696
+			} else
645 697
 			{
646
-				if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Certificate for order \'' . $this->basename . '\' not found. Cannot revoke certificate.', 'function revokeCertificate');
698
+				if($this->log >= LECLient::LOG_STATUS) {
699
+					LEFunctions::log('Certificate for order \'' . $this->basename . '\' not found. Cannot revoke certificate.', 'function revokeCertificate');
700
+				}
647 701
 			}
648
-		}
649
-		else
702
+		} else
650 703
 		{
651
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Order for \'' . $this->basename . '\' not valid. Cannot revoke certificate.', 'function revokeCertificate');
704
+			if($this->log >= LECLient::LOG_STATUS) {
705
+				LEFunctions::log('Order for \'' . $this->basename . '\' not valid. Cannot revoke certificate.', 'function revokeCertificate');
706
+			}
652 707
 		}
653 708
 		return false;
654 709
 	}
Please login to merge, or discard this patch.
LEClient/src/LEAccount.php 1 patch
Braces   +26 added lines, -17 removed lines patch added patch discarded remove patch
@@ -65,15 +65,18 @@  discard block
 block discarded – undo
65 65
 
66 66
 		if(!file_exists($this->accountKeys['private_key']) OR !file_exists($this->accountKeys['public_key']))
67 67
 		{
68
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('No account found, attempting to create account.', 'function LEAccount __construct');
68
+			if($this->log >= LECLient::LOG_STATUS) {
69
+				LEFunctions::log('No account found, attempting to create account.', 'function LEAccount __construct');
70
+			}
69 71
 			LEFunctions::RSAgenerateKeys(null, $this->accountKeys['private_key'], $this->accountKeys['public_key']);
70 72
 			$this->connector->accountURL = $this->createLEAccount($email);
71
-		}
72
-		else
73
+		} else
73 74
 		{
74 75
 			$this->connector->accountURL = $this->getLEAccount();
75 76
 		}
76
-		if($this->connector->accountURL == false) throw new \RuntimeException('Account not found or deactivated.');
77
+		if($this->connector->accountURL == false) {
78
+			throw new \RuntimeException('Account not found or deactivated.');
79
+		}
77 80
 		$this->getLEAccountData();
78 81
 	}
79 82
 
@@ -92,7 +95,9 @@  discard block
 block discarded – undo
92 95
 		$post = $this->connector->post($this->connector->newAccount, $sign);
93 96
 		if(strpos($post['header'], "201 Created") !== false)
94 97
 		{
95
-			if(preg_match('~Location: (\S+)~i', $post['header'], $matches)) return trim($matches[1]);
98
+			if(preg_match('~Location: (\S+)~i', $post['header'], $matches)) {
99
+				return trim($matches[1]);
100
+			}
96 101
 		}
97 102
 		return false;
98 103
 	}
@@ -109,7 +114,9 @@  discard block
 block discarded – undo
109 114
 
110 115
 		if(strpos($post['header'], "200 OK") !== false)
111 116
 		{
112
-			if(preg_match('~Location: (\S+)~i', $post['header'], $matches)) return trim($matches[1]);
117
+			if(preg_match('~Location: (\S+)~i', $post['header'], $matches)) {
118
+				return trim($matches[1]);
119
+			}
113 120
 		}
114 121
 		return false;
115 122
 	}
@@ -130,8 +137,7 @@  discard block
 block discarded – undo
130 137
 			$this->initialIp = $post['body']['initialIp'];
131 138
 			$this->createdAt = $post['body']['createdAt'];
132 139
 			$this->status = $post['body']['status'];
133
-		}
134
-		else
140
+		} else
135 141
 		{
136 142
 			throw new \RuntimeException('Account data cannot be found.');
137 143
 		}
@@ -159,10 +165,11 @@  discard block
 block discarded – undo
159 165
 			$this->initialIp = $post['body']['initialIp'];
160 166
 			$this->createdAt = $post['body']['createdAt'];
161 167
 			$this->status = $post['body']['status'];
162
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Account data updated.', 'function updateAccount');
168
+			if($this->log >= LECLient::LOG_STATUS) {
169
+				LEFunctions::log('Account data updated.', 'function updateAccount');
170
+			}
163 171
 			return true;
164
-		}
165
-		else
172
+		} else
166 173
 		{
167 174
 			return false;
168 175
 		}
@@ -195,10 +202,11 @@  discard block
 block discarded – undo
195 202
 			rename($this->accountKeys['private_key'].'.new', $this->accountKeys['private_key']);
196 203
 			rename($this->accountKeys['public_key'].'.new', $this->accountKeys['public_key']);
197 204
 
198
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Account keys changed.', 'function changeAccountKey');
205
+			if($this->log >= LECLient::LOG_STATUS) {
206
+				LEFunctions::log('Account keys changed.', 'function changeAccountKey');
207
+			}
199 208
 			return true;
200
-		}
201
-		else
209
+		} else
202 210
 		{
203 211
 			return false;
204 212
 		}
@@ -216,9 +224,10 @@  discard block
 block discarded – undo
216 224
 		if(strpos($post['header'], "200 OK") !== false)
217 225
 		{
218 226
 			$this->connector->accountDeactivated = true;
219
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Account deactivated.', 'function deactivateAccount');
220
-		}
221
-		else
227
+			if($this->log >= LECLient::LOG_STATUS) {
228
+				LEFunctions::log('Account deactivated.', 'function deactivateAccount');
229
+			}
230
+		} else
222 231
 		{
223 232
 			return false;
224 233
 		}
Please login to merge, or discard this patch.
LEClient/src/LEFunctions.php 1 patch
Braces   +19 added lines, -10 removed lines patch added patch discarded remove patch
@@ -47,14 +47,18 @@  discard block
 block discarded – undo
47 47
 	public static function RSAGenerateKeys($directory, $privateKeyFile = 'private.pem', $publicKeyFile = 'public.pem', $keySize = 4096)
48 48
 	{
49 49
 
50
-		if ($keySize < 2048 || $keySize > 4096)  throw new \RuntimeException("RSA key size must be between 2048 and 4096");
50
+		if ($keySize < 2048 || $keySize > 4096) {
51
+			throw new \RuntimeException("RSA key size must be between 2048 and 4096");
52
+		}
51 53
 
52 54
 		$res = openssl_pkey_new(array(
53 55
 			"private_key_type" => OPENSSL_KEYTYPE_RSA,
54 56
 			"private_key_bits" => intval($keySize),
55 57
 		));
56 58
 
57
-		if(!openssl_pkey_export($res, $privateKey)) throw new \RuntimeException("RSA keypair export failed!");
59
+		if(!openssl_pkey_export($res, $privateKey)) {
60
+			throw new \RuntimeException("RSA keypair export failed!");
61
+		}
58 62
 
59 63
 		$details = openssl_pkey_get_details($res);
60 64
 
@@ -82,7 +86,9 @@  discard block
 block discarded – undo
82 86
      */
83 87
 	public static function ECGenerateKeys($directory, $privateKeyFile = 'private.pem', $publicKeyFile = 'public.pem', $keySize = 256)
84 88
 	{
85
-		if (version_compare(PHP_VERSION, '7.1.0') == -1) throw new \RuntimeException("PHP 7.1+ required for EC keys");
89
+		if (version_compare(PHP_VERSION, '7.1.0') == -1) {
90
+			throw new \RuntimeException("PHP 7.1+ required for EC keys");
91
+		}
86 92
 
87 93
 
88 94
 		if ($keySize == 256)
@@ -91,18 +97,20 @@  discard block
 block discarded – undo
91 97
 						"private_key_type" => OPENSSL_KEYTYPE_EC,
92 98
 						"curve_name" => "prime256v1",
93 99
 				));
94
-		}
95
-		elseif ($keySize == 384)
100
+		} elseif ($keySize == 384)
96 101
 		{
97 102
 				$res = openssl_pkey_new(array(
98 103
 						"private_key_type" => OPENSSL_KEYTYPE_EC,
99 104
 						"curve_name" => "secp384r1",
100 105
 				));
106
+		} else {
107
+			throw new \RuntimeException("EC key size must be 256 or 384");
101 108
 		}
102
-		else throw new \RuntimeException("EC key size must be 256 or 384");
103 109
 
104 110
 
105
-		if(!openssl_pkey_export($res, $privateKey)) throw new \RuntimeException("EC keypair export failed!");
111
+		if(!openssl_pkey_export($res, $privateKey)) {
112
+			throw new \RuntimeException("EC keypair export failed!");
113
+		}
106 114
 
107 115
 		$details = openssl_pkey_get_details($res);
108 116
 
@@ -167,8 +175,7 @@  discard block
 block discarded – undo
167 175
 			echo '[' . date('d-m-Y H:i:s') . '] ' . $function . ":\n";
168 176
 			print_r($data);
169 177
 			echo "\n\n";
170
-		}
171
-		else
178
+		} else
172 179
 		{
173 180
 			echo '<b>' . date('d-m-Y H:i:s') . ', ' . $function . ':</b><br>';
174 181
 			print_r($data);
@@ -212,7 +219,9 @@  discard block
 block discarded – undo
212 219
 		$records = dns_get_record($DNS, DNS_TXT);
213 220
 		foreach($records as $record)
214 221
 		{
215
-			if($record['host'] == $DNS && $record['type'] == 'TXT' && $record['txt'] == $DNSDigest) return true;
222
+			if($record['host'] == $DNS && $record['type'] == 'TXT' && $record['txt'] == $DNSDigest) {
223
+				return true;
224
+			}
216 225
 		}
217 226
 		return false;
218 227
 	}
Please login to merge, or discard this patch.
LEClient/src/LEConnector.php 1 patch
Braces   +20 added lines, -8 removed lines patch added patch discarded remove patch
@@ -86,7 +86,9 @@  discard block
 block discarded – undo
86 86
      */
87 87
 	private function getNewNonce()
88 88
 	{
89
-		if(strpos($this->head($this->newNonce)['header'], "204 No Content") == false) throw new \RuntimeException('No new nonce.');
89
+		if(strpos($this->head($this->newNonce)['header'], "204 No Content") == false) {
90
+			throw new \RuntimeException('No new nonce.');
91
+		}
90 92
 	}
91 93
 
92 94
     /**
@@ -100,7 +102,9 @@  discard block
 block discarded – undo
100 102
      */
101 103
 	private function request($method, $URL, $data = null)
102 104
 	{
103
-		if($this->accountDeactivated) throw new \RuntimeException('The account was deactivated. No further requests can be made.');
105
+		if($this->accountDeactivated) {
106
+			throw new \RuntimeException('The account was deactivated. No further requests can be made.');
107
+		}
104 108
 
105 109
 		$headers = array('Accept: application/json', 'Content-Type: application/json');
106 110
 		$requestURL = preg_match('~^http~', $URL) ? $URL : $this->baseURL . $URL;
@@ -137,7 +141,9 @@  discard block
 block discarded – undo
137 141
         $body = substr($response, $header_size);
138 142
 		$jsonbody = json_decode($body, true);
139 143
 		$jsonresponse = array('request' => $method . ' ' . $requestURL, 'header' => $header, 'body' => $jsonbody === null ? $body : $jsonbody);
140
-		if($this->log >= LECLient::LOG_DEBUG) LEFunctions::log($jsonresponse);
144
+		if($this->log >= LECLient::LOG_DEBUG) {
145
+			LEFunctions::log($jsonresponse);
146
+		}
141 147
 
142 148
 		if(	(($method == 'POST' OR $method == 'GET') AND strpos($header, "200 OK") === false AND strpos($header, "201 Created") === false) OR
143 149
 			($method == 'HEAD' AND strpos($header, "204 No Content") === false))
@@ -148,10 +154,12 @@  discard block
 block discarded – undo
148 154
 		if(preg_match('~Replay\-Nonce: (\S+)~i', $header, $matches))
149 155
 		{
150 156
 			$this->nonce = trim($matches[1]);
151
-		}
152
-		else
157
+		} else
153 158
 		{
154
-			if($method == 'POST') $this->getNewNonce(); // Not expecting a new nonce with GET and HEAD requests.
159
+			if($method == 'POST') {
160
+				$this->getNewNonce();
161
+			}
162
+			// Not expecting a new nonce with GET and HEAD requests.
155 163
 		}
156 164
 
157 165
         return $jsonresponse;
@@ -205,7 +213,9 @@  discard block
 block discarded – undo
205 213
      */
206 214
 	public function signRequestJWK($payload, $url, $privateKeyFile = '')
207 215
     {
208
-		if($privateKeyFile == '') $privateKeyFile = $this->accountKeys['private_key'];
216
+		if($privateKeyFile == '') {
217
+			$privateKeyFile = $this->accountKeys['private_key'];
218
+		}
209 219
 		$privateKey = openssl_pkey_get_private(file_get_contents($privateKeyFile));
210 220
         $details = openssl_pkey_get_details($privateKey);
211 221
 
@@ -247,7 +257,9 @@  discard block
 block discarded – undo
247 257
      */
248 258
 	public function signRequestKid($payload, $kid, $url, $privateKeyFile = '')
249 259
     {
250
-		if($privateKeyFile == '') $privateKeyFile = $this->accountKeys['private_key'];
260
+		if($privateKeyFile == '') {
261
+			$privateKeyFile = $this->accountKeys['private_key'];
262
+		}
251 263
         $privateKey = openssl_pkey_get_private(file_get_contents($privateKeyFile));
252 264
         $details = openssl_pkey_get_details($privateKey);
253 265
 
Please login to merge, or discard this patch.
LEClient/src/LEAuthorization.php 1 patch
Braces   +11 added lines, -7 removed lines patch added patch discarded remove patch
@@ -66,10 +66,11 @@  discard block
 block discarded – undo
66 66
 			$this->status = $get['body']['status'];
67 67
 			$this->expires = $get['body']['expires'];
68 68
 			$this->challenges = $get['body']['challenges'];
69
-		}
70
-		else
69
+		} else
71 70
 		{
72
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Cannot find authorization \'' . $authorizationURL . '\'.', 'function LEAuthorization __construct');
71
+			if($this->log >= LECLient::LOG_STATUS) {
72
+				LEFunctions::log('Cannot find authorization \'' . $authorizationURL . '\'.', 'function LEAuthorization __construct');
73
+			}
73 74
 		}
74 75
 	}
75 76
 	
@@ -86,10 +87,11 @@  discard block
 block discarded – undo
86 87
 			$this->status = $get['body']['status'];
87 88
 			$this->expires = $get['body']['expires'];
88 89
 			$this->challenges = $get['body']['challenges'];
89
-		}
90
-		else
90
+		} else
91 91
 		{
92
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Cannot find authorization \'' . $authorizationURL . '\'.', 'function updateData');
92
+			if($this->log >= LECLient::LOG_STATUS) {
93
+				LEFunctions::log('Cannot find authorization \'' . $authorizationURL . '\'.', 'function updateData');
94
+			}
93 95
 		}
94 96
 	}
95 97
 	
@@ -105,7 +107,9 @@  discard block
 block discarded – undo
105 107
 	{
106 108
 		foreach($this->challenges as $challenge)
107 109
 		{
108
-			if($challenge['type'] == $type) return $challenge;
110
+			if($challenge['type'] == $type) {
111
+				return $challenge;
112
+			}
109 113
 		}
110 114
 		throw new \RuntimeException('No challenge found for type \'' . $type . '\' and identifier \'' . $this->identifier['value'] . '\'.');
111 115
 	}
Please login to merge, or discard this patch.
exampleDNSFinish.php 1 patch
Braces   +7 added lines, -3 removed lines patch added patch discarded remove patch
@@ -34,8 +34,12 @@
 block discarded – undo
34 34
 if($order->allAuthorizationsValid())
35 35
 {
36 36
 	// Finalize the order first, if that is not yet done.
37
-	if(!$order->isFinalized()) $order->finalizeOrder();
37
+	if(!$order->isFinalized()) {
38
+		$order->finalizeOrder();
39
+	}
38 40
 	// Check whether the order has been finalized before we can get the certificate. If finalized, get the certificate.
39
-	if($order->isFinalized()) $order->getCertificate();
40
-}
41
+	if($order->isFinalized()) {
42
+		$order->getCertificate();
43
+	}
44
+	}
41 45
 ?>
42 46
\ No newline at end of file
Please login to merge, or discard this patch.