@@ -15,10 +15,8 @@ |
||
15 | 15 | * |
16 | 16 | * @internal |
17 | 17 | */ |
18 | -class DummyTest |
|
19 | -{ |
|
20 | - public function __toString() |
|
21 | - { |
|
18 | +class DummyTest { |
|
19 | + public function __toString() { |
|
22 | 20 | return 'DummyTest'; |
23 | 21 | } |
24 | 22 | } |
@@ -23,8 +23,7 @@ |
||
23 | 23 | * See https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md |
24 | 24 | * for the full interface specification. |
25 | 25 | */ |
26 | -interface LoggerInterface |
|
27 | -{ |
|
26 | +interface LoggerInterface { |
|
28 | 27 | /** |
29 | 28 | * System is unusable. |
30 | 29 | * |
@@ -32,8 +32,7 @@ discard block |
||
32 | 32 | /** |
33 | 33 | * Class documentation |
34 | 34 | */ |
35 | -class Logger extends AbstractLogger |
|
36 | -{ |
|
35 | +class Logger extends AbstractLogger { |
|
37 | 36 | /** |
38 | 37 | * KLogger options |
39 | 38 | * Anything options not considered 'core' to the logging library should be |
@@ -115,28 +114,27 @@ discard block |
||
115 | 114 | * @internal param string $logFilePrefix The prefix for the log file name |
116 | 115 | * @internal param string $logFileExt The extension for the log file |
117 | 116 | */ |
118 | - public function __construct($logDirectory, $logLevelThreshold = LogLevel::DEBUG, array $options = array()) |
|
119 | - { |
|
117 | + public function __construct($logDirectory, $logLevelThreshold = LogLevel::DEBUG, array $options = array()) { |
|
120 | 118 | $this->logLevelThreshold = $logLevelThreshold; |
121 | 119 | $this->options = array_merge($this->options, $options); |
122 | 120 | |
123 | 121 | $logDirectory = rtrim($logDirectory, DIRECTORY_SEPARATOR); |
124 | - if ( ! file_exists($logDirectory)) { |
|
122 | + if ( ! file_exists($logDirectory)) { |
|
125 | 123 | mkdir($logDirectory, $this->defaultPermissions, true); |
126 | 124 | } |
127 | 125 | |
128 | - if(strpos($logDirectory, 'php://') === 0) { |
|
126 | + if(strpos($logDirectory, 'php://') === 0) { |
|
129 | 127 | $this->setLogToStdOut($logDirectory); |
130 | 128 | $this->setFileHandle('w+'); |
131 | - } else { |
|
129 | + } else { |
|
132 | 130 | $this->setLogFilePath($logDirectory); |
133 | - if(file_exists($this->logFilePath) && !is_writable($this->logFilePath)) { |
|
131 | + if(file_exists($this->logFilePath) && !is_writable($this->logFilePath)) { |
|
134 | 132 | throw new RuntimeException('The file could not be written to. Check that appropriate permissions have been set.'); |
135 | 133 | } |
136 | 134 | $this->setFileHandle('a'); |
137 | 135 | } |
138 | 136 | |
139 | - if ( ! $this->fileHandle) { |
|
137 | + if ( ! $this->fileHandle) { |
|
140 | 138 | throw new RuntimeException('The file could not be opened. Check permissions.'); |
141 | 139 | } |
142 | 140 | } |
@@ -144,22 +142,21 @@ discard block |
||
144 | 142 | /** |
145 | 143 | * @param string $stdOutPath |
146 | 144 | */ |
147 | - public function setLogToStdOut($stdOutPath) { |
|
145 | + public function setLogToStdOut($stdOutPath) { |
|
148 | 146 | $this->logFilePath = $stdOutPath; |
149 | 147 | } |
150 | 148 | |
151 | 149 | /** |
152 | 150 | * @param string $logDirectory |
153 | 151 | */ |
154 | - public function setLogFilePath($logDirectory) { |
|
155 | - if ($this->options['filename']) { |
|
156 | - if (strpos($this->options['filename'], '.log') !== false || strpos($this->options['filename'], '.txt') !== false) { |
|
152 | + public function setLogFilePath($logDirectory) { |
|
153 | + if ($this->options['filename']) { |
|
154 | + if (strpos($this->options['filename'], '.log') !== false || strpos($this->options['filename'], '.txt') !== false) { |
|
157 | 155 | $this->logFilePath = $logDirectory.DIRECTORY_SEPARATOR.$this->options['filename']; |
158 | - } |
|
159 | - else { |
|
156 | + } else { |
|
160 | 157 | $this->logFilePath = $logDirectory.DIRECTORY_SEPARATOR.$this->options['filename'].'.'.$this->options['extension']; |
161 | 158 | } |
162 | - } else { |
|
159 | + } else { |
|
163 | 160 | $this->logFilePath = $logDirectory.DIRECTORY_SEPARATOR.$this->options['prefix'].date('Y-m-d').'.'.$this->options['extension']; |
164 | 161 | } |
165 | 162 | } |
@@ -169,7 +166,7 @@ discard block |
||
169 | 166 | * |
170 | 167 | * @internal param resource $fileHandle |
171 | 168 | */ |
172 | - public function setFileHandle($writeMode) { |
|
169 | + public function setFileHandle($writeMode) { |
|
173 | 170 | $this->fileHandle = fopen($this->logFilePath, $writeMode); |
174 | 171 | } |
175 | 172 | |
@@ -177,9 +174,8 @@ discard block |
||
177 | 174 | /** |
178 | 175 | * Class destructor |
179 | 176 | */ |
180 | - public function __destruct() |
|
181 | - { |
|
182 | - if ($this->fileHandle) { |
|
177 | + public function __destruct() { |
|
178 | + if ($this->fileHandle) { |
|
183 | 179 | fclose($this->fileHandle); |
184 | 180 | } |
185 | 181 | } |
@@ -189,8 +185,7 @@ discard block |
||
189 | 185 | * |
190 | 186 | * @param string $dateFormat Valid format string for date() |
191 | 187 | */ |
192 | - public function setDateFormat($dateFormat) |
|
193 | - { |
|
188 | + public function setDateFormat($dateFormat) { |
|
194 | 189 | $this->options['dateFormat'] = $dateFormat; |
195 | 190 | } |
196 | 191 | |
@@ -199,8 +194,7 @@ discard block |
||
199 | 194 | * |
200 | 195 | * @param string $logLevelThreshold The log level threshold |
201 | 196 | */ |
202 | - public function setLogLevelThreshold($logLevelThreshold) |
|
203 | - { |
|
197 | + public function setLogLevelThreshold($logLevelThreshold) { |
|
204 | 198 | $this->logLevelThreshold = $logLevelThreshold; |
205 | 199 | } |
206 | 200 | |
@@ -212,9 +206,8 @@ discard block |
||
212 | 206 | * @param array $context |
213 | 207 | * @return null |
214 | 208 | */ |
215 | - public function log($level, $message, array $context = array()) |
|
216 | - { |
|
217 | - if ($this->logLevels[$this->logLevelThreshold] < $this->logLevels[$level]) { |
|
209 | + public function log($level, $message, array $context = array()) { |
|
210 | + if ($this->logLevels[$this->logLevelThreshold] < $this->logLevels[$level]) { |
|
218 | 211 | return; |
219 | 212 | } |
220 | 213 | $message = $this->formatMessage($level, $message, $context); |
@@ -227,16 +220,15 @@ discard block |
||
227 | 220 | * @param string $message Line to write to the log |
228 | 221 | * @return void |
229 | 222 | */ |
230 | - public function write($message) |
|
231 | - { |
|
232 | - if (null !== $this->fileHandle) { |
|
233 | - if (fwrite($this->fileHandle, $message) === false) { |
|
223 | + public function write($message) { |
|
224 | + if (null !== $this->fileHandle) { |
|
225 | + if (fwrite($this->fileHandle, $message) === false) { |
|
234 | 226 | throw new RuntimeException('The file could not be written to. Check that appropriate permissions have been set.'); |
235 | - } else { |
|
227 | + } else { |
|
236 | 228 | $this->lastLine = trim($message); |
237 | 229 | $this->logLineCount++; |
238 | 230 | |
239 | - if ($this->options['flushFrequency'] && $this->logLineCount % $this->options['flushFrequency'] === 0) { |
|
231 | + if ($this->options['flushFrequency'] && $this->logLineCount % $this->options['flushFrequency'] === 0) { |
|
240 | 232 | fflush($this->fileHandle); |
241 | 233 | } |
242 | 234 | } |
@@ -248,8 +240,7 @@ discard block |
||
248 | 240 | * |
249 | 241 | * @return string |
250 | 242 | */ |
251 | - public function getLogFilePath() |
|
252 | - { |
|
243 | + public function getLogFilePath() { |
|
253 | 244 | return $this->logFilePath; |
254 | 245 | } |
255 | 246 | |
@@ -258,8 +249,7 @@ discard block |
||
258 | 249 | * |
259 | 250 | * @return string |
260 | 251 | */ |
261 | - public function getLastLogLine() |
|
262 | - { |
|
252 | + public function getLastLogLine() { |
|
263 | 253 | return $this->lastLine; |
264 | 254 | } |
265 | 255 | |
@@ -271,9 +261,8 @@ discard block |
||
271 | 261 | * @param array $context The context |
272 | 262 | * @return string |
273 | 263 | */ |
274 | - protected function formatMessage($level, $message, $context) |
|
275 | - { |
|
276 | - if ($this->options['logFormat']) { |
|
264 | + protected function formatMessage($level, $message, $context) { |
|
265 | + if ($this->options['logFormat']) { |
|
277 | 266 | $parts = array( |
278 | 267 | 'date' => $this->getTimestamp(), |
279 | 268 | 'level' => strtoupper($level), |
@@ -283,15 +272,15 @@ discard block |
||
283 | 272 | 'context' => json_encode($context), |
284 | 273 | ); |
285 | 274 | $message = $this->options['logFormat']; |
286 | - foreach ($parts as $part => $value) { |
|
275 | + foreach ($parts as $part => $value) { |
|
287 | 276 | $message = str_replace('{'.$part.'}', $value, $message); |
288 | 277 | } |
289 | 278 | |
290 | - } else { |
|
279 | + } else { |
|
291 | 280 | $message = "[{$this->getTimestamp()}] [{$level}] {$message}"; |
292 | 281 | } |
293 | 282 | |
294 | - if ($this->options['appendContext'] && ! empty($context)) { |
|
283 | + if ($this->options['appendContext'] && ! empty($context)) { |
|
295 | 284 | $message .= PHP_EOL.$this->indent($this->contextToString($context)); |
296 | 285 | } |
297 | 286 | |
@@ -307,8 +296,7 @@ discard block |
||
307 | 296 | * |
308 | 297 | * @return string |
309 | 298 | */ |
310 | - private function getTimestamp() |
|
311 | - { |
|
299 | + private function getTimestamp() { |
|
312 | 300 | $originalTime = microtime(true); |
313 | 301 | $micro = sprintf("%06d", ($originalTime - floor($originalTime)) * 1000000); |
314 | 302 | $date = new DateTime(date('Y-m-d H:i:s.'.$micro, $originalTime)); |
@@ -322,10 +310,9 @@ discard block |
||
322 | 310 | * @param array $context The Context |
323 | 311 | * @return string |
324 | 312 | */ |
325 | - protected function contextToString($context) |
|
326 | - { |
|
313 | + protected function contextToString($context) { |
|
327 | 314 | $export = ''; |
328 | - foreach ($context as $key => $value) { |
|
315 | + foreach ($context as $key => $value) { |
|
329 | 316 | $export .= "{$key}: "; |
330 | 317 | $export .= preg_replace(array( |
331 | 318 | '/=>\s+([a-zA-Z])/im', |
@@ -348,8 +335,7 @@ discard block |
||
348 | 335 | * @param string $indent What to use as the indent. |
349 | 336 | * @return string |
350 | 337 | */ |
351 | - protected function indent($string, $indent = ' ') |
|
352 | - { |
|
338 | + protected function indent($string, $indent = ' ') { |
|
353 | 339 | return $indent.str_replace("\n", "\n".$indent, $string); |
354 | 340 | } |
355 | 341 | } |
@@ -45,8 +45,7 @@ |
||
45 | 45 | * |
46 | 46 | * @return string |
47 | 47 | */ |
48 | - function random_bytes($bytes) |
|
49 | - { |
|
48 | + function random_bytes($bytes) { |
|
50 | 49 | /** @var resource $fp */ |
51 | 50 | static $fp = null; |
52 | 51 |
@@ -38,8 +38,7 @@ |
||
38 | 38 | * |
39 | 39 | * @return int |
40 | 40 | */ |
41 | - function random_int($min, $max) |
|
42 | - { |
|
41 | + function random_int($min, $max) { |
|
43 | 42 | /** |
44 | 43 | * Type and input logic checks |
45 | 44 | * |
@@ -40,8 +40,7 @@ |
||
40 | 40 | * |
41 | 41 | * @return string |
42 | 42 | */ |
43 | - function random_bytes($bytes) |
|
44 | - { |
|
43 | + function random_bytes($bytes) { |
|
45 | 44 | try { |
46 | 45 | /** @var int $bytes */ |
47 | 46 | $bytes = RandomCompat_intval($bytes); |
@@ -45,8 +45,7 @@ |
||
45 | 45 | * |
46 | 46 | * @throws TypeError |
47 | 47 | */ |
48 | - function RandomCompat_intval($number, $fail_open = false) |
|
49 | - { |
|
48 | + function RandomCompat_intval($number, $fail_open = false) { |
|
50 | 49 | if (is_int($number) || is_float($number)) { |
51 | 50 | $number += 0; |
52 | 51 | } elseif (is_numeric($number)) { |
@@ -208,8 +208,7 @@ |
||
208 | 208 | * @throws Exception |
209 | 209 | * @return string |
210 | 210 | */ |
211 | - function random_bytes($length) |
|
212 | - { |
|
211 | + function random_bytes($length) { |
|
213 | 212 | unset($length); // Suppress "variable not used" warnings. |
214 | 213 | throw new Exception( |
215 | 214 | 'There is no suitable CSPRNG installed on your system' |
@@ -28,21 +28,18 @@ |
||
28 | 28 | |
29 | 29 | if (!class_exists('Error', false)) { |
30 | 30 | // We can't really avoid making this extend Exception in PHP 5. |
31 | - class Error extends Exception |
|
32 | - { |
|
31 | + class Error extends Exception { |
|
33 | 32 | |
34 | 33 | } |
35 | 34 | } |
36 | 35 | |
37 | 36 | if (!class_exists('TypeError', false)) { |
38 | 37 | if (is_subclass_of('Error', 'Exception')) { |
39 | - class TypeError extends Error |
|
40 | - { |
|
38 | + class TypeError extends Error { |
|
41 | 39 | |
42 | 40 | } |
43 | 41 | } else { |
44 | - class TypeError extends Exception |
|
45 | - { |
|
42 | + class TypeError extends Exception { |
|
46 | 43 | |
47 | 44 | } |
48 | 45 | } |