Passed
Branch master (52717f)
by John
02:35
created
exampleHTTP.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -16,19 +16,19 @@  discard block
 block discarded – undo
16 16
 // Initiating the order instance. The keys and certificate will be stored in /example.org/ (argument 1) and the domains in the array (argument 2) will be on the certificate.
17 17
 $order = $client->getOrCreateOrder($basename, $domains);
18 18
 // Check whether there are any authorizations pending. If that is the case, try to verify the pending authorizations.
19
-if(!$order->allAuthorizationsValid())
19
+if (!$order->allAuthorizationsValid())
20 20
 {
21 21
 	// Get the HTTP challenges from the pending authorizations.
22 22
 	$pending = $order->getPendingAuthorizations(LEOrder::CHALLENGE_TYPE_HTTP);
23 23
 	// Walk the list of pending authorization HTTP challenges.
24
-	if(!empty($pending))
24
+	if (!empty($pending))
25 25
 	{
26
-		foreach($pending as $challenge)
26
+		foreach ($pending as $challenge)
27 27
 		{
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)) mkdir($folder, 0777, true);
32 32
 			// Store the challenge file for this domain.
33 33
 			file_put_contents($folder . $challenge['filename'], $challenge['content']);
34 34
 			// Let LetsEncrypt verify this challenge.
@@ -37,11 +37,11 @@  discard block
 block discarded – undo
37 37
 	}
38 38
 }
39 39
 // Check once more whether all authorizations are valid before we can finalize the order.
40
-if($order->allAuthorizationsValid())
40
+if ($order->allAuthorizationsValid())
41 41
 {
42 42
 	// Finalize the order first, if that is not yet done.
43
-	if(!$order->isFinalized()) $order->finalizeOrder();
43
+	if (!$order->isFinalized()) $order->finalizeOrder();
44 44
 	// Check whether the order has been finalized before we can get the certificate. If finalized, get the certificate.
45
-	if($order->isFinalized()) $order->getCertificate();
45
+	if ($order->isFinalized()) $order->getCertificate();
46 46
 }
47 47
 ?>
48 48
\ No newline at end of file
Please login to merge, or discard this 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 2 patches
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -56,9 +56,9 @@  discard block
 block discarded – undo
56 56
 
57 57
 	private $log;
58 58
 
59
-	const LOG_OFF = 0;		// Logs no messages or faults, except Runtime Exceptions.
60
-	const LOG_STATUS = 1;	// Logs only messages and faults.
61
-	const LOG_DEBUG = 2;	// Logs messages, faults and raw responses from HTTP requests.
59
+	const LOG_OFF = 0; // Logs no messages or faults, except Runtime Exceptions.
60
+	const LOG_STATUS = 1; // Logs only messages and faults.
61
+	const LOG_DEBUG = 2; // Logs messages, faults and raw responses from HTTP requests.
62 62
 
63 63
     /**
64 64
      * Initiates the LetsEncrypt main client.
@@ -95,18 +95,18 @@  discard block
 block discarded – undo
95 95
 
96 96
 			$certificateKeysDir = $certificateKeys;
97 97
 
98
-			if(!file_exists($certificateKeys))
98
+			if (!file_exists($certificateKeys))
99 99
 			{
100 100
 				mkdir($certificateKeys, 0777, true);
101 101
 				LEFunctions::createhtaccess($certificateKeys);
102 102
 			}
103 103
 
104 104
 			$this->certificateKeys = array(
105
-				"public_key" => $certificateKeys.'/public.pem',
106
-				"private_key" => $certificateKeys.'/private.pem',
107
-				"certificate" => $certificateKeys.'/certificate.crt',
108
-				"fullchain_certificate" => $certificateKeys.'/fullchain.crt',
109
-				"order" => $certificateKeys.'/order'
105
+				"public_key" => $certificateKeys . '/public.pem',
106
+				"private_key" => $certificateKeys . '/private.pem',
107
+				"certificate" => $certificateKeys . '/certificate.crt',
108
+				"fullchain_certificate" => $certificateKeys . '/fullchain.crt',
109
+				"order" => $certificateKeys . '/order'
110 110
 			);
111 111
 
112 112
 		}
@@ -115,12 +115,12 @@  discard block
 block discarded – undo
115 115
 
116 116
 			if (!isset($certificateKeys['certificate']) && !isset($certificateKeys['fullchain_certificate'])) throw new \RuntimeException('certificateKeys[certificate] or certificateKeys[fullchain_certificate] file path must be set');
117 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';
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';
120 120
 
121 121
 			foreach ($certificateKeys as $param => $file) {
122 122
 				$parentDir = dirname($file);
123
-				if (!is_dir($parentDir)) throw new \RuntimeException($parentDir.' directory not found');
123
+				if (!is_dir($parentDir)) throw new \RuntimeException($parentDir . ' directory not found');
124 124
 			}
125 125
 
126 126
 			$this->certificateKeys = $certificateKeys;
@@ -134,17 +134,17 @@  discard block
 block discarded – undo
134 134
 		if (is_string($accountKeys))
135 135
 		{
136 136
 
137
-			$accountKeys = $certificateKeysDir.'/'.$accountKeys;
137
+			$accountKeys = $certificateKeysDir . '/' . $accountKeys;
138 138
 
139
-			if(!file_exists($accountKeys))
139
+			if (!file_exists($accountKeys))
140 140
 			{
141 141
 				mkdir($accountKeys, 0777, true);
142 142
 				LEFunctions::createhtaccess($accountKeys);
143 143
 			}
144 144
 
145 145
 			$this->accountKeys = array(
146
-				"private_key" => $accountKeys.'/private.pem',
147
-				"public_key" => $accountKeys.'/public.pem'
146
+				"private_key" => $accountKeys . '/private.pem',
147
+				"public_key" => $accountKeys . '/public.pem'
148 148
 			);
149 149
 		}
150 150
 		elseif (is_array($accountKeys))
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 
155 155
 			foreach ($accountKeys as $param => $file) {
156 156
 				$parentDir = dirname($file);
157
-				if (!is_dir($parentDir)) throw new \RuntimeException($parentDir.' directory not found');
157
+				if (!is_dir($parentDir)) throw new \RuntimeException($parentDir . ' directory not found');
158 158
 			}
159 159
 
160 160
 			$this->accountKeys = $accountKeys;
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
 
168 168
 		$this->connector = new LEConnector($this->log, $this->baseURL, $this->accountKeys);
169 169
 		$this->account = new LEAccount($this->connector, $this->log, $email, $this->accountKeys);
170
-		if($this->log) LEFunctions::log('LEClient finished constructing', 'function LEClient __construct');
170
+		if ($this->log) LEFunctions::log('LEClient finished constructing', 'function LEClient __construct');
171 171
 	}
172 172
 
173 173
 
Please login to merge, or discard this 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 2 patches
Spacing   +83 added lines, -83 removed lines patch added patch discarded remove patch
@@ -100,23 +100,23 @@  discard block
 block discarded – undo
100 100
 
101 101
 		$this->certificateKeys = $certificateKeys;
102 102
 
103
-		if(file_exists($this->certificateKeys['private_key']) AND file_exists($this->certificateKeys['order']) AND file_exists($this->certificateKeys['public_key']))
103
+		if (file_exists($this->certificateKeys['private_key']) AND file_exists($this->certificateKeys['order']) AND file_exists($this->certificateKeys['public_key']))
104 104
 		{
105 105
 			$this->orderURL = file_get_contents($this->certificateKeys['order']);
106 106
 			if (filter_var($this->orderURL, FILTER_VALIDATE_URL))
107 107
 			{
108 108
 				$get = $this->connector->get($this->orderURL);
109
-				if(strpos($get['header'], "200 OK") !== false)
109
+				if (strpos($get['header'], "200 OK") !== false)
110 110
 				{
111 111
 					$orderdomains = array_map(function($ident) { return $ident['value']; }, $get['body']['identifiers']);
112 112
 					$diff = array_merge(array_diff($orderdomains, $domains), array_diff($domains, $orderdomains));
113
-					if(!empty($diff))
113
+					if (!empty($diff))
114 114
 					{
115 115
 						foreach ($this->certificateKeys as $file)
116 116
 						{
117
-							if (is_file($file)) rename($file, $file.'.old');
117
+							if (is_file($file)) rename($file, $file . '.old');
118 118
 						}
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');
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 120
 						$this->createOrder($domains, $notBefore, $notAfter, $keyType);
121 121
 					}
122 122
 					else
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
 						$this->identifiers = $get['body']['identifiers'];
127 127
 						$this->authorizationURLs = $get['body']['authorizations'];
128 128
 						$this->finalizeURL = $get['body']['finalize'];
129
-						if(array_key_exists('certificate', $get['body'])) $this->certificateURL = $get['body']['certificate'];
129
+						if (array_key_exists('certificate', $get['body'])) $this->certificateURL = $get['body']['certificate'];
130 130
 						$this->updateAuthorizations();
131 131
 					}
132 132
 				}
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
 					{
137 137
 						if (is_file($file)) unlink($file);
138 138
 					}
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');
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 140
 					$this->createOrder($domains, $notBefore, $notAfter);
141 141
 				}
142 142
 			}
@@ -147,14 +147,14 @@  discard block
 block discarded – undo
147 147
 				{
148 148
 					if (is_file($file)) unlink($file);
149 149
 				}
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');
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 151
 
152 152
 				$this->createOrder($domains, $notBefore, $notAfter);
153 153
 			}
154 154
 		}
155 155
 		else
156 156
 		{
157
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('No order found for \'' . $this->basename . '\'. Creating new order.', 'function LEOrder __construct');
157
+			if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('No order found for \'' . $this->basename . '\'. Creating new order.', 'function LEOrder __construct');
158 158
 			$this->createOrder($domains, $notBefore, $notAfter);
159 159
 		}
160 160
 	}
@@ -168,22 +168,22 @@  discard block
 block discarded – undo
168 168
      */
