@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | * @return static |
65 | 65 | */ |
66 | 66 | public static function getInstance() { |
67 | - if(!self::$instance) { |
|
67 | + if (!self::$instance) { |
|
68 | 68 | self::$instance = new static(); |
69 | 69 | } |
70 | 70 | return self::$instance; |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | * @throws \Exception |
78 | 78 | */ |
79 | 79 | public static function setPostponeStorage(Storage $storage) { |
80 | - if(self::$instance) { |
|
80 | + if (self::$instance) { |
|
81 | 81 | throw new \Exception(__METHOD__ . ' can be called only before ' . __CLASS__ . '::getInstance()'); |
82 | 82 | } |
83 | 83 | self::$postponeStorage = $storage; |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | * @return Storage |
88 | 88 | */ |
89 | 89 | private function getPostponeStorage() { |
90 | - if(!self::$postponeStorage) { |
|
90 | + if (!self::$postponeStorage) { |
|
91 | 91 | self::$postponeStorage = new Storage\Session(); |
92 | 92 | } |
93 | 93 | return self::$postponeStorage; |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | |
96 | 96 | protected function __construct() { |
97 | 97 | $this->initConnection(); |
98 | - $this->setServerEncoding(ini_get('mbstring.internal_encoding') ? : self::CLIENT_ENCODING); |
|
98 | + $this->setServerEncoding(ini_get('mbstring.internal_encoding') ?: self::CLIENT_ENCODING); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | private final function __clone() { |
@@ -114,14 +114,14 @@ discard block |
||
114 | 114 | * @throws \Exception |
115 | 115 | */ |
116 | 116 | private function initConnection() { |
117 | - if($this->isCliMode()) { |
|
117 | + if ($this->isCliMode()) { |
|
118 | 118 | return; |
119 | 119 | } |
120 | 120 | |
121 | 121 | $this->initServerCookie(); |
122 | 122 | $this->client = $this->initClient(); |
123 | 123 | |
124 | - if($this->client) { |
|
124 | + if ($this->client) { |
|
125 | 125 | ob_start(); |
126 | 126 | $this->isActiveClient = true; |
127 | 127 | $this->registerFlushOnShutDown(); |
@@ -140,14 +140,14 @@ discard block |
||
140 | 140 | * @throws \Exception |
141 | 141 | */ |
142 | 142 | private function initClient() { |
143 | - if(isset($_COOKIE[self::CLIENT_INFO_COOKIE])) { |
|
143 | + if (isset($_COOKIE[self::CLIENT_INFO_COOKIE])) { |
|
144 | 144 | $clientData = @json_decode(base64_decode($_COOKIE[self::CLIENT_INFO_COOKIE], true), true); |
145 | - if(!$clientData) { |
|
145 | + if (!$clientData) { |
|
146 | 146 | throw new \Exception('Wrong format of response cookie data: ' . $_COOKIE[self::CLIENT_INFO_COOKIE]); |
147 | 147 | } |
148 | 148 | |
149 | 149 | $client = new Client($clientData); |
150 | - if(isset($clientData['auth'])) { |
|
150 | + if (isset($clientData['auth'])) { |
|
151 | 151 | $client->auth = new ClientAuth($clientData['auth']); |
152 | 152 | } |
153 | 153 | return $client; |
@@ -159,9 +159,9 @@ discard block |
||
159 | 159 | * @throws \Exception |
160 | 160 | */ |
161 | 161 | private function initServerCookie() { |
162 | - if(!isset($_COOKIE[self::SERVER_COOKIE]) || $_COOKIE[self::SERVER_COOKIE] != self::SERVER_PROTOCOL) { |
|
162 | + if (!isset($_COOKIE[self::SERVER_COOKIE]) || $_COOKIE[self::SERVER_COOKIE] != self::SERVER_PROTOCOL) { |
|
163 | 163 | $isSuccess = setcookie(self::SERVER_COOKIE, self::SERVER_PROTOCOL, null, '/'); |
164 | - if(!$isSuccess) { |
|
164 | + if (!$isSuccess) { |
|
165 | 165 | throw new \Exception('Unable to set PHP Console server cookie'); |
166 | 166 | } |
167 | 167 | } |
@@ -195,11 +195,11 @@ discard block |
||
195 | 195 | * @param array $ipMasks Use *(star character) for "any numbers" placeholder array('192.168.*.*', '10.2.12*.*', '127.0.0.1') |
196 | 196 | */ |
197 | 197 | public function setAllowedIpMasks(array $ipMasks) { |
198 | - if($this->isActiveClient()) { |
|
199 | - if(isset($_SERVER['REMOTE_ADDR'])) { |
|
198 | + if ($this->isActiveClient()) { |
|
199 | + if (isset($_SERVER['REMOTE_ADDR'])) { |
|
200 | 200 | $ip = $_SERVER['REMOTE_ADDR']; |
201 | - foreach($ipMasks as $ipMask) { |
|
202 | - if(preg_match('~^' . str_replace(array('.', '*'), array('\.', '\w+'), $ipMask) . '$~i', $ip)) { |
|
201 | + foreach ($ipMasks as $ipMask) { |
|
202 | + if (preg_match('~^' . str_replace(array('.', '*'), array('\.', '\w+'), $ipMask) . '$~i', $ip)) { |
|
203 | 203 | return; |
204 | 204 | } |
205 | 205 | } |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | * @return Dumper |
213 | 213 | */ |
214 | 214 | public function getDumper() { |
215 | - if(!$this->dumper) { |
|
215 | + if (!$this->dumper) { |
|
216 | 216 | $this->dumper = new Dumper(); |
217 | 217 | } |
218 | 218 | return $this->dumper; |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | * @return Dispatcher\Errors |
232 | 232 | */ |
233 | 233 | public function getErrorsDispatcher() { |
234 | - if(!$this->errorsDispatcher) { |
|
234 | + if (!$this->errorsDispatcher) { |
|
235 | 235 | $this->errorsDispatcher = new Dispatcher\Errors($this, $this->getDumper()); |
236 | 236 | } |
237 | 237 | return $this->errorsDispatcher; |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | * @return Dispatcher\Debug |
251 | 251 | */ |
252 | 252 | public function getDebugDispatcher() { |
253 | - if(!$this->debugDispatcher) { |
|
253 | + if (!$this->debugDispatcher) { |
|
254 | 254 | $this->debugDispatcher = new Dispatcher\Debug($this, $this->getDumper()); |
255 | 255 | } |
256 | 256 | return $this->debugDispatcher; |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | * @return Dispatcher\Evaluate |
270 | 270 | */ |
271 | 271 | public function getEvalDispatcher() { |
272 | - if(!$this->evalDispatcher) { |
|
272 | + if (!$this->evalDispatcher) { |
|
273 | 273 | $this->evalDispatcher = new Dispatcher\Evaluate($this, new EvalProvider(), $this->getDumper()); |
274 | 274 | } |
275 | 275 | return $this->evalDispatcher; |
@@ -285,32 +285,32 @@ discard block |
||
285 | 285 | * @throws \Exception |
286 | 286 | */ |
287 | 287 | public function startEvalRequestsListener($exitOnEval = true, $flushDebugMessages = true) { |
288 | - if(!$this->auth) { |
|
288 | + if (!$this->auth) { |
|
289 | 289 | throw new \Exception('Eval dispatcher is allowed only in password protected mode. See PhpConsole\Connector::getInstance()->setPassword(...)'); |
290 | 290 | } |
291 | - if($this->isEvalListenerStarted) { |
|
291 | + if ($this->isEvalListenerStarted) { |
|
292 | 292 | throw new \Exception('Eval requests listener already started'); |
293 | 293 | } |
294 | 294 | $this->isEvalListenerStarted = true; |
295 | 295 | |
296 | - if($this->isActiveClient() && $this->isAuthorized() && isset($_POST[Connector::POST_VAR_NAME]['eval'])) { |
|
296 | + if ($this->isActiveClient() && $this->isAuthorized() && isset($_POST[Connector::POST_VAR_NAME]['eval'])) { |
|
297 | 297 | $request = $_POST[Connector::POST_VAR_NAME]['eval']; |
298 | - if(!isset($request['data']) || !isset($request['signature'])) { |
|
298 | + if (!isset($request['data']) || !isset($request['signature'])) { |
|
299 | 299 | throw new \Exception('Wrong PHP Console eval request'); |
300 | 300 | } |
301 | - if($this->auth->getSignature($request['data']) !== $request['signature']) { |
|
301 | + if ($this->auth->getSignature($request['data']) !== $request['signature']) { |
|
302 | 302 | throw new \Exception('Wrong PHP Console eval request signature'); |
303 | 303 | } |
304 | - if($flushDebugMessages) { |
|
305 | - foreach($this->messages as $i => $message) { |
|
306 | - if($message instanceof DebugMessage) { |
|
304 | + if ($flushDebugMessages) { |
|
305 | + foreach ($this->messages as $i => $message) { |
|
306 | + if ($message instanceof DebugMessage) { |
|
307 | 307 | unset($this->messages[$i]); |
308 | 308 | } |
309 | 309 | } |
310 | 310 | } |
311 | 311 | $this->convertEncoding($request['data'], $this->serverEncoding, self::CLIENT_ENCODING); |
312 | 312 | $this->getEvalDispatcher()->dispatchCode($request['data']); |
313 | - if($exitOnEval) { |
|
313 | + if ($exitOnEval) { |
|
314 | 314 | exit; |
315 | 315 | } |
316 | 316 | } |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | */ |
324 | 324 | public function setSourcesBasePath($sourcesBasePath) { |
325 | 325 | $sourcesBasePath = realpath($sourcesBasePath); |
326 | - if(!$sourcesBasePath) { |
|
326 | + if (!$sourcesBasePath) { |
|
327 | 327 | throw new \Exception('Path "' . $sourcesBasePath . '" not found'); |
328 | 328 | } |
329 | 329 | $this->sourcesBasePath = $sourcesBasePath; |
@@ -338,12 +338,12 @@ discard block |
||
338 | 338 | * @throws \Exception |
339 | 339 | */ |
340 | 340 | public function setPassword($password, $publicKeyByIp = true) { |
341 | - if($this->auth) { |
|
341 | + if ($this->auth) { |
|
342 | 342 | throw new \Exception('Password already defined'); |
343 | 343 | } |
344 | 344 | $this->convertEncoding($password, self::CLIENT_ENCODING, $this->serverEncoding); |
345 | 345 | $this->auth = new Auth($password, $publicKeyByIp); |
346 | - if($this->client) { |
|
346 | + if ($this->client) { |
|
347 | 347 | $this->isAuthorized = $this->client->auth && $this->auth->isValidAuth($this->client->auth); |
348 | 348 | } |
349 | 349 | } |
@@ -386,18 +386,18 @@ discard block |
||
386 | 386 | * @throws \Exception |
387 | 387 | */ |
388 | 388 | protected function convertEncoding(&$string, $toEncoding, $fromEncoding) { |
389 | - if($string && is_string($string) && $toEncoding != $fromEncoding) { |
|
389 | + if ($string && is_string($string) && $toEncoding != $fromEncoding) { |
|
390 | 390 | static $isMbString; |
391 | - if($isMbString === null) { |
|
391 | + if ($isMbString === null) { |
|
392 | 392 | $isMbString = extension_loaded('mbstring'); |
393 | 393 | } |
394 | - if($isMbString) { |
|
395 | - $string = @mb_convert_encoding($string, $toEncoding, $fromEncoding) ? : $string; |
|
394 | + if ($isMbString) { |
|
395 | + $string = @mb_convert_encoding($string, $toEncoding, $fromEncoding) ?: $string; |
|
396 | 396 | } |
397 | 397 | else { |
398 | - $string = @iconv($fromEncoding, $toEncoding . '//IGNORE', $string) ? : $string; |
|
398 | + $string = @iconv($fromEncoding, $toEncoding . '//IGNORE', $string) ?: $string; |
|
399 | 399 | } |
400 | - if(!$string && $toEncoding == 'UTF-8') { |
|
400 | + if (!$string && $toEncoding == 'UTF-8') { |
|
401 | 401 | $string = utf8_encode($string); |
402 | 402 | } |
403 | 403 | } |
@@ -409,7 +409,7 @@ discard block |
||
409 | 409 | * @throws \Exception |
410 | 410 | */ |
411 | 411 | public function setHeadersLimit($bytes) { |
412 | - if($bytes < static::PHP_HEADERS_SIZE) { |
|
412 | + if ($bytes < static::PHP_HEADERS_SIZE) { |
|
413 | 413 | throw new \Exception('Headers limit cannot be less then ' . __CLASS__ . '::PHP_HEADERS_SIZE'); |
414 | 414 | } |
415 | 415 | $bytes -= static::PHP_HEADERS_SIZE; |
@@ -421,7 +421,7 @@ discard block |
||
421 | 421 | * @param $encoding |
422 | 422 | */ |
423 | 423 | public function setServerEncoding($encoding) { |
424 | - if($encoding == 'utf8' || $encoding == 'utf-8') { |
|
424 | + if ($encoding == 'utf8' || $encoding == 'utf-8') { |
|
425 | 425 | $encoding = 'UTF-8'; // otherwise mb_convert_encoding() sometime fails with error(thanks to @alexborisov) |
426 | 426 | } |
427 | 427 | $this->serverEncoding = $encoding; |
@@ -432,7 +432,7 @@ discard block |
||
432 | 432 | * @param Message $message |
433 | 433 | */ |
434 | 434 | public function sendMessage(Message $message) { |
435 | - if($this->isActiveClient()) { |
|
435 | + if ($this->isActiveClient()) { |
|
436 | 436 | $this->messages[] = $message; |
437 | 437 | } |
438 | 438 | } |
@@ -450,7 +450,7 @@ discard block |
||
450 | 450 | */ |
451 | 451 | public function onShutDown() { |
452 | 452 | $this->registeredShutDowns--; |
453 | - if(!$this->registeredShutDowns) { |
|
453 | + if (!$this->registeredShutDowns) { |
|
454 | 454 | $this->proceedResponsePackage(); |
455 | 455 | } |
456 | 456 | } |
@@ -475,19 +475,19 @@ discard block |
||
475 | 475 | * @throws \Exception |
476 | 476 | */ |
477 | 477 | private function proceedResponsePackage() { |
478 | - if($this->isActiveClient()) { |
|
478 | + if ($this->isActiveClient()) { |
|
479 | 479 | $response = new Response(); |
480 | 480 | $response->isSslOnlyMode = $this->isSslOnlyMode; |
481 | 481 | |
482 | - if(isset($_POST[self::POST_VAR_NAME]['getBackData'])) { |
|
482 | + if (isset($_POST[self::POST_VAR_NAME]['getBackData'])) { |
|
483 | 483 | $response->getBackData = $_POST[self::POST_VAR_NAME]['getBackData']; |
484 | 484 | } |
485 | 485 | |
486 | - if(!$this->isSslOnlyMode || $this->isSsl()) { |
|
487 | - if($this->auth) { |
|
486 | + if (!$this->isSslOnlyMode || $this->isSsl()) { |
|
487 | + if ($this->auth) { |
|
488 | 488 | $response->auth = $this->auth->getServerAuthStatus($this->client->auth); |
489 | 489 | } |
490 | - if(!$this->auth || $this->isAuthorized()) { |
|
490 | + if (!$this->auth || $this->isAuthorized()) { |
|
491 | 491 | $response->isLocal = isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] == '127.0.0.1'; |
492 | 492 | $response->docRoot = isset($_SERVER['DOCUMENT_ROOT']) ? $_SERVER['DOCUMENT_ROOT'] : null; |
493 | 493 | $response->sourcesBasePath = $this->sourcesBasePath; |
@@ -498,7 +498,7 @@ discard block |
||
498 | 498 | |
499 | 499 | $responseData = $this->serializeResponse($response); |
500 | 500 | |
501 | - if(strlen($responseData) > $this->headersLimit || !$this->setHeaderData($responseData, self::HEADER_NAME, false)) { |
|
501 | + if (strlen($responseData) > $this->headersLimit || !$this->setHeaderData($responseData, self::HEADER_NAME, false)) { |
|
502 | 502 | $this->getPostponeStorage()->push($this->postponeResponseId, $responseData); |
503 | 503 | } |
504 | 504 | } |
@@ -515,8 +515,8 @@ discard block |
||
515 | 515 | } |
516 | 516 | |
517 | 517 | private function setHeaderData($responseData, $headerName, $throwException = true) { |
518 | - if(headers_sent($file, $line)) { |
|
519 | - if($throwException) { |
|
518 | + if (headers_sent($file, $line)) { |
|
519 | + if ($throwException) { |
|
520 | 520 | throw new \Exception('Unable to process response data, headers already sent in ' . $file . ':' . $line . '. Try to use ob_start() and don\'t use flush().'); |
521 | 521 | } |
522 | 522 | return false; |
@@ -526,14 +526,14 @@ discard block |
||
526 | 526 | } |
527 | 527 | |
528 | 528 | protected function objectToArray(&$var) { |
529 | - if(is_object($var)) { |
|
529 | + if (is_object($var)) { |
|
530 | 530 | $var = get_object_vars($var); |
531 | 531 | array_walk_recursive($var, array($this, 'objectToArray')); |
532 | 532 | } |
533 | 533 | } |
534 | 534 | |
535 | 535 | protected function serializeResponse(DataObject $response) { |
536 | - if($this->serverEncoding != self::CLIENT_ENCODING) { |
|
536 | + if ($this->serverEncoding != self::CLIENT_ENCODING) { |
|
537 | 537 | $this->objectToArray($response); |
538 | 538 | $this->convertArrayEncoding($response, self::CLIENT_ENCODING, $this->serverEncoding); |
539 | 539 | } |
@@ -544,7 +544,7 @@ discard block |
||
544 | 544 | * Check if there is postponed response request and dispatch it |
545 | 545 | */ |
546 | 546 | private function listenGetPostponedResponse() { |
547 | - if(isset($_POST[self::POST_VAR_NAME]['getPostponedResponse'])) { |
|
547 | + if (isset($_POST[self::POST_VAR_NAME]['getPostponedResponse'])) { |
|
548 | 548 | header('Content-Type: application/json; charset=' . self::CLIENT_ENCODING); |
549 | 549 | echo $this->getPostponeStorage()->pop($_POST[self::POST_VAR_NAME]['getPostponedResponse']); |
550 | 550 | $this->disable(); |
@@ -556,7 +556,7 @@ discard block |
||
556 | 556 | abstract class DataObject { |
557 | 557 | |
558 | 558 | public function __construct(array $properties = array()) { |
559 | - foreach($properties as $property => $value) { |
|
559 | + foreach ($properties as $property => $value) { |
|
560 | 560 | $this->$property = $value; |
561 | 561 | } |
562 | 562 | } |
@@ -41,10 +41,10 @@ discard block |
||
41 | 41 | try { |
42 | 42 | $result->return = static::executeCode($code, $this->sharedVars); |
43 | 43 | } |
44 | - catch(\Throwable $exception) { |
|
44 | + catch (\Throwable $exception) { |
|
45 | 45 | $result->exception = $exception; |
46 | 46 | } |
47 | - catch(\Exception $exception) { |
|
47 | + catch (\Exception $exception) { |
|
48 | 48 | $result->exception = $exception; |
49 | 49 | } |
50 | 50 | $result->time = abs(microtime(true) - $startTime - $selfTime); |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | * @throws \Exception |
62 | 62 | */ |
63 | 63 | public function addCodeHandler($callback) { |
64 | - if(!is_callable($callback)) { |
|
64 | + if (!is_callable($callback)) { |
|
65 | 65 | throw new \Exception('Argument is not callable'); |
66 | 66 | } |
67 | 67 | $this->codeCallbackHandlers[] = $callback; |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | * @return mixed |
74 | 74 | */ |
75 | 75 | protected function applyHandlersToCode($code) { |
76 | - foreach($this->codeCallbackHandlers as $callback) { |
|
76 | + foreach ($this->codeCallbackHandlers as $callback) { |
|
77 | 77 | call_user_func_array($callback, array(&$code)); |
78 | 78 | } |
79 | 79 | return $code; |
@@ -84,8 +84,8 @@ discard block |
||
84 | 84 | */ |
85 | 85 | protected function backupGlobals() { |
86 | 86 | $this->globalsBackup = array(); |
87 | - foreach($GLOBALS as $key => $value) { |
|
88 | - if($key != 'GLOBALS') { |
|
87 | + foreach ($GLOBALS as $key => $value) { |
|
88 | + if ($key != 'GLOBALS') { |
|
89 | 89 | $this->globalsBackup[$key] = $value; |
90 | 90 | } |
91 | 91 | } |
@@ -95,11 +95,11 @@ discard block |
||
95 | 95 | * Restore global vars data from backup var |
96 | 96 | */ |
97 | 97 | protected function restoreGlobals() { |
98 | - foreach($this->globalsBackup as $key => $value) { |
|
98 | + foreach ($this->globalsBackup as $key => $value) { |
|
99 | 99 | $GLOBALS[$key] = $value; |
100 | 100 | } |
101 | - foreach(array_diff(array_keys($GLOBALS), array_keys($this->globalsBackup)) as $newKey) { |
|
102 | - if($newKey != 'GLOBALS') { |
|
101 | + foreach (array_diff(array_keys($GLOBALS), array_keys($this->globalsBackup)) as $newKey) { |
|
102 | + if ($newKey != 'GLOBALS') { |
|
103 | 103 | unset($GLOBALS[$newKey]); |
104 | 104 | } |
105 | 105 | } |
@@ -112,11 +112,11 @@ discard block |
||
112 | 112 | * @return mixed |
113 | 113 | */ |
114 | 114 | protected static function executeCode($_code, array $_sharedVars) { |
115 | - foreach($_sharedVars as $var => $value) { |
|
116 | - if(isset($GLOBALS[$var]) && $var[0] == '_') { // extract($this->sharedVars, EXTR_OVERWRITE) and $$var = $value do not overwrites global vars |
|
115 | + foreach ($_sharedVars as $var => $value) { |
|
116 | + if (isset($GLOBALS[$var]) && $var[0] == '_') { // extract($this->sharedVars, EXTR_OVERWRITE) and $$var = $value do not overwrites global vars |
|
117 | 117 | $GLOBALS[$var] = $value; |
118 | 118 | } |
119 | - elseif(!isset($$var)) { |
|
119 | + elseif (!isset($$var)) { |
|
120 | 120 | $$var = $value; |
121 | 121 | } |
122 | 122 | } |
@@ -175,9 +175,9 @@ discard block |
||
175 | 175 | * @codeCoverageIgnore |
176 | 176 | */ |
177 | 177 | protected function forcePhpConsoleClassesAutoLoad() { |
178 | - foreach(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(__DIR__), \RecursiveIteratorIterator::LEAVES_ONLY) as $path) { |
|
178 | + foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(__DIR__), \RecursiveIteratorIterator::LEAVES_ONLY) as $path) { |
|
179 | 179 | /** @var $path \SplFileInfo */ |
180 | - if($path->isFile() && $path->getExtension() == 'php' && $path->getFilename() !== 'PsrLogger.php') { |
|
180 | + if ($path->isFile() && $path->getExtension() == 'php' && $path->getFilename() !== 'PsrLogger.php') { |
|
181 | 181 | require_once($path->getPathname()); |
182 | 182 | } |
183 | 183 | } |
@@ -189,11 +189,11 @@ discard block |
||
189 | 189 | * @codeCoverageIgnore |
190 | 190 | */ |
191 | 191 | protected function applyOpenBaseDirSetting() { |
192 | - if($this->openBaseDirs) { |
|
192 | + if ($this->openBaseDirs) { |
|
193 | 193 | $value = implode(PATH_SEPARATOR, $this->openBaseDirs); |
194 | - if(ini_get('open_basedir') != $value) { |
|
194 | + if (ini_get('open_basedir') != $value) { |
|
195 | 195 | $this->forcePhpConsoleClassesAutoLoad(); |
196 | - if(ini_set('open_basedir', $value) === false) { |
|
196 | + if (ini_set('open_basedir', $value) === false) { |
|
197 | 197 | throw new \Exception('Unable to set "open_basedir" php.ini setting'); |
198 | 198 | } |
199 | 199 | } |
@@ -227,10 +227,10 @@ discard block |
||
227 | 227 | * @throws \Exception |
228 | 228 | */ |
229 | 229 | public function addSharedVarReference($name, &$var) { |
230 | - if(isset($this->sharedVars[$name])) { |
|
230 | + if (isset($this->sharedVars[$name])) { |
|
231 | 231 | throw new \Exception('Var with name "' . $name . '" already added'); |
232 | 232 | } |
233 | - $this->sharedVars[$name] =& $var; |
|
233 | + $this->sharedVars[$name] = & $var; |
|
234 | 234 | } |
235 | 235 | } |
236 | 236 |
@@ -38,11 +38,11 @@ discard block |
||
38 | 38 | * @return Connector |
39 | 39 | */ |
40 | 40 | public static function register(Connector $connector = null, Handler $handler = null) { |
41 | - if(static::$connector) { |
|
41 | + if (static::$connector) { |
|
42 | 42 | throw new \Exception('Helper already registered'); |
43 | 43 | } |
44 | 44 | self::$handler = $handler; |
45 | - self::$connector = $connector ? : Connector::getInstance(); |
|
45 | + self::$connector = $connector ?: Connector::getInstance(); |
|
46 | 46 | self::$isActive = self::$connector->isActiveClient(); |
47 | 47 | return self::$connector; |
48 | 48 | } |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | * @throws \Exception |
62 | 62 | */ |
63 | 63 | public static function getConnector() { |
64 | - if(!self::$connector) { |
|
64 | + if (!self::$connector) { |
|
65 | 65 | throw new \Exception('Helper is not registered. Call ' . get_called_class() . '::register()'); |
66 | 66 | } |
67 | 67 | return self::$connector; |
@@ -73,10 +73,10 @@ discard block |
||
73 | 73 | * @throws \Exception |
74 | 74 | */ |
75 | 75 | public static function getHandler() { |
76 | - if(!self::$connector) { |
|
76 | + if (!self::$connector) { |
|
77 | 77 | throw new \Exception('Helper is not registered. Call ' . get_called_class() . '::register()'); |
78 | 78 | } |
79 | - if(!self::$handler) { |
|
79 | + if (!self::$handler) { |
|
80 | 80 | self::$handler = Handler::getInstance(); |
81 | 81 | } |
82 | 82 | return self::$handler; |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | * @param int|array $ignoreTraceCalls Ignore tracing classes by name prefix `array('PhpConsole')` or fixed number of calls to ignore |
90 | 90 | */ |
91 | 91 | public static function debug($data, $tags = null, $ignoreTraceCalls = 0) { |
92 | - if(self::$isActive) { |
|
92 | + if (self::$isActive) { |
|
93 | 93 | self::$connector->getDebugDispatcher()->dispatchDebug($data, $tags, is_numeric($ignoreTraceCalls) ? $ignoreTraceCalls + 1 : $ignoreTraceCalls); |
94 | 94 | } |
95 | 95 | } |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | * @param $args |
102 | 102 | */ |
103 | 103 | public static function __callStatic($tags, $args) { |
104 | - if(isset($args[1])) { |
|
104 | + if (isset($args[1])) { |
|
105 | 105 | $tags .= '.' . $args[1]; |
106 | 106 | } |
107 | 107 | static::debug(isset($args[0]) ? $args[0] : null, $tags, 1); |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | |
114 | 114 | use PhpConsole\Helper; |
115 | 115 | |
116 | - if(!class_exists('PC', false)) { |
|
116 | + if (!class_exists('PC', false)) { |
|
117 | 117 | /** |
118 | 118 | * Helper short class name in global namespace |
119 | 119 | */ |
@@ -71,11 +71,11 @@ |
||
71 | 71 | */ |
72 | 72 | protected function getClientUid() { |
73 | 73 | $clientUid = ''; |
74 | - if($this->publicKeyByIp) { |
|
75 | - if(isset($_SERVER['REMOTE_ADDR'])) { |
|
74 | + if ($this->publicKeyByIp) { |
|
75 | + if (isset($_SERVER['REMOTE_ADDR'])) { |
|
76 | 76 | $clientUid .= $_SERVER['REMOTE_ADDR']; |
77 | 77 | } |
78 | - if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
|
78 | + if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
|
79 | 79 | $clientUid .= $_SERVER['HTTP_X_FORWARDED_FOR']; |
80 | 80 | } |
81 | 81 | } |
@@ -55,16 +55,16 @@ discard block |
||
55 | 55 | * |
56 | 56 | */ |
57 | 57 | public function log($level, $message, array $context = array()) { |
58 | - if(is_object($message) && is_callable($message, '__toString')) { |
|
58 | + if (is_object($message) && is_callable($message, '__toString')) { |
|
59 | 59 | $message = (string)$message; |
60 | 60 | } |
61 | 61 | $message = $this->fetchMessageContext($message, $context); |
62 | 62 | |
63 | - if(isset(static::$debugLevels[$level])) { |
|
63 | + if (isset(static::$debugLevels[$level])) { |
|
64 | 64 | $this->connector->getDebugDispatcher()->dispatchDebug($message, static::$debugLevels[$level], $this->ignoreTraceCalls); |
65 | 65 | } |
66 | - elseif(isset(static::$errorsLevels[$level])) { |
|
67 | - if(isset($context['exception']) && ($context['exception'] instanceof \Exception || $context['exception'] instanceof \Throwable)) { |
|
66 | + elseif (isset(static::$errorsLevels[$level])) { |
|
67 | + if (isset($context['exception']) && ($context['exception'] instanceof \Exception || $context['exception'] instanceof \Throwable)) { |
|
68 | 68 | $this->connector->getErrorsDispatcher()->dispatchException($context['exception']); |
69 | 69 | } |
70 | 70 | else { |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | |
79 | 79 | protected function fetchMessageContext($message, array $context) { |
80 | 80 | $replace = array(); |
81 | - foreach($context as $key => $value) { |
|
81 | + foreach ($context as $key => $value) { |
|
82 | 82 | $replace['{' . $key . '}'] = $this->contextDumper->dump($value); |
83 | 83 | } |
84 | 84 | return strtr($message, $replace); |
@@ -55,14 +55,14 @@ discard block |
||
55 | 55 | * @param int|array $ignoreTraceCalls Ignore tracing classes by name prefix `array('PhpConsole')` or fixed number of calls to ignore |
56 | 56 | */ |
57 | 57 | public function dispatchError($code = null, $text = null, $file = null, $line = null, $ignoreTraceCalls = 0) { |
58 | - if($this->isActive()) { |
|
58 | + if ($this->isActive()) { |
|
59 | 59 | $message = new ErrorMessage(); |
60 | 60 | $message->code = $code; |
61 | 61 | $message->class = $this->getErrorTypeByCode($code); |
62 | 62 | $message->data = $this->dumper->dump($text); |
63 | 63 | $message->file = $file; |
64 | 64 | $message->line = $line; |
65 | - if($ignoreTraceCalls !== null) { |
|
65 | + if ($ignoreTraceCalls !== null) { |
|
66 | 66 | $message->trace = $this->fetchTrace(debug_backtrace(), $file, $line, is_array($ignoreTraceCalls) ? $ignoreTraceCalls : $ignoreTraceCalls + 1); |
67 | 67 | } |
68 | 68 | $this->sendMessage($message); |
@@ -74,8 +74,8 @@ discard block |
||
74 | 74 | * @param \Exception|\Throwable $exception |
75 | 75 | */ |
76 | 76 | public function dispatchException($exception) { |
77 | - if($this->isActive()) { |
|
78 | - if($this->dispatchPreviousExceptions && $exception->getPrevious()) { |
|
77 | + if ($this->isActive()) { |
|
78 | + if ($this->dispatchPreviousExceptions && $exception->getPrevious()) { |
|
79 | 79 | $this->dispatchException($exception->getPrevious()); |
80 | 80 | } |
81 | 81 | $message = new ErrorMessage(); |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | * @param Message $message |
95 | 95 | */ |
96 | 96 | protected function sendMessage(Message $message) { |
97 | - if(!$this->isIgnored($message)) { |
|
97 | + if (!$this->isIgnored($message)) { |
|
98 | 98 | parent::sendMessage($message); |
99 | 99 | $this->sentMessages[] = $message; |
100 | 100 | } |
@@ -106,14 +106,14 @@ discard block |
||
106 | 106 | * @return string |
107 | 107 | */ |
108 | 108 | protected function getErrorTypeByCode($code) { |
109 | - if(!static::$errorsConstantsValues) { |
|
110 | - foreach(static::$errorsConstantsNames as $constantName) { |
|
111 | - if(defined($constantName)) { |
|
109 | + if (!static::$errorsConstantsValues) { |
|
110 | + foreach (static::$errorsConstantsNames as $constantName) { |
|
111 | + if (defined($constantName)) { |
|
112 | 112 | static::$errorsConstantsValues[constant($constantName)] = $constantName; |
113 | 113 | } |
114 | 114 | } |
115 | 115 | } |
116 | - if(isset(static::$errorsConstantsValues[$code])) { |
|
116 | + if (isset(static::$errorsConstantsValues[$code])) { |
|
117 | 117 | return static::$errorsConstantsValues[$code]; |
118 | 118 | } |
119 | 119 | return (string)$code; |
@@ -125,9 +125,9 @@ discard block |
||
125 | 125 | * @return bool |
126 | 126 | */ |
127 | 127 | protected function isIgnored(ErrorMessage $message) { |
128 | - if($this->ignoreRepeatedSource && $message->file) { |
|
129 | - foreach($this->sentMessages as $sentMessage) { |
|
130 | - if($message->file == $sentMessage->file && $message->line == $sentMessage->line && $message->class == $sentMessage->class) { |
|
128 | + if ($this->ignoreRepeatedSource && $message->file) { |
|
129 | + foreach ($this->sentMessages as $sentMessage) { |
|
130 | + if ($message->file == $sentMessage->file && $message->line == $sentMessage->line && $message->class == $sentMessage->class) { |
|
131 | 131 | return true; |
132 | 132 | } |
133 | 133 | } |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | * @param $code |
54 | 54 | */ |
55 | 55 | public function dispatchCode($code) { |
56 | - if($this->isActive()) { |
|
56 | + if ($this->isActive()) { |
|
57 | 57 | $previousLastError = error_get_last(); |
58 | 58 | $oldDisplayErrors = ini_set('display_errors', false); |
59 | 59 | $result = $this->evalProvider->evaluate($code); |
@@ -65,10 +65,10 @@ discard block |
||
65 | 65 | $message->time = round($result->time, 6); |
66 | 66 | |
67 | 67 | $newLastError = error_get_last(); |
68 | - if($newLastError && $newLastError != $previousLastError) { |
|
68 | + if ($newLastError && $newLastError != $previousLastError) { |
|
69 | 69 | $this->connector->getErrorsDispatcher()->dispatchError($newLastError ['type'], $newLastError ['message'], $newLastError ['file'], $newLastError ['line'], 999); |
70 | 70 | } |
71 | - if($result->exception) { |
|
71 | + if ($result->exception) { |
|
72 | 72 | $this->connector->getErrorsDispatcher()->dispatchException($result->exception); |
73 | 73 | } |
74 | 74 | $this->sendMessage($message); |
@@ -26,13 +26,13 @@ |
||
26 | 26 | * @param int|array $ignoreTraceCalls Ignore tracing classes by name prefix `array('PhpConsole')` or fixed number of calls to ignore |
27 | 27 | */ |
28 | 28 | public function dispatchDebug($data, $tags = null, $ignoreTraceCalls = 0) { |
29 | - if($this->isActive()) { |
|
29 | + if ($this->isActive()) { |
|
30 | 30 | $message = new DebugMessage(); |
31 | 31 | $message->data = $this->dumper->dump($data); |
32 | - if($tags) { |
|
32 | + if ($tags) { |
|
33 | 33 | $message->tags = explode('.', $tags); |
34 | 34 | } |
35 | - if($this->detectTraceAndSource && $ignoreTraceCalls !== null) { |
|
35 | + if ($this->detectTraceAndSource && $ignoreTraceCalls !== null) { |
|
36 | 36 | $message->trace = $this->fetchTrace(debug_backtrace(), $message->file, $message->line, $ignoreTraceCalls); |
37 | 37 | } |
38 | 38 | $this->sendMessage($message); |
@@ -3,7 +3,7 @@ |
||
3 | 3 | require_once(__DIR__ . '/../../src/PhpConsole/__autoload.php'); |
4 | 4 | |
5 | 5 | $password = null; |
6 | -if(!$password) { |
|
6 | +if (!$password) { |
|
7 | 7 | die('Please set $password variable value in ' . __FILE__); |
8 | 8 | } |
9 | 9 |