@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | * @param null|string $sourceBasePath |
59 | 59 | */ |
60 | 60 | public static function start($handleErrors = true, $handleExceptions = true, $sourceBasePath = null) { |
61 | - if(self::$instance) { |
|
61 | + if (self::$instance) { |
|
62 | 62 | die('PhpConsole already started'); |
63 | 63 | } |
64 | 64 | self::$instance = new static(); |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | } |
75 | 75 | |
76 | 76 | public static function getInstance() { |
77 | - if(!self::$instance) { |
|
77 | + if (!self::$instance) { |
|
78 | 78 | throw new \Exception('PhpConsole not started'); |
79 | 79 | } |
80 | 80 | return self::$instance; |
@@ -113,13 +113,13 @@ discard block |
||
113 | 113 | use PhpConsole\Handler; |
114 | 114 | use PhpConsole\OldVersionAdapter; |
115 | 115 | |
116 | - if(!class_exists('PhpConsole', false)) { |
|
116 | + if (!class_exists('PhpConsole', false)) { |
|
117 | 117 | class PhpConsole extends OldVersionAdapter { |
118 | 118 | |
119 | 119 | } |
120 | 120 | } |
121 | 121 | |
122 | - if(!function_exists('debug')) { |
|
122 | + if (!function_exists('debug')) { |
|
123 | 123 | function debug($message, $tags = 'debug') { |
124 | 124 | Handler::getInstance()->debug($message, $tags, 1); |
125 | 125 | } |
@@ -2,8 +2,8 @@ |
||
2 | 2 | |
3 | 3 | namespace PhpConsole; |
4 | 4 | |
5 | -spl_autoload_register(function ($class) { |
|
6 | - if(strpos($class, __NAMESPACE__) === 0) { |
|
5 | +spl_autoload_register(function($class) { |
|
6 | + if (strpos($class, __NAMESPACE__) === 0) { |
|
7 | 7 | /** @noinspection PhpIncludeInspection */ |
8 | 8 | require_once(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $class) . '.php'); |
9 | 9 | } |
@@ -22,12 +22,12 @@ discard block |
||
22 | 22 | |
23 | 23 | public function __construct($server = 'mongodb://localhost:27017', $db = 'phpconsole', $collection = 'phpconsole') { |
24 | 24 | $this->mongoClient = new \MongoClient($server); |
25 | - if(!$this->mongoClient) { |
|
25 | + if (!$this->mongoClient) { |
|
26 | 26 | throw new \Exception('Unable to connect to MongoDB server'); |
27 | 27 | } |
28 | 28 | |
29 | 29 | $this->mongoCollection = $this->mongoClient->selectCollection($db, $collection); |
30 | - if(!$this->mongoCollection) { |
|
30 | + if (!$this->mongoCollection) { |
|
31 | 31 | throw new \Exception('Unable to get collection'); |
32 | 32 | } |
33 | 33 | |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | */ |
66 | 66 | protected function get($key) { |
67 | 67 | $record = $this->mongoCollection->findOne(array('key' => $key)); |
68 | - if($record && is_array($record) && array_key_exists('data', $record)) { |
|
68 | + if ($record && is_array($record) && array_key_exists('data', $record)) { |
|
69 | 69 | return $record['data']; |
70 | 70 | } |
71 | 71 | } |
@@ -45,7 +45,7 @@ |
||
45 | 45 | */ |
46 | 46 | public function pop($key) { |
47 | 47 | $data = $this->get($key); |
48 | - if($data) { |
|
48 | + if ($data) { |
|
49 | 49 | $this->delete($key); |
50 | 50 | } |
51 | 51 | return $data; |
@@ -20,7 +20,7 @@ |
||
20 | 20 | |
21 | 21 | public function __construct($host = 'localhost', $port = 11211) { |
22 | 22 | $this->memcache = new \Memcache(); |
23 | - if(!$this->memcache->connect($host, $port)) { |
|
23 | + if (!$this->memcache->connect($host, $port)) { |
|
24 | 24 | throw new \Exception('Unable to connect to Memcache server'); |
25 | 25 | } |
26 | 26 | } |
@@ -21,7 +21,7 @@ |
||
21 | 21 | * @param bool $autoStart Start session if it's not started |
22 | 22 | */ |
23 | 23 | public function __construct($sessionKey = '__PHP_Console_postponed', $autoStart = true) { |
24 | - if($autoStart && (defined('PHP_SESSION_ACTIVE') ? session_status() != PHP_SESSION_ACTIVE : !session_id()) && !headers_sent()) { |
|
24 | + if ($autoStart && (defined('PHP_SESSION_ACTIVE') ? session_status() != PHP_SESSION_ACTIVE : !session_id()) && !headers_sent()) { |
|
25 | 25 | session_start(); |
26 | 26 | } |
27 | 27 | register_shutdown_function('session_write_close'); // force saving session data if session handler is overridden |
@@ -23,14 +23,14 @@ discard block |
||
23 | 23 | * @throws \Exception |
24 | 24 | */ |
25 | 25 | public function __construct($filePath, $validatePathNotUnderDocRoot = true) { |
26 | - if(!file_exists($filePath)) { |
|
27 | - if(file_put_contents($filePath, '') === false) { |
|
26 | + if (!file_exists($filePath)) { |
|
27 | + if (file_put_contents($filePath, '') === false) { |
|
28 | 28 | throw new \Exception('Unable to write file ' . $filePath); |
29 | 29 | } |
30 | 30 | } |
31 | 31 | $this->filePath = realpath($filePath); |
32 | 32 | |
33 | - if($validatePathNotUnderDocRoot && $this->isPathUnderDocRoot()) { |
|
33 | + if ($validatePathNotUnderDocRoot && $this->isPathUnderDocRoot()) { |
|
34 | 34 | throw new \Exception('Path ' . $this->filePath . ' is under DOCUMENT_ROOT. It\'s insecure!'); |
35 | 35 | } |
36 | 36 | } |
@@ -41,10 +41,10 @@ discard block |
||
41 | 41 | |
42 | 42 | protected function initFileHandler() { |
43 | 43 | $this->fileHandler = fopen($this->filePath, 'a+b'); |
44 | - if(!$this->fileHandler) { |
|
44 | + if (!$this->fileHandler) { |
|
45 | 45 | throw new \Exception('Unable to read/write file ' . $this->filePath); |
46 | 46 | } |
47 | - while(!flock($this->fileHandler, LOCK_EX | LOCK_NB)) { |
|
47 | + while (!flock($this->fileHandler, LOCK_EX | LOCK_NB)) { |
|
48 | 48 | usleep(10000); |
49 | 49 | } |
50 | 50 | fseek($this->fileHandler, 0); |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | * @return array |
56 | 56 | */ |
57 | 57 | protected function getKeysData() { |
58 | - return json_decode(fgets($this->fileHandler), true) ? : array(); |
|
58 | + return json_decode(fgets($this->fileHandler), true) ?: array(); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | } |
68 | 68 | |
69 | 69 | protected function closeFileHandler() { |
70 | - if($this->fileHandler) { |
|
70 | + if ($this->fileHandler) { |
|
71 | 71 | flock($this->fileHandler, LOCK_UN); |
72 | 72 | fclose($this->fileHandler); |
73 | 73 | $this->fileHandler = null; |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | */ |
35 | 35 | public function pop($key) { |
36 | 36 | $keysData = $this->getKeysData(); |
37 | - if(isset($keysData[$key])) { |
|
37 | + if (isset($keysData[$key])) { |
|
38 | 38 | $keyData = $keysData[$key]['data']; |
39 | 39 | unset($keysData[$key]); |
40 | 40 | $this->saveKeysData($keysData); |
@@ -63,8 +63,8 @@ discard block |
||
63 | 63 | */ |
64 | 64 | protected function clearExpiredKeys(array &$keysData) { |
65 | 65 | $expireTime = time() - $this->keyLifetime; |
66 | - foreach($keysData as $key => $item) { |
|
67 | - if($item['time'] < $expireTime) { |
|
66 | + foreach ($keysData as $key => $item) { |
|
67 | + if ($item['time'] < $expireTime) { |
|
68 | 68 | unset($keysData[$key]); |
69 | 69 | } |
70 | 70 | } |
@@ -64,33 +64,33 @@ discard block |
||
64 | 64 | $ignoreByNumber = is_numeric($ignoreTraceCalls) ? $ignoreTraceCalls : 0; |
65 | 65 | $ignoreByClassPrefixes = is_array($ignoreTraceCalls) ? array_merge($ignoreTraceCalls, array(__NAMESPACE__)) : null; |
66 | 66 | |
67 | - foreach($trace as $i => $call) { |
|
68 | - if(!$file && $i == $ignoreTraceCalls && isset($call['file'])) { |
|
67 | + foreach ($trace as $i => $call) { |
|
68 | + if (!$file && $i == $ignoreTraceCalls && isset($call['file'])) { |
|
69 | 69 | $file = $call['file']; |
70 | 70 | $line = $call['line']; |
71 | 71 | } |
72 | - if($ignoreByClassPrefixes && isset($call['class'])) { |
|
73 | - foreach($ignoreByClassPrefixes as $classPrefix) { |
|
74 | - if(strpos($call['class'], $classPrefix) !== false) { |
|
72 | + if ($ignoreByClassPrefixes && isset($call['class'])) { |
|
73 | + foreach ($ignoreByClassPrefixes as $classPrefix) { |
|
74 | + if (strpos($call['class'], $classPrefix) !== false) { |
|
75 | 75 | unset($trace[$i]); |
76 | 76 | continue; |
77 | 77 | } |
78 | 78 | } |
79 | 79 | } |
80 | - if($i < $ignoreByNumber || (isset($call['file']) && $call['file'] == $file && $call['line'] == $line)) { |
|
80 | + if ($i < $ignoreByNumber || (isset($call['file']) && $call['file'] == $file && $call['line'] == $line)) { |
|
81 | 81 | unset($trace[$i]); |
82 | 82 | } |
83 | 83 | } |
84 | 84 | |
85 | 85 | $traceCalls = array(); |
86 | - foreach(array_reverse($trace) as $call) { |
|
86 | + foreach (array_reverse($trace) as $call) { |
|
87 | 87 | $args = array(); |
88 | - if(isset($call['args'])) { |
|
89 | - foreach($call['args'] as $arg) { |
|
90 | - if(is_object($arg)) { |
|
88 | + if (isset($call['args'])) { |
|
89 | + foreach ($call['args'] as $arg) { |
|
90 | + if (is_object($arg)) { |
|
91 | 91 | $args[] = get_class($arg); |
92 | 92 | } |
93 | - elseif(is_array($arg)) { |
|
93 | + elseif (is_array($arg)) { |
|
94 | 94 | $args[] = 'Array[' . count($arg) . ']'; |
95 | 95 | } |
96 | 96 | else { |
@@ -100,16 +100,16 @@ discard block |
||
100 | 100 | } |
101 | 101 | } |
102 | 102 | |
103 | - if(strpos($call['function'], '{closure}')) { |
|
103 | + if (strpos($call['function'], '{closure}')) { |
|
104 | 104 | $call['function'] = '{closure}'; |
105 | 105 | } |
106 | 106 | |
107 | 107 | $traceCall = new TraceCall(); |
108 | 108 | $traceCall->call = (isset($call['class']) ? $call['class'] . $call['type'] : '') . $call['function'] . '(' . implode(', ', $args) . ')'; |
109 | - if(isset($call['file'])) { |
|
109 | + if (isset($call['file'])) { |
|
110 | 110 | $traceCall->file = $call['file']; |
111 | 111 | } |
112 | - if(isset($call['line'])) { |
|
112 | + if (isset($call['line'])) { |
|
113 | 113 | $traceCall->line = $call['line']; |
114 | 114 | } |
115 | 115 | $traceCalls[] = $traceCall; |