169 169
 	private function createOrder($domains, $notBefore, $notAfter)
170 170
 	{
171
-		if(preg_match('~(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z|^$)~', $notBefore) AND preg_match('~(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z|^$)~', $notAfter))
171
+		if (preg_match('~(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z|^$)~', $notBefore) AND preg_match('~(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z|^$)~', $notAfter))
172 172
 		{
173 173
 
174 174
 			$dns = array();
175
-			foreach($domains as $domain)
175
+			foreach ($domains as $domain)
176 176
 			{
177
-				if(preg_match_all('~(\*\.)~', $domain) > 1) throw new \RuntimeException('Cannot create orders with multiple wildcards in one domain.');
177
+				if (preg_match_all('~(\*\.)~', $domain) > 1) throw new \RuntimeException('Cannot create orders with multiple wildcards in one domain.');
178 178
 				$dns[] = array('type' => 'dns', 'value' => $domain);
179 179
 			}
180 180
 			$payload = array("identifiers" => $dns, 'notBefore' => $notBefore, 'notAfter' => $notAfter);
181 181
 			$sign = $this->connector->signRequestKid($payload, $this->connector->accountURL, $this->connector->newOrder);
182 182
 			$post = $this->connector->post($this->connector->newOrder, $sign);
183 183
 
184
-			if(strpos($post['header'], "201 Created") !== false)
184
+			if (strpos($post['header'], "201 Created") !== false)
185 185
 			{
186
-				if(preg_match('~Location: (\S+)~i', $post['header'], $matches))
186
+				if (preg_match('~Location: (\S+)~i', $post['header'], $matches))
187 187
 				{
188 188
 					$this->orderURL = trim($matches[1]);
189 189
 					file_put_contents($this->certificateKeys['order'], $this->orderURL);
@@ -205,10 +205,10 @@  discard block
 block discarded – undo
205 205
 					$this->identifiers = $post['body']['identifiers'];
206 206
 					$this->authorizationURLs = $post['body']['authorizations'];
207 207
 					$this->finalizeURL = $post['body']['finalize'];
208
-					if(array_key_exists('certificate', $post['body'])) $this->certificateURL = $post['body']['certificate'];
208
+					if (array_key_exists('certificate', $post['body'])) $this->certificateURL = $post['body']['certificate'];
209 209
 					$this->updateAuthorizations();
210 210
 
211
-					if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Created order for \'' . $this->basename . '\'.', 'function createOrder (function LEOrder __construct)');
211
+					if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Created order for \'' . $this->basename . '\'.', 'function createOrder (function LEOrder __construct)');
212 212
 				}
213 213
 				else
214 214
 				{
@@ -232,19 +232,19 @@  discard block
 block discarded – undo
232 232
 	private function updateOrderData()
233 233
 	{
234 234
 		$get = $this->connector->get($this->orderURL);
235
-		if(strpos($get['header'], "200 OK") !== false)
235
+		if (strpos($get['header'], "200 OK") !== false)
236 236
 		{
237 237
 			$this->status = $get['body']['status'];
238 238
 			$this->expires = $get['body']['expires'];
239 239
 			$this->identifiers = $get['body']['identifiers'];
240 240
 			$this->authorizationURLs = $get['body']['authorizations'];
241 241
 			$this->finalizeURL = $get['body']['finalize'];
242
-			if(array_key_exists('certificate', $get['body'])) $this->certificateURL = $get['body']['certificate'];
242
+			if (array_key_exists('certificate', $get['body'])) $this->certificateURL = $get['body']['certificate'];
243 243
 			$this->updateAuthorizations();
244 244
 		}
245 245
 		else
246 246
 		{
247
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Cannot update data for order \'' . $this->basename . '\'.', 'function updateOrderData');
247
+			if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Cannot update data for order \'' . $this->basename . '\'.', 'function updateOrderData');
248 248
 		}
249 249
 	}
250 250
 
@@ -254,12 +254,12 @@  discard block
 block discarded – undo
254 254
 	private function updateAuthorizations()
255 255
 	{
256 256
 		$this->authorizations = array();
257
-		foreach($this->authorizationURLs as $authURL)
257
+		foreach ($this->authorizationURLs as $authURL)
258 258
 		{
259 259
 			if (filter_var($authURL, FILTER_VALIDATE_URL))
260 260
 			{
261 261
 				$auth = new LEAuthorization($this->connector, $this->log, $authURL);
262
-				if($auth != false) $this->authorizations[] = $auth;
262
+				if ($auth != false) $this->authorizations[] = $auth;
263 263
 			}
264 264
 		}
265 265
 	}
@@ -271,11 +271,11 @@  discard block
 block discarded – undo
271 271
      */
272 272
 	public function allAuthorizationsValid()
273 273
 	{
274
-		if(count($this->authorizations) > 0)
274
+		if (count($this->authorizations) > 0)
275 275
 		{
276
-			foreach($this->authorizations as $auth)
276
+			foreach ($this->authorizations as $auth)
277 277
 			{
278
-				if($auth->status != 'valid') return false;
278
+				if ($auth->status != 'valid') return false;
279 279
 			}
280 280
 			return true;
281 281
 		}
@@ -308,15 +308,15 @@  discard block
 block discarded – undo
308 308
 		);
309 309
 		$digest = LEFunctions::Base64UrlSafeEncode(hash('sha256', json_encode($header), true));
310 310
 
311
-		foreach($this->authorizations as $auth)
311
+		foreach ($this->authorizations as $auth)
312 312
 		{
313
-			if($auth->status == 'pending')
313
+			if ($auth->status == 'pending')
314 314
 			{
315 315
 				$challenge = $auth->getChallenge($type);
316
-				if($challenge['status'] == 'pending')
316
+				if ($challenge['status'] == 'pending')
317 317
 				{
318 318
 					$keyAuthorization = $challenge['token'] . '.' . $digest;
319
-					switch(strtolower($type))
319
+					switch (strtolower($type))
320 320
 					{
321 321
 						case LEOrder::CHALLENGE_TYPE_HTTP:
322 322
 							$authorizations[] = array('type' => LEOrder::CHALLENGE_TYPE_HTTP, 'identifier' => $auth->identifier['value'], 'filename' => $challenge['token'], 'content' => $keyAuthorization);
@@ -355,27 +355,27 @@  discard block
 block discarded – undo
355 355
 		);
356 356
 		$digest = LEFunctions::Base64UrlSafeEncode(hash('sha256', json_encode($header), true));
357 357
 
358
-		foreach($this->authorizations as $auth)
358
+		foreach ($this->authorizations as $auth)
359 359
 		{
360
-			if($auth->identifier['value'] == $identifier)
360
+			if ($auth->identifier['value'] == $identifier)
361 361
 			{
362
-				if($auth->status == 'pending')
362
+				if ($auth->status == 'pending')
363 363
 				{
364 364
 					$challenge = $auth->getChallenge($type);
365
-					if($challenge['status'] == 'pending')
365
+					if ($challenge['status'] == 'pending')
366 366
 					{
367 367
 						$keyAuthorization = $challenge['token'] . '.' . $digest;
368
-						switch($type)
368
+						switch ($type)
369 369
 						{
370 370
 							case LEOrder::CHALLENGE_TYPE_HTTP:
371
-								if(LEFunctions::checkHTTPChallenge($identifier, $challenge['token'], $keyAuthorization))
371
+								if (LEFunctions::checkHTTPChallenge($identifier, $challenge['token'], $keyAuthorization))
372 372
 								{
373 373
 									$sign = $this->connector->signRequestKid(array('keyAuthorization' => $keyAuthorization), $this->connector->accountURL, $challenge['url']);
374 374
 									$post = $this->connector->post($challenge['url'], $sign);
375
-									if(strpos($post['header'], "200 OK") !== false)
375
+									if (strpos($post['header'], "200 OK") !== false)
376 376
 									{
377
-										if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('HTTP challenge for \'' . $identifier . '\' valid.', 'function verifyPendingOrderAuthorization');
378
-										while($auth->status == 'pending')
377
+										if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('HTTP challenge for \'' . $identifier . '\' valid.', 'function verifyPendingOrderAuthorization');
378
+										while ($auth->status == 'pending')
379 379
 										{
380 380
 											sleep(1);
381 381
 											$auth->updateData();
@@ -385,19 +385,19 @@  discard block
 block discarded – undo
385 385
 								}
386 386
 								else
387 387
 								{
388
-									if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('HTTP challenge for \'' . $identifier . '\' tested, found invalid.', 'function verifyPendingOrderAuthorization');
388
+									if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('HTTP challenge for \'' . $identifier . '\' tested, found invalid.', 'function verifyPendingOrderAuthorization');
389 389
 								}
390 390
 								break;
391 391
 							case LEOrder::CHALLENGE_TYPE_DNS:
392 392
 								$DNSDigest = LEFunctions::Base64UrlSafeEncode(hash('sha256', $keyAuthorization, true));
393
-								if(LEFunctions::checkDNSChallenge($identifier, $DNSDigest))
393
+								if (LEFunctions::checkDNSChallenge($identifier, $DNSDigest))
394 394
 								{
395 395
 									$sign = $this->connector->signRequestKid(array('keyAuthorization' => $keyAuthorization), $this->connector->accountURL, $challenge['url']);
396 396
 									$post = $this->connector->post($challenge['url'], $sign);
397
-									if(strpos($post['header'], "200 OK") !== false)
397
+									if (strpos($post['header'], "200 OK") !== false)
398 398
 									{
399
-										if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('DNS challenge for \'' . $identifier . '\' valid.', 'function verifyPendingOrderAuthorization');
400
-										while($auth->status == 'pending')
399
+										if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('DNS challenge for \'' . $identifier . '\' valid.', 'function verifyPendingOrderAuthorization');
400
+										while ($auth->status == 'pending')
401 401
 										{
402 402
 											sleep(1);
403 403
 											$auth->updateData();
@@ -407,7 +407,7 @@  discard block
 block discarded – undo
407 407
 								}
408 408
 								else
409 409
 								{
410
-									if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('DNS challenge for \'' . $identifier . '\' tested, found invalid.', 'function verifyPendingOrderAuthorization');
410
+									if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('DNS challenge for \'' . $identifier . '\' tested, found invalid.', 'function verifyPendingOrderAuthorization');
411 411
 								}
412 412
 								break;
413 413
 						}
@@ -427,21 +427,21 @@  discard block
 block discarded – undo
427 427
      */
428 428
 	public function deactivateOrderAuthorization($identifier)
429 429
 	{
430
-		foreach($this->authorizations as $auth)
430
+		foreach ($this->authorizations as $auth)
431 431
 		{
432
-			if($auth->identifier['value'] == $identifier)
432
+			if ($auth->identifier['value'] == $identifier)
433 433
 			{
434 434
 				$sign = $this->connector->signRequestKid(array('status' => 'deactivated'), $this->connector->accountURL, $auth->authorizationURL);
435 435
 				$post = $this->connector->post($auth->authorizationURL, $sign);
436
-				if(strpos($post['header'], "200 OK") !== false)
436
+				if (strpos($post['header'], "200 OK") !== false)
437 437
 				{
438
-					if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Authorization for \'' . $identifier . '\' deactivated.', 'function deactivateOrderAuthorization');
438
+					if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Authorization for \'' . $identifier . '\' deactivated.', 'function deactivateOrderAuthorization');
439 439
 					$this->updateAuthorizations();
440 440
 					return true;
441 441
 				}
442 442
 			}
443 443
 		}
444
-		if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('No authorization found for \'' . $identifier . '\', cannot deactivate.', 'function deactivateOrderAuthorization');
444
+		if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('No authorization found for \'' . $identifier . '\', cannot deactivate.', 'function deactivateOrderAuthorization');
445 445
 		return false;
446 446
 	}
447 447
 
@@ -453,12 +453,12 @@  discard block
 block discarded – undo
453 453
      */
454 454
 	public function generateCSR()
455 455
 	{
456
-		$domains = array_map(function ($dns) { return $dns['value']; }, $this->identifiers);
457
-		if(in_array($this->basename, $domains))
456
+		$domains = array_map(function($dns) { return $dns['value']; }, $this->identifiers);
457
+		if (in_array($this->basename, $domains))
458 458
 		{
459 459
 			$CN = $this->basename;
460 460
 		}
461
-		elseif(in_array('*.' . $this->basename, $domains))
461
+		elseif (in_array('*.' . $this->basename, $domains))
462 462
 		{
463 463
 			$CN = '*.' . $this->basename;
464 464
 		}
@@ -471,7 +471,7 @@  discard block
 block discarded – undo
471 471
 			"commonName" => $CN
472 472
 		);
473 473
 
474
-		$san = implode(",", array_map(function ($dns) {
474
+		$san = implode(",", array_map(function($dns) {
475 475
             return "DNS:" . $dns;
476 476
         }, $domains));
477 477
         $tmpConf = tmpfile();
@@ -495,7 +495,7 @@  discard block
 block discarded – undo
495 495
 
496 496
 		$privateKey = openssl_pkey_get_private(file_get_contents($this->certificateKeys['private_key']));
497 497
 		$csr = openssl_csr_new($dn, $privateKey, array('config' => $tmpConfPath, 'digest_alg' => 'sha256'));
498
-		openssl_csr_export ($csr, $csr);
498
+		openssl_csr_export($csr, $csr);
499 499
 		return $csr;
500 500
 	}
501 501
 
@@ -508,36 +508,36 @@  discard block
 block discarded – undo
508 508
      */
509 509
 	public function finalizeOrder($csr = '')
510 510
 	{
511
-		if($this->status == 'pending')
511
+		if ($this->status == 'pending')
512 512
 		{
513
-			if($this->allAuthorizationsValid())
513
+			if ($this->allAuthorizationsValid())
514 514
 			{
515
-				if(empty($csr)) $csr = $this->generateCSR();
516
-				if(preg_match('~-----BEGIN\sCERTIFICATE\sREQUEST-----(.*)-----END\sCERTIFICATE\sREQUEST-----~s', $csr, $matches)) $csr = $matches[1];
515
+				if (empty($csr)) $csr = $this->generateCSR();
516
+				if (preg_match('~-----BEGIN\sCERTIFICATE\sREQUEST-----(.*)-----END\sCERTIFICATE\sREQUEST-----~s', $csr, $matches)) $csr = $matches[1];
517 517
 				$csr = trim(LEFunctions::Base64UrlSafeEncode(base64_decode($csr)));
518 518
 				$sign = $this->connector->signRequestKid(array('csr' => $csr), $this->connector->accountURL, $this->finalizeURL);
519 519
 				$post = $this->connector->post($this->finalizeURL, $sign);
520
-				if(strpos($post['header'], "200 OK") !== false)
520
+				if (strpos($post['header'], "200 OK") !== false)
521 521
 				{
522 522
 					$this->status = $post['body']['status'];
523 523
 					$this->expires = $post['body']['expires'];
524 524
 					$this->identifiers = $post['body']['identifiers'];
525 525
 					$this->authorizationURLs = $post['body']['authorizations'];
526 526
 					$this->finalizeURL = $post['body']['finalize'];
527
-					if(array_key_exists('certificate', $post['body'])) $this->certificateURL = $post['body']['certificate'];
527
+					if (array_key_exists('certificate', $post['body'])) $this->certificateURL = $post['body']['certificate'];
528 528
 					$this->updateAuthorizations();
529
-					if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Order for \'' . $this->basename . '\' finalized.', 'function finalizeOrder');
529
+					if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Order for \'' . $this->basename . '\' finalized.', 'function finalizeOrder');
530 530
 					return true;
531 531
 				}
532 532
 			}
533 533
 			else
534 534
 			{
535
-				if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Not all authorizations are valid for \'' . $this->basename . '\'. Cannot finalize order.', 'function finalizeOrder');
535
+				if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Not all authorizations are valid for \'' . $this->basename . '\'. Cannot finalize order.', 'function finalizeOrder');
536 536
 			}
537 537
 		}
538 538
 		else
539 539
 		{
540
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Order status for \'' . $this->basename . '\' is \'' . $this->status . '\'. Cannot finalize order.', 'function finalizeOrder');
540
+			if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Order status for \'' . $this->basename . '\' is \'' . $this->status . '\'. Cannot finalize order.', 'function finalizeOrder');
541 541
 		}
542 542
 		return false;
543 543
 	}
@@ -561,48 +561,48 @@  discard block
 block discarded – undo
561 561
 	public function getCertificate()
562 562
 	{
563 563
 		$polling = 0;
564
-		while($this->status == 'processing' && $polling < 4)
564
+		while ($this->status == 'processing' && $polling < 4)
565 565
 		{
566
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Certificate for \'' . $this->basename . '\' being processed. Retrying in 5 seconds...', 'function getCertificate');
566
+			if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Certificate for \'' . $this->basename . '\' being processed. Retrying in 5 seconds...', 'function getCertificate');
567 567
 			sleep(5);
568 568
 			$this->updateOrderData();
569 569
 			$polling++;
570 570
 		}
571
-		if($this->status == 'valid' && !empty($this->certificateURL))
571
+		if ($this->status == 'valid' && !empty($this->certificateURL))
572 572
 		{
573 573
 			$get = $this->connector->get($this->certificateURL);
574
-			if(strpos($get['header'], "200 OK") !== false)
574
+			if (strpos($get['header'], "200 OK") !== false)
575 575
 			{
576
-				if(preg_match_all('~(-----BEGIN\sCERTIFICATE-----[\s\S]+?-----END\sCERTIFICATE-----)~i', $get['body'], $matches))
576
+				if (preg_match_all('~(-----BEGIN\sCERTIFICATE-----[\s\S]+?-----END\sCERTIFICATE-----)~i', $get['body'], $matches))
577 577
 				{
578
-					if (isset($this->certificateKeys['certificate'])) file_put_contents($this->certificateKeys['certificate'],  $matches[0][0]);
578
+					if (isset($this->certificateKeys['certificate'])) file_put_contents($this->certificateKeys['certificate'], $matches[0][0]);
579 579
 
580
-					if(count($matches[0]) > 1 && isset($this->certificateKeys['fullchain_certificate']))
580
+					if (count($matches[0]) > 1 && isset($this->certificateKeys['fullchain_certificate']))
581 581
 					{
582
-						$fullchain = $matches[0][0]."\n";
583
-						for($i=1;$i<count($matches[0]);$i++)
582
+						$fullchain = $matches[0][0] . "\n";
583
+						for ($i = 1; $i < count($matches[0]); $i++)
584 584
 						{
585
-							$fullchain .= $matches[0][$i]."\n";
585
+							$fullchain .= $matches[0][$i] . "\n";
586 586
 
587 587
 						}
588 588
 						file_put_contents(trim($this->certificateKeys['fullchain_certificate']), $fullchain);
589 589
 					}
590
-					if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Certificate for \'' . $this->basename . '\' saved', 'function getCertificate');
590
+					if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Certificate for \'' . $this->basename . '\' saved', 'function getCertificate');
591 591
 					return true;
592 592
 				}
593 593
 				else
594 594
 				{
595
-					if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Received invalid certificate for \'' . $this->basename . '\'. Cannot save certificate.', 'function getCertificate');
595
+					if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Received invalid certificate for \'' . $this->basename . '\'. Cannot save certificate.', 'function getCertificate');
596 596
 				}
597 597
 			}
598 598
 			else
599 599
 			{
600
-				if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Invalid response for certificate request for \'' . $this->basename . '\'. Cannot save certificate.', 'function getCertificate');
600
+				if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Invalid response for certificate request for \'' . $this->basename . '\'. Cannot save certificate.', 'function getCertificate');
601 601
 			}
602 602
 		}
603 603
 		else
604 604
 		{
605
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Order for \'' . $this->basename . '\' not valid. Cannot retrieve certificate.', 'function getCertificate');
605
+			if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Order for \'' . $this->basename . '\' not valid. Cannot retrieve certificate.', 'function getCertificate');
606 606
 		}
607 607
 		return false;
608 608
 	}
@@ -617,13 +617,13 @@  discard block
 block discarded – undo
617 617
      */
618 618
 	public function revokeCertificate($reason = 0)
619 619
 	{
620
-		if($this->status == 'valid')
620
+		if ($this->status == 'valid')
621 621
 		{
622 622
 			if (isset($this->certificateKeys['certificate'])) $certFile = $this->certificateKeys['certificate'];
623 623
 			elseif (isset($this->certificateKeys['fullchain_certificate']))  $certFile = $this->certificateKeys['fullchain_certificate'];
624 624
 			else throw new \RuntimeException('certificateKeys[certificate] or certificateKeys[fullchain_certificate] required');
625 625
 
626
-			if(file_exists($certFile) && file_exists($this->certificateKeys['private_key']))
626
+			if (file_exists($certFile) && file_exists($this->certificateKeys['private_key']))
627 627
 			{
628 628
 				$certificate = file_get_contents($this->certificateKeys['certificate']);
629 629
 				preg_match('~-----BEGIN\sCERTIFICATE-----(.*)-----END\sCERTIFICATE-----~s', $certificate, $matches);
@@ -631,24 +631,24 @@  discard block
 block discarded – undo
631 631
 
632 632
 				$sign = $this->connector->signRequestJWK(array('certificate' => $certificate, 'reason' => $reason), $this->connector->revokeCert);
633 633
 				$post = $this->connector->post($this->connector->revokeCert, $sign);
634
-				if(strpos($post['header'], "200 OK") !== false)
634
+				if (strpos($post['header'], "200 OK") !== false)
635 635
 				{
636
-					if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Certificate for order \'' . $this->basename . '\' revoked.', 'function revokeCertificate');
636
+					if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Certificate for order \'' . $this->basename . '\' revoked.', 'function revokeCertificate');
637 637
 					return true;
638 638
 				}
639 639
 				else
640 640
 				{
641
-					if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Certificate for order \'' . $this->basename . '\' cannot be revoked.', 'function revokeCertificate');
641
+					if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Certificate for order \'' . $this->basename . '\' cannot be revoked.', 'function revokeCertificate');
642 642
 				}
643 643
 			}
644 644
 			else
645 645
 			{
646
-				if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Certificate for order \'' . $this->basename . '\' not found. Cannot revoke certificate.', 'function revokeCertificate');
646
+				if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Certificate for order \'' . $this->basename . '\' not found. Cannot revoke certificate.', 'function revokeCertificate');
647 647
 			}
648 648
 		}
649 649
 		else
650 650
 		{
651
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Order for \'' . $this->basename . '\' not valid. Cannot revoke certificate.', 'function revokeCertificate');
651
+			if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Order for \'' . $this->basename . '\' not valid. Cannot revoke certificate.', 'function revokeCertificate');
652 652
 		}
653 653
 		return false;
654 654
 	}
Please login to merge, or discard this 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 2 patches
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -63,9 +63,9 @@  discard block
 block discarded – undo
63 63
 		$this->accountKeys = $accountKeys;
64 64
 		$this->log = $log;
65 65
 
66
-		if(!file_exists($this->accountKeys['private_key']) OR !file_exists($this->accountKeys['public_key']))
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) LEFunctions::log('No account found, attempting to create account.', 'function LEAccount __construct');
69 69
 			LEFunctions::RSAgenerateKeys(null, $this->accountKeys['private_key'], $this->accountKeys['public_key']);
70 70
 			$this->connector->accountURL = $this->createLEAccount($email);
71 71
 		}
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 		{
74 74
 			$this->connector->accountURL = $this->getLEAccount();
75 75
 		}
76
-		if($this->connector->accountURL == false) throw new \RuntimeException('Account not found or deactivated.');
76
+		if ($this->connector->accountURL == false) throw new \RuntimeException('Account not found or deactivated.');
77 77
 		$this->getLEAccountData();
78 78
 	}
79 79
 
@@ -90,9 +90,9 @@  discard block
 block discarded – undo
90 90
 
91 91
 		$sign = $this->connector->signRequestJWK(array('contact' => $contact, 'termsOfServiceAgreed' => true), $this->connector->newAccount);
92 92
 		$post = $this->connector->post($this->connector->newAccount, $sign);
93
-		if(strpos($post['header'], "201 Created") !== false)
93
+		if (strpos($post['header'], "201 Created") !== false)
94 94
 		{
95
-			if(preg_match('~Location: (\S+)~i', $post['header'], $matches)) return trim($matches[1]);
95
+			if (preg_match('~Location: (\S+)~i', $post['header'], $matches)) return trim($matches[1]);
96 96
 		}
97 97
 		return false;
98 98
 	}
@@ -107,9 +107,9 @@  discard block
 block discarded – undo
107 107
 		$sign = $this->connector->signRequestJWK(array('onlyReturnExisting' => true), $this->connector->newAccount);
108 108
 		$post = $this->connector->post($this->connector->newAccount, $sign);
109 109
 
110
-		if(strpos($post['header'], "200 OK") !== false)
110
+		if (strpos($post['header'], "200 OK") !== false)
111 111
 		{
112
-			if(preg_match('~Location: (\S+)~i', $post['header'], $matches)) return trim($matches[1]);
112
+			if (preg_match('~Location: (\S+)~i', $post['header'], $matches)) return trim($matches[1]);
113 113
 		}
114 114
 		return false;
115 115
 	}
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 	{
122 122
 		$sign = $this->connector->signRequestKid(array('' => ''), $this->connector->accountURL, $this->connector->accountURL);
123 123
 		$post = $this->connector->post($this->connector->accountURL, $sign);
124
-		if(strpos($post['header'], "200 OK") !== false)
124
+		if (strpos($post['header'], "200 OK") !== false)
125 125
 		{
126 126
 			$this->id = $post['body']['id'];
127 127
 			$this->key = $post['body']['key'];
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 
151 151
 		$sign = $this->connector->signRequestKid(array('contact' => $contact), $this->connector->accountURL, $this->connector->accountURL);
152 152
 		$post = $this->connector->post($this->connector->accountURL, $sign);
153
-		if(strpos($post['header'], "200 OK") !== false)
153
+		if (strpos($post['header'], "200 OK") !== false)
154 154
 		{
155 155
 			$this->id = $post['body']['id'];
156 156
 			$this->key = $post['body']['key'];
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 			$this->initialIp = $post['body']['initialIp'];
160 160
 			$this->createdAt = $post['body']['createdAt'];
161 161
 			$this->status = $post['body']['status'];
162
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Account data updated.', 'function updateAccount');
162
+			if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Account data updated.', 'function updateAccount');
163 163
 			return true;
164 164
 		}
165 165
 		else
@@ -175,27 +175,27 @@  discard block
 block discarded – undo
175 175
      */
176 176
 	public function changeAccountKeys()
177 177
 	{
178
-		LEFunctions::RSAgenerateKeys(null, $this->accountKeys['private_key'].'.new', $this->accountKeys['public_key'].'.new');
179
-		$privateKey = openssl_pkey_get_private(file_get_contents($this->accountKeys['private_key'].'.new'));
178
+		LEFunctions::RSAgenerateKeys(null, $this->accountKeys['private_key'] . '.new', $this->accountKeys['public_key'] . '.new');
179
+		$privateKey = openssl_pkey_get_private(file_get_contents($this->accountKeys['private_key'] . '.new'));
180 180
 		$details = openssl_pkey_get_details($privateKey);
181 181
     $innerPayload = array('account' => $this->connector->accountURL, 'newKey' => array(
182 182
 			"kty" => "RSA",
183 183
 			"n" => LEFunctions::Base64UrlSafeEncode($details["rsa"]["n"]),
184 184
 			"e" => LEFunctions::Base64UrlSafeEncode($details["rsa"]["e"])
185 185
 		));
186
-		$outerPayload = $this->connector->signRequestJWK($innerPayload, $this->connector->keyChange, $this->accountKeys['private_key'].'.new');
186
+		$outerPayload = $this->connector->signRequestJWK($innerPayload, $this->connector->keyChange, $this->accountKeys['private_key'] . '.new');
187 187
 		$sign = $this->connector->signRequestKid($outerPayload, $this->connector->accountURL, $this->connector->keyChange);
188 188
 		$post = $this->connector->post($this->connector->keyChange, $sign);
189
-		if(strpos($post['header'], "200 OK") !== false)
189
+		if (strpos($post['header'], "200 OK") !== false)
190 190
 		{
191 191
 			$this->getLEAccountData();
192 192
 
193 193
 			unlink($this->accountKeys['private_key']);
194 194
 			unlink($this->accountKeys['public_key']);
195
-			rename($this->accountKeys['private_key'].'.new', $this->accountKeys['private_key']);
196
-			rename($this->accountKeys['public_key'].'.new', $this->accountKeys['public_key']);
195
+			rename($this->accountKeys['private_key'] . '.new', $this->accountKeys['private_key']);
196
+			rename($this->accountKeys['public_key'] . '.new', $this->accountKeys['public_key']);
197 197
 
198
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Account keys changed.', 'function changeAccountKey');
198
+			if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Account keys changed.', 'function changeAccountKey');
199 199
 			return true;
200 200
 		}
201 201
 		else
@@ -213,10 +213,10 @@  discard block
 block discarded – undo
213 213
 	{
214 214
 		$sign = $this->connector->signRequestKid(array('status' => 'deactivated'), $this->connector->accountURL, $this->connector->accountURL);
215 215
 		$post = $this->connector->post($this->connector->accountURL, $sign);
216
-		if(strpos($post['header'], "200 OK") !== false)
216
+		if (strpos($post['header'], "200 OK") !== false)
217 217
 		{
218 218
 			$this->connector->accountDeactivated = true;
219
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Account deactivated.', 'function deactivateAccount');
219
+			if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Account deactivated.', 'function deactivateAccount');
220 220
 		}
221 221
 		else
222 222
 		{
Please login to merge, or discard this 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 2 patches
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -54,14 +54,14 @@  discard block
 block discarded – undo
54 54
 			"private_key_bits" => intval($keySize),
55 55
 		));
56 56
 
57
-		if(!openssl_pkey_export($res, $privateKey)) throw new \RuntimeException("RSA keypair export failed!");
57
+		if (!openssl_pkey_export($res, $privateKey)) throw new \RuntimeException("RSA keypair export failed!");
58 58
 
59 59
 		$details = openssl_pkey_get_details($res);
60 60
 
61 61
 		if ($directory !== null && $directory !== '')
62 62
 		{
63
-			$privateKeyFile = $directory.$privateKeyFile;
64
-			$publicKeyFile = $directory.$publicKeyFile;
63
+			$privateKeyFile = $directory . $privateKeyFile;
64
+			$publicKeyFile = $directory . $publicKeyFile;
65 65
 		}
66 66
 
67 67
 		file_put_contents($privateKeyFile, $privateKey);
@@ -102,14 +102,14 @@  discard block
 block discarded – undo
102 102
 		else throw new \RuntimeException("EC key size must be 256 or 384");
103 103
 
104 104
 
105
-		if(!openssl_pkey_export($res, $privateKey)) throw new \RuntimeException("EC keypair export failed!");
105
+		if (!openssl_pkey_export($res, $privateKey)) throw new \RuntimeException("EC keypair export failed!");
106 106
 
107 107
 		$details = openssl_pkey_get_details($res);
108 108
 
109 109
 		if ($directory !== null && $directory !== '')
110 110
 		{
111
-			$privateKeyFile = $directory.$privateKeyFile;
112
-			$publicKeyFile = $directory.$publicKeyFile;
111
+			$privateKeyFile = $directory . $privateKeyFile;
112
+			$publicKeyFile = $directory . $publicKeyFile;
113 113
 		}
114 114
 
115 115
 		file_put_contents($privateKeyFile, $privateKey);
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
 	{
162 162
 		$e = new Exception();
163 163
 		$trace = $e->getTrace();
164
-		$function = $function == '' ? 'function ' .  $trace[3]['function'] . ' (function ' . $trace[2]['function'] . ')' : $function;
164
+		$function = $function == '' ? 'function ' . $trace[3]['function'] . ' (function ' . $trace[2]['function'] . ')' : $function;
165 165
 		if (PHP_SAPI == "cli")
166 166
 		{
167 167
 			echo '[' . date('d-m-Y H:i:s') . '] ' . $function . ":\n";
@@ -210,9 +210,9 @@  discard block
 block discarded – undo
210 210
 	{
211 211
 		$DNS = '_acme-challenge.' . str_replace('*.', '', $domain);
212 212
 		$records = dns_get_record($DNS, DNS_TXT);
213
-		foreach($records as $record)
213
+		foreach ($records as $record)
214 214
 		{
215
-			if($record['host'] == $DNS && $record['type'] == 'TXT' && $record['txt'] == $DNSDigest) return true;
215
+			if ($record['host'] == $DNS && $record['type'] == 'TXT' && $record['txt'] == $DNSDigest) return true;
216 216
 		}
217 217
 		return false;
218 218
 	}
Please login to merge, or discard this 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 2 patches
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -86,7 +86,7 @@  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) throw new \RuntimeException('No new nonce.');
90 90
 	}
91 91
 
92 92
     /**
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
      */
101 101
 	private function request($method, $URL, $data = null)
102 102
 	{
103
-		if($this->accountDeactivated) throw new \RuntimeException('The account was deactivated. No further requests can be made.');
103
+		if ($this->accountDeactivated) throw new \RuntimeException('The account was deactivated. No further requests can be made.');
104 104
 
105 105
 		$headers = array('Accept: application/json', 'Content-Type: application/json');
106 106
 		$requestURL = preg_match('~^http~', $URL) ? $URL : $this->baseURL . $URL;
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
         }
128 128
         $response = curl_exec($handle);
129 129
 
130
-        if(curl_errno($handle)) {
130
+        if (curl_errno($handle)) {
131 131
             throw new \RuntimeException('Curl: ' . curl_error($handle));
132 132
         }
133 133
 
@@ -137,21 +137,21 @@  discard block
 block discarded – undo
137 137
         $body = substr($response, $header_size);
138 138
 		$jsonbody = json_decode($body, true);
139 139
 		$jsonresponse = array('request' => $method . ' ' . $requestURL, 'header' => $header, 'body' => $jsonbody === null ? $body : $jsonbody);
140
-		if($this->log >= LECLient::LOG_DEBUG) LEFunctions::log($jsonresponse);
140
+		if ($this->log >= LECLient::LOG_DEBUG) LEFunctions::log($jsonresponse);
141 141
 
142
-		if(	(($method == 'POST' OR $method == 'GET') AND strpos($header, "200 OK") === false AND strpos($header, "201 Created") === false) OR
142
+		if ((($method == 'POST' OR $method == 'GET') AND strpos($header, "200 OK") === false AND strpos($header, "201 Created") === false) OR
143 143
 			($method == 'HEAD' AND strpos($header, "204 No Content") === false))
144 144
 		{
145 145
 			throw new \RuntimeException('Invalid response, header: ' . $header);
146 146
 		}
147 147
 
148
-		if(preg_match('~Replay\-Nonce: (\S+)~i', $header, $matches))
148
+		if (preg_match('~Replay\-Nonce: (\S+)~i', $header, $matches))
149 149
 		{
150 150
 			$this->nonce = trim($matches[1]);
151 151
 		}
152 152
 		else
153 153
 		{
154
-			if($method == 'POST') $this->getNewNonce(); // Not expecting a new nonce with GET and HEAD requests.
154
+			if ($method == 'POST') $this->getNewNonce(); // Not expecting a new nonce with GET and HEAD requests.
155 155
 		}
156 156
 
157 157
         return $jsonresponse;
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
      */
206 206
 	public function signRequestJWK($payload, $url, $privateKeyFile = '')
207 207
     {
208
-		if($privateKeyFile == '') $privateKeyFile = $this->accountKeys['private_key'];
208
+		if ($privateKeyFile == '') $privateKeyFile = $this->accountKeys['private_key'];
209 209
 		$privateKey = openssl_pkey_get_private(file_get_contents($privateKeyFile));
210 210
         $details = openssl_pkey_get_details($privateKey);
211 211
 
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
         $payload64 = LEFunctions::Base64UrlSafeEncode(str_replace('\\/', '/', is_array($payload) ? json_encode($payload) : $payload));
224 224
         $protected64 = LEFunctions::Base64UrlSafeEncode(json_encode($protected));
225 225
 
226
-        openssl_sign($protected64.'.'.$payload64, $signed, $privateKey, "SHA256");
226
+        openssl_sign($protected64 . '.' . $payload64, $signed, $privateKey, "SHA256");
227 227
         $signed64 = LEFunctions::Base64UrlSafeEncode($signed);
228 228
 
229 229
         $data = array(
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
      */
248 248
 	public function signRequestKid($payload, $kid, $url, $privateKeyFile = '')
249 249
     {
250
-		if($privateKeyFile == '') $privateKeyFile = $this->accountKeys['private_key'];
250
+		if ($privateKeyFile == '') $privateKeyFile = $this->accountKeys['private_key'];
251 251
         $privateKey = openssl_pkey_get_private(file_get_contents($privateKeyFile));
252 252
         $details = openssl_pkey_get_details($privateKey);
253 253
 
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
         $payload64 = LEFunctions::Base64UrlSafeEncode(str_replace('\\/', '/', is_array($payload) ? json_encode($payload) : $payload));
262 262
         $protected64 = LEFunctions::Base64UrlSafeEncode(json_encode($protected));
263 263
 
264
-        openssl_sign($protected64.'.'.$payload64, $signed, $privateKey, "SHA256");
264
+        openssl_sign($protected64 . '.' . $payload64, $signed, $privateKey, "SHA256");
265 265
         $signed64 = LEFunctions::Base64UrlSafeEncode($signed);
266 266
 
267 267
         $data = array(
Please login to merge, or discard this 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 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 		$this->authorizationURL = $authorizationURL;
61 61
 		
62 62
 		$get = $this->connector->get($this->authorizationURL);
63
-		if(strpos($get['header'], "200 OK") !== false)
63
+		if (strpos($get['header'], "200 OK") !== false)
64 64
 		{
65 65
 			$this->identifier = $get['body']['identifier'];
66 66
 			$this->status = $get['body']['status'];
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 		}
70 70
 		else
71 71
 		{
72
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Cannot find authorization \'' . $authorizationURL . '\'.', 'function LEAuthorization __construct');
72
+			if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Cannot find authorization \'' . $authorizationURL . '\'.', 'function LEAuthorization __construct');
73 73
 		}
74 74
 	}
75 75
 	
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
 	public function updateData()
81 81
 	{
82 82
 		$get = $this->connector->get($this->authorizationURL);
83
-		if(strpos($get['header'], "200 OK") !== false)
83
+		if (strpos($get['header'], "200 OK") !== false)
84 84
 		{
85 85
 			$this->identifier = $get['body']['identifier'];
86 86
 			$this->status = $get['body']['status'];
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
 		}
90 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) LEFunctions::log('Cannot find authorization \'' . $authorizationURL . '\'.', 'function updateData');
93 93
 		}
94 94
 	}
95 95
 	
@@ -103,9 +103,9 @@  discard block
 block discarded – undo
103 103
      */
104 104
 	public function getChallenge($type)
105 105
 	{
106
-		foreach($this->challenges as $challenge)
106
+		foreach ($this->challenges as $challenge)
107 107
 		{
108
-			if($challenge['type'] == $type) return $challenge;
108
+			if ($challenge['type'] == $type) return $challenge;
109 109
 		}
110 110
 		throw new \RuntimeException('No challenge found for type \'' . $type . '\' and identifier \'' . $this->identifier['value'] . '\'.');
111 111
 	}
Please login to merge, or discard this 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.
exampleDNSInit.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -16,14 +16,14 @@
 block discarded – undo
16 16
 // Initiating the order instance. The keys and certificate will be stored in /example.org/ (argument 1) and the domains in the array (argument 2) will be on the certificate.
17 17
 $order = $client->getOrCreateOrder($basename, $domains);
18 18
 // Check whether there are any authorizations pending. If that is the case, try to verify the pending authorizations.
19
-if(!$order->allAuthorizationsValid())
19
+if (!$order->allAuthorizationsValid())
20 20
 {
21 21
 	// Get the DNS challenges from the pending authorizations.
22 22
 	$pending = $order->getPendingAuthorizations(LEOrder::CHALLENGE_TYPE_DNS);
23 23
 	// Walk the list of pending authorization DNS challenges.
24
-	if(!empty($pending))
24
+	if (!empty($pending))
25 25
 	{
26
-		foreach($pending as $challenge)
26
+		foreach ($pending as $challenge)
27 27
 		{
28 28
 			// For the purpose of this example, a fictitious functions creates or updates the ACME challenge DNS record for this domain. 
29 29
 			setDNSRecord($challenge['identifier'], $challenge['DNSDigest'])
Please login to merge, or discard this patch.
exampleDNSFinish.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -16,14 +16,14 @@  discard block
 block discarded – undo
16 16
 // Initiating the order instance. The keys and certificate will be stored in /example.org/ (argument 1) and the domains in the array (argument 2) will be on the certificate.
17 17
 $order = $client->getOrCreateOrder($basename, $domains);
18 18
 // Check whether there are any authorizations pending. If that is the case, try to verify the pending authorizations.
19
-if(!$order->allAuthorizationsValid())
19
+if (!$order->allAuthorizationsValid())
20 20
 {
21 21
 	// Get the DNS challenges from the pending authorizations.
22 22
 	$pending = $order->getPendingAuthorizations(LEOrder::CHALLENGE_TYPE_DNS);
23 23
 	// Walk the list of pending authorization DNS challenges.
24
-	if(!empty($pending))
24
+	if (!empty($pending))
25 25
 	{
26
-		foreach($pending as $challenge)
26
+		foreach ($pending as $challenge)
27 27
 		{
28 28
 			// Let LetsEncrypt verify this challenge, which should have been fulfilled in exampleDNSStart.php.
29 29
 			$order->verifyPendingOrderAuthorization($challenge['identifier'], LEOrder::CHALLENGE_TYPE_DNS);
@@ -31,11 +31,11 @@  discard block
 block discarded – undo
31 31
 	}
32 32
 }
33 33
 // Check once more whether all authorizations are valid before we can finalize the order.
34
-if($order->allAuthorizationsValid())
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()) $order->finalizeOrder();
38 38
 	// Check whether the order has been finalized before we can get the certificate. If finalized, get the certificate.
39
-	if($order->isFinalized()) $order->getCertificate();
39
+	if ($order->isFinalized()) $order->getCertificate();
40 40
 }
41 41
 ?>
42 42
\ No newline at end of file
Please login to merge, or discard this 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.