Passed
Branch php-cs-fixer (b9836a)
by Fabio
15:58
created
framework/Caching/TChainedCacheDependency.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 	 */
37 37
 	public function getDependencies()
38 38
 	{
39
-		if($this->_dependencies === null)
39
+		if ($this->_dependencies === null)
40 40
 			$this->_dependencies = new TCacheDependencyList;
41 41
 		return $this->_dependencies;
42 42
 	}
@@ -49,10 +49,10 @@  discard block
 block discarded – undo
49 49
 	 */
50 50
 	public function getHasChanged()
51 51
 	{
52
-		if($this->_dependencies !== null)
52
+		if ($this->_dependencies !== null)
53 53
 		{
54
-			foreach($this->_dependencies as $dependency)
55
-				if($dependency->getHasChanged())
54
+			foreach ($this->_dependencies as $dependency)
55
+				if ($dependency->getHasChanged())
56 56
 					return true;
57 57
 		}
58 58
 		return false;
Please login to merge, or discard this patch.
Braces   +6 added lines, -4 removed lines patch added patch discarded remove patch
@@ -36,8 +36,9 @@  discard block
 block discarded – undo
36 36
 	 */
37 37
 	public function getDependencies()
38 38
 	{
39
-		if($this->_dependencies === null)
40
-			$this->_dependencies = new TCacheDependencyList;
39
+		if($this->_dependencies === null) {
40
+					$this->_dependencies = new TCacheDependencyList;
41
+		}
41 42
 		return $this->_dependencies;
42 43
 	}
43 44
 
@@ -51,9 +52,10 @@  discard block
 block discarded – undo
51 52
 	{
52 53
 		if($this->_dependencies !== null)
53 54
 		{
54
-			foreach($this->_dependencies as $dependency)
55
-				if($dependency->getHasChanged())
55
+			foreach($this->_dependencies as $dependency) {
56
+							if($dependency->getHasChanged())
56 57
 					return true;
58
+			}
57 59
 		}
58 60
 		return false;
59 61
 	}
Please login to merge, or discard this patch.
framework/Caching/TXCache.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -53,13 +53,13 @@  discard block
 block discarded – undo
53 53
     */
54 54
 	public function init($config)
55 55
 	{
56
-		if(!function_exists('xcache_isset'))
56
+		if (!function_exists('xcache_isset'))
57 57
 			throw new TConfigurationException('xcache_extension_required');
58 58
 
59
-		$enabled = (int)ini_get('xcache.cacher') !== 0;
60
-		$var_size = (int)ini_get('xcache.var_size');
59
+		$enabled = (int) ini_get('xcache.cacher') !== 0;
60
+		$var_size = (int) ini_get('xcache.var_size');
61 61
 
62
-		if(!($enabled && $var_size > 0))
62
+		if (!($enabled && $var_size > 0))
63 63
 			throw new TConfigurationException('xcache_extension_not_enabled');
64 64
 
65 65
 		parent::init($config);
@@ -121,9 +121,9 @@  discard block
 block discarded – undo
121 121
 	 */
122 122
 	public function flush()
123 123
 	{
124
-		for($i = 0, $max = xcache_count(XC_TYPE_VAR); $i < $max; $i++)
124
+		for ($i = 0, $max = xcache_count(XC_TYPE_VAR); $i < $max; $i++)
125 125
 		{
126
-			if(xcache_clear_cache(XC_TYPE_VAR, $i) === false)
126
+			if (xcache_clear_cache(XC_TYPE_VAR, $i) === false)
127 127
 				return false;
128 128
 		}
129 129
 		return true;
Please login to merge, or discard this patch.
Braces   +9 added lines, -6 removed lines patch added patch discarded remove patch
@@ -53,14 +53,16 @@  discard block
 block discarded – undo
53 53
     */
54 54
 	public function init($config)
55 55
 	{
56
-		if(!function_exists('xcache_isset'))
57
-			throw new TConfigurationException('xcache_extension_required');
56
+		if(!function_exists('xcache_isset')) {
57
+					throw new TConfigurationException('xcache_extension_required');
58
+		}
58 59
 
59 60
 		$enabled = (int)ini_get('xcache.cacher') !== 0;
60 61
 		$var_size = (int)ini_get('xcache.var_size');
61 62
 
62
-		if(!($enabled && $var_size > 0))
63
-			throw new TConfigurationException('xcache_extension_not_enabled');
63
+		if(!($enabled && $var_size > 0)) {
64
+					throw new TConfigurationException('xcache_extension_not_enabled');
65
+		}
64 66
 
65 67
 		parent::init($config);
66 68
 	}
@@ -123,8 +125,9 @@  discard block
 block discarded – undo
123 125
 	{
124 126
 		for($i = 0, $max = xcache_count(XC_TYPE_VAR); $i < $max; $i++)
125 127
 		{
126
-			if(xcache_clear_cache(XC_TYPE_VAR, $i) === false)
127
-				return false;
128
+			if(xcache_clear_cache(XC_TYPE_VAR, $i) === false) {
129
+							return false;
130
+			}
128 131
 		}
129 132
 		return true;
130 133
 	}
Please login to merge, or discard this patch.
framework/Caching/TCache.php 2 patches
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -61,11 +61,11 @@  discard block
 block discarded – undo
61 61
 	 */
62 62
 	public function init($config)
63 63
 	{
64
-		if($this->_prefix === null)
64
+		if ($this->_prefix === null)
65 65
 			$this->_prefix = $this->getApplication()->getUniqueID();
66
-		if($this->_primary)
66
+		if ($this->_primary)
67 67
 		{
68
-			if($this->getApplication()->getCache() === null)
68
+			if ($this->getApplication()->getCache() === null)
69 69
 				$this->getApplication()->setCache($this);
70 70
 			else
71 71
 				throw new TConfigurationException('cache_primary_duplicated', get_class($this));
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
 	 */
115 115
 	protected function generateUniqueKey($key)
116 116
 	{
117
-		return md5($this->_prefix . $key);
117
+		return md5($this->_prefix.$key);
118 118
 	}
119 119
 
120 120
 	/**
@@ -124,11 +124,11 @@  discard block
 block discarded – undo
124 124
 	 */
125 125
 	public function get($id)
126 126
 	{
127
-		if(($data = $this->getValue($this->generateUniqueKey($id))) !== false)
127
+		if (($data = $this->getValue($this->generateUniqueKey($id))) !== false)
128 128
 		{
129
-			if(!is_array($data))
129
+			if (!is_array($data))
130 130
 				return false;
131
-			if(!($data[1] instanceof ICacheDependency) || !$data[1]->getHasChanged())
131
+			if (!($data[1] instanceof ICacheDependency) || !$data[1]->getHasChanged())
132 132
 				return $data[0];
133 133
 		}
134 134
 		return false;
@@ -148,11 +148,11 @@  discard block
 block discarded – undo
148 148
 	 */
149 149
 	public function set($id, $value, $expire = 0, $dependency = null)
150 150
 	{
151
-		if(empty($value) && $expire === 0)
151
+		if (empty($value) && $expire === 0)
152 152
 			$this->delete($id);
153 153
 		else
154 154
 		{
155
-			$data = [$value,$dependency];
155
+			$data = [$value, $dependency];
156 156
 			return $this->setValue($this->generateUniqueKey($id), $data, $expire);
157 157
 		}
158 158
 	}
@@ -168,9 +168,9 @@  discard block
 block discarded – undo
168 168
 	 */
169 169
 	public function add($id, $value, $expire = 0, $dependency = null)
170 170
 	{
171
-		if(empty($value) && $expire === 0)
171
+		if (empty($value) && $expire === 0)
172 172
 			return false;
173
-		$data = [$value,$dependency];
173
+		$data = [$value, $dependency];
174 174
 		return $this->addValue($this->generateUniqueKey($id), $data, $expire);
175 175
 	}
176 176
 
Please login to merge, or discard this patch.
Braces   +20 added lines, -15 removed lines patch added patch discarded remove patch
@@ -61,14 +61,16 @@  discard block
 block discarded – undo
61 61
 	 */
62 62
 	public function init($config)
63 63
 	{
64
-		if($this->_prefix === null)
65
-			$this->_prefix = $this->getApplication()->getUniqueID();
64
+		if($this->_prefix === null) {
65
+					$this->_prefix = $this->getApplication()->getUniqueID();
66
+		}
66 67
 		if($this->_primary)
67 68
 		{
68
-			if($this->getApplication()->getCache() === null)
69
-				$this->getApplication()->setCache($this);
70
-			else
71
-				throw new TConfigurationException('cache_primary_duplicated', get_class($this));
69
+			if($this->getApplication()->getCache() === null) {
70
+							$this->getApplication()->setCache($this);
71
+			} else {
72
+							throw new TConfigurationException('cache_primary_duplicated', get_class($this));
73
+			}
72 74
 		}
73 75
 	}
74 76
 
@@ -126,10 +128,12 @@  discard block
 block discarded – undo
126 128
 	{
127 129
 		if(($data = $this->getValue($this->generateUniqueKey($id))) !== false)
128 130
 		{
129
-			if(!is_array($data))
130
-				return false;
131
-			if(!($data[1] instanceof ICacheDependency) || !$data[1]->getHasChanged())
132
-				return $data[0];
131
+			if(!is_array($data)) {
132
+							return false;
133
+			}
134
+			if(!($data[1] instanceof ICacheDependency) || !$data[1]->getHasChanged()) {
135
+							return $data[0];
136
+			}
133 137
 		}
134 138
 		return false;
135 139
 	}
@@ -148,9 +152,9 @@  discard block
 block discarded – undo
148 152
 	 */
149 153
 	public function set($id, $value, $expire = 0, $dependency = null)
150 154
 	{
151
-		if(empty($value) && $expire === 0)
152
-			$this->delete($id);
153
-		else
155
+		if(empty($value) && $expire === 0) {
156
+					$this->delete($id);
157
+		} else
154 158
 		{
155 159
 			$data = [$value,$dependency];
156 160
 			return $this->setValue($this->generateUniqueKey($id), $data, $expire);
@@ -168,8 +172,9 @@  discard block
 block discarded – undo
168 172
 	 */
169 173
 	public function add($id, $value, $expire = 0, $dependency = null)
170 174
 	{
171
-		if(empty($value) && $expire === 0)
172
-			return false;
175
+		if(empty($value) && $expire === 0) {
176
+					return false;
177
+		}
173 178
 		$data = [$value,$dependency];
174 179
 		return $this->addValue($this->generateUniqueKey($id), $data, $expire);
175 180
 	}
Please login to merge, or discard this patch.
framework/Caching/TDbCache.php 2 patches
Spacing   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
 	 */
131 131
 	public function __destruct()
132 132
 	{
133
-		if($this->_db !== null)
133
+		if ($this->_db !== null)
134 134
 			$this->_db->setActive(false);
135 135
 	}
136 136
 
@@ -185,46 +185,46 @@  discard block
 block discarded – undo
185 185
 	 */
186 186
 	protected function initializeCache($force = false)
187 187
 	{
188
-		if($this->_cacheInitialized && !$force) return;
188
+		if ($this->_cacheInitialized && !$force) return;
189 189
 		$db = $this->getDbConnection();
190 190
 		try
191 191
 		{
192
-			$key = 'TDbCache:' . $this->_cacheTable . ':created';
193
-			if($force)
192
+			$key = 'TDbCache:'.$this->_cacheTable.':created';
193
+			if ($force)
194 194
 				$this -> _createCheck = false;
195 195
 			else
196 196
 				$this -> _createCheck = $this -> getApplication() -> getGlobalState($key, 0);
197 197
 
198
-			if($this->_autoCreate && !$this -> _createCheck) {
198
+			if ($this->_autoCreate && !$this -> _createCheck) {
199 199
 
200
-				Prado::trace(($force ? 'Force initializing: ' : 'Initializing: ') . $this -> id . ', ' . $this->_cacheTable, '\Prado\Caching\TDbCache');
200
+				Prado::trace(($force ? 'Force initializing: ' : 'Initializing: ').$this -> id.', '.$this->_cacheTable, '\Prado\Caching\TDbCache');
201 201
 
202
-				$sql = 'SELECT 1 FROM ' . $this->_cacheTable . ' WHERE 0=1';
202
+				$sql = 'SELECT 1 FROM '.$this->_cacheTable.' WHERE 0=1';
203 203
 				$db->createCommand($sql)->queryScalar();
204 204
 
205 205
 				$this -> _createCheck = true;
206 206
 				$this -> getApplication() -> setGlobalState($key, time());
207 207
 			}
208 208
 		}
209
-		catch(\Exception $e)
209
+		catch (\Exception $e)
210 210
 		{
211 211
 			// DB table not exists
212
-			if($this->_autoCreate)
212
+			if ($this->_autoCreate)
213 213
 			{
214
-				Prado::trace('Autocreate: ' . $this->_cacheTable, '\Prado\Caching\TDbCache');
214
+				Prado::trace('Autocreate: '.$this->_cacheTable, '\Prado\Caching\TDbCache');
215 215
 
216 216
 				$driver = $db->getDriverName();
217
-				if($driver === 'mysql')
217
+				if ($driver === 'mysql')
218 218
 					$blob = 'LONGBLOB';
219
-				elseif($driver === 'pgsql')
219
+				elseif ($driver === 'pgsql')
220 220
 					$blob = 'BYTEA';
221 221
 				else
222 222
 					$blob = 'BLOB';
223 223
 
224
-				$sql = 'CREATE TABLE ' . $this->_cacheTable . " (itemkey CHAR(128) PRIMARY KEY, value $blob, expire INTEGER)";
224
+				$sql = 'CREATE TABLE '.$this->_cacheTable." (itemkey CHAR(128) PRIMARY KEY, value $blob, expire INTEGER)";
225 225
 				$db->createCommand($sql)->execute();
226 226
 
227
-				$sql = 'CREATE INDEX IX_expire ON ' . $this->_cacheTable . ' (expire)';
227
+				$sql = 'CREATE INDEX IX_expire ON '.$this->_cacheTable.' (expire)';
228 228
 				$db->createCommand($sql)->execute();
229 229
 
230 230
 				$this -> _createCheck = true;
@@ -245,17 +245,17 @@  discard block
 block discarded – undo
245 245
 	public function flushCacheExpired($force = false)
246 246
 	{
247 247
 		$interval = $this -> getFlushInterval();
248
-		if(!$force && $interval === 0) return;
248
+		if (!$force && $interval === 0) return;
249 249
 
250
-		$key = 'TDbCache:' . $this->_cacheTable . ':flushed';
250
+		$key = 'TDbCache:'.$this->_cacheTable.':flushed';
251 251
 		$now = time();
252
-		$next = $interval + (integer)$this -> getApplication() -> getGlobalState($key, 0);
252
+		$next = $interval + (integer) $this -> getApplication() -> getGlobalState($key, 0);
253 253
 
254
-		if($force || $next <= $now)
254
+		if ($force || $next <= $now)
255 255
 		{
256
-			if(!$this->_cacheInitialized) $this->initializeCache();
257
-			Prado::trace(($force ? 'Force flush of expired items: ' : 'Flush expired items: ') . $this -> id . ', ' . $this->_cacheTable, '\Prado\Caching\TDbCache');
258
-			$sql = 'DELETE FROM ' . $this->_cacheTable . ' WHERE expire<>0 AND expire<' . $now;
256
+			if (!$this->_cacheInitialized) $this->initializeCache();
257
+			Prado::trace(($force ? 'Force flush of expired items: ' : 'Flush expired items: ').$this -> id.', '.$this->_cacheTable, '\Prado\Caching\TDbCache');
258
+			$sql = 'DELETE FROM '.$this->_cacheTable.' WHERE expire<>0 AND expire<'.$now;
259 259
 			$this->getDbConnection()->createCommand($sql)->execute();
260 260
 			$this -> getApplication() -> setGlobalState($key, $now);
261 261
 		}
@@ -292,10 +292,10 @@  discard block
 block discarded – undo
292 292
 	 */
293 293
 	protected function createDbConnection()
294 294
 	{
295
-		if($this->_connID !== '')
295
+		if ($this->_connID !== '')
296 296
 		{
297 297
 			$config = $this->getApplication()->getModule($this->_connID);
298
-			if($config instanceof TDataSourceConfig)
298
+			if ($config instanceof TDataSourceConfig)
299 299
 				return $config->getDbConnection();
300 300
 			else
301 301
 				throw new TConfigurationException('dbcache_connectionid_invalid', $this->_connID);
@@ -303,19 +303,19 @@  discard block
 block discarded – undo
303 303
 		else
304 304
 		{
305 305
 			$db = new TDbConnection;
306
-			if($this->_connectionString !== '')
306
+			if ($this->_connectionString !== '')
307 307
 			{
308 308
 				$db->setConnectionString($this->_connectionString);
309
-				if($this->_username !== '')
309
+				if ($this->_username !== '')
310 310
 					$db->setUsername($this->_username);
311
-				if($this->_password !== '')
311
+				if ($this->_password !== '')
312 312
 					$db->setPassword($this->_password);
313 313
 			}
314 314
 			else
315 315
 			{
316 316
 				// default to SQLite3 database
317
-				$dbFile = $this->getApplication()->getRuntimePath() . '/sqlite3.cache';
318
-				$db->setConnectionString('sqlite:' . $dbFile);
317
+				$dbFile = $this->getApplication()->getRuntimePath().'/sqlite3.cache';
318
+				$db->setConnectionString('sqlite:'.$dbFile);
319 319
 			}
320 320
 			return $db;
321 321
 		}
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
 	 */
327 327
 	public function getDbConnection()
328 328
 	{
329
-		if($this->_db === null)
329
+		if ($this->_db === null)
330 330
 			$this->_db = $this->createDbConnection();
331 331
 
332 332
 		$this->_db->setActive(true);
@@ -463,13 +463,13 @@  discard block
 block discarded – undo
463 463
 	 */
464 464
 	protected function getValue($key)
465 465
 	{
466
-		if(!$this->_cacheInitialized) $this->initializeCache();
466
+		if (!$this->_cacheInitialized) $this->initializeCache();
467 467
 		try {
468
-			$sql = 'SELECT value FROM ' . $this->_cacheTable . ' WHERE itemkey=\'' . $key . '\' AND (expire=0 OR expire>' . time() . ') ORDER BY expire DESC';
468
+			$sql = 'SELECT value FROM '.$this->_cacheTable.' WHERE itemkey=\''.$key.'\' AND (expire=0 OR expire>'.time().') ORDER BY expire DESC';
469 469
 			$command = $this->getDbConnection()->createCommand($sql);
470 470
 			return unserialize($command->queryScalar());
471 471
 		}
472
-		catch(\Exception $e)
472
+		catch (\Exception $e)
473 473
 		{
474 474
 			$this->initializeCache(true);
475 475
 			return unserialize($command->queryScalar());
@@ -502,8 +502,8 @@  discard block
 block discarded – undo
502 502
 	 */
503 503
 	protected function addValue($key, $value, $expire)
504 504
 	{
505
-		if(!$this->_cacheInitialized) $this->initializeCache();
506
-		$expire = ($expire <= 0)?0:time() + $expire;
505
+		if (!$this->_cacheInitialized) $this->initializeCache();
506
+		$expire = ($expire <= 0) ? 0 : time() + $expire;
507 507
 		$sql = "INSERT INTO {$this->_cacheTable} (itemkey,value,expire) VALUES(:key,:value,$expire)";
508 508
 		try
509 509
 		{
@@ -513,7 +513,7 @@  discard block
 block discarded – undo
513 513
 			$command->execute();
514 514
 			return true;
515 515
 		}
516
-		catch(\Exception $e)
516
+		catch (\Exception $e)
517 517
 		{
518 518
 			try
519 519
 			{
@@ -521,7 +521,7 @@  discard block
 block discarded – undo
521 521
 				$command->execute();
522 522
 				return true;
523 523
 			}
524
-			catch(\Exception $e)
524
+			catch (\Exception $e)
525 525
 			{
526 526
 				return false;
527 527
 			}
@@ -536,7 +536,7 @@  discard block
 block discarded – undo
536 536
 	 */
537 537
 	protected function deleteValue($key)
538 538
 	{
539
-		if(!$this->_cacheInitialized) $this->initializeCache();
539
+		if (!$this->_cacheInitialized) $this->initializeCache();
540 540
 		try
541 541
 		{
542 542
 			$command = $this->getDbConnection()->createCommand("DELETE FROM {$this->_cacheTable} WHERE itemkey=:key");
@@ -544,7 +544,7 @@  discard block
 block discarded – undo
544 544
 			$command->execute();
545 545
 			return true;
546 546
 		}
547
-		catch(\Exception $e)
547
+		catch (\Exception $e)
548 548
 		{
549 549
 			$this->initializeCache(true);
550 550
 			$command->execute();
@@ -558,13 +558,13 @@  discard block
 block discarded – undo
558 558
 	 */
559 559
 	public function flush()
560 560
 	{
561
-		if(!$this->_cacheInitialized) $this->initializeCache();
561
+		if (!$this->_cacheInitialized) $this->initializeCache();
562 562
 		try
563 563
 		{
564 564
 			$command = $this->getDbConnection()->createCommand("DELETE FROM {$this->_cacheTable}");
565 565
 			$command->execute();
566 566
 		}
567
-		catch(\Exception $e)
567
+		catch (\Exception $e)
568 568
 		{
569 569
 			try
570 570
 			{
@@ -572,7 +572,7 @@  discard block
 block discarded – undo
572 572
 				$command->execute();
573 573
 				return true;
574 574
 			}
575
-			catch(\Exception $e)
575
+			catch (\Exception $e)
576 576
 			{
577 577
 				return false;
578 578
 			}
Please login to merge, or discard this patch.
Braces   +61 added lines, -49 removed lines patch added patch discarded remove patch
@@ -130,8 +130,9 @@  discard block
 block discarded – undo
130 130
 	 */
131 131
 	public function __destruct()
132 132
 	{
133
-		if($this->_db !== null)
134
-			$this->_db->setActive(false);
133
+		if($this->_db !== null) {
134
+					$this->_db->setActive(false);
135
+		}
135 136
 	}
136 137
 
137 138
 	/**
@@ -185,15 +186,18 @@  discard block
 block discarded – undo
185 186
 	 */
186 187
 	protected function initializeCache($force = false)
187 188
 	{
188
-		if($this->_cacheInitialized && !$force) return;
189
+		if($this->_cacheInitialized && !$force) {
190
+			return;
191
+		}
189 192
 		$db = $this->getDbConnection();
190 193
 		try
191 194
 		{
192 195
 			$key = 'TDbCache:' . $this->_cacheTable . ':created';
193
-			if($force)
194
-				$this -> _createCheck = false;
195
-			else
196
-				$this -> _createCheck = $this -> getApplication() -> getGlobalState($key, 0);
196
+			if($force) {
197
+							$this -> _createCheck = false;
198
+			} else {
199
+							$this -> _createCheck = $this -> getApplication() -> getGlobalState($key, 0);
200
+			}
197 201
 
198 202
 			if($this->_autoCreate && !$this -> _createCheck) {
199 203
 
@@ -205,8 +209,7 @@  discard block
 block discarded – undo
205 209
 				$this -> _createCheck = true;
206 210
 				$this -> getApplication() -> setGlobalState($key, time());
207 211
 			}
208
-		}
209
-		catch(\Exception $e)
212
+		} catch(\Exception $e)
210 213
 		{
211 214
 			// DB table not exists
212 215
 			if($this->_autoCreate)
@@ -214,12 +217,13 @@  discard block
 block discarded – undo
214 217
 				Prado::trace('Autocreate: ' . $this->_cacheTable, '\Prado\Caching\TDbCache');
215 218
 
216 219
 				$driver = $db->getDriverName();
217
-				if($driver === 'mysql')
218
-					$blob = 'LONGBLOB';
219
-				elseif($driver === 'pgsql')
220
-					$blob = 'BYTEA';
221
-				else
222
-					$blob = 'BLOB';
220
+				if($driver === 'mysql') {
221
+									$blob = 'LONGBLOB';
222
+				} elseif($driver === 'pgsql') {
223
+									$blob = 'BYTEA';
224
+				} else {
225
+									$blob = 'BLOB';
226
+				}
223 227
 
224 228
 				$sql = 'CREATE TABLE ' . $this->_cacheTable . " (itemkey CHAR(128) PRIMARY KEY, value $blob, expire INTEGER)";
225 229
 				$db->createCommand($sql)->execute();
@@ -229,9 +233,9 @@  discard block
 block discarded – undo
229 233
 
230 234
 				$this -> _createCheck = true;
231 235
 				$this -> getApplication() -> setGlobalState($key, time());
236
+			} else {
237
+							throw new TConfigurationException('db_cachetable_inexistent', $this->_cacheTable);
232 238
 			}
233
-			else
234
-				throw new TConfigurationException('db_cachetable_inexistent', $this->_cacheTable);
235 239
 		}
236 240
 		$this->_cacheInitialized = true;
237 241
 	}
@@ -245,7 +249,9 @@  discard block
 block discarded – undo
245 249
 	public function flushCacheExpired($force = false)
246 250
 	{
247 251
 		$interval = $this -> getFlushInterval();
248
-		if(!$force && $interval === 0) return;
252
+		if(!$force && $interval === 0) {
253
+			return;
254
+		}
249 255
 
250 256
 		$key = 'TDbCache:' . $this->_cacheTable . ':flushed';
251 257
 		$now = time();
@@ -253,7 +259,9 @@  discard block
 block discarded – undo
253 259
 
254 260
 		if($force || $next <= $now)
255 261
 		{
256
-			if(!$this->_cacheInitialized) $this->initializeCache();
262
+			if(!$this->_cacheInitialized) {
263
+				$this->initializeCache();
264
+			}
257 265
 			Prado::trace(($force ? 'Force flush of expired items: ' : 'Flush expired items: ') . $this -> id . ', ' . $this->_cacheTable, '\Prado\Caching\TDbCache');
258 266
 			$sql = 'DELETE FROM ' . $this->_cacheTable . ' WHERE expire<>0 AND expire<' . $now;
259 267
 			$this->getDbConnection()->createCommand($sql)->execute();
@@ -295,23 +303,24 @@  discard block
 block discarded – undo
295 303
 		if($this->_connID !== '')
296 304
 		{
297 305
 			$config = $this->getApplication()->getModule($this->_connID);
298
-			if($config instanceof TDataSourceConfig)
299
-				return $config->getDbConnection();
300
-			else
301
-				throw new TConfigurationException('dbcache_connectionid_invalid', $this->_connID);
302
-		}
303
-		else
306
+			if($config instanceof TDataSourceConfig) {
307
+							return $config->getDbConnection();
308
+			} else {
309
+							throw new TConfigurationException('dbcache_connectionid_invalid', $this->_connID);
310
+			}
311
+		} else
304 312
 		{
305 313
 			$db = new TDbConnection;
306 314
 			if($this->_connectionString !== '')
307 315
 			{
308 316
 				$db->setConnectionString($this->_connectionString);
309
-				if($this->_username !== '')
310
-					$db->setUsername($this->_username);
311
-				if($this->_password !== '')
312
-					$db->setPassword($this->_password);
313
-			}
314
-			else
317
+				if($this->_username !== '') {
318
+									$db->setUsername($this->_username);
319
+				}
320
+				if($this->_password !== '') {
321
+									$db->setPassword($this->_password);
322
+				}
323
+			} else
315 324
 			{
316 325
 				// default to SQLite3 database
317 326
 				$dbFile = $this->getApplication()->getRuntimePath() . '/sqlite3.cache';
@@ -326,8 +335,9 @@  discard block
 block discarded – undo
326 335
 	 */
327 336
 	public function getDbConnection()
328 337
 	{
329
-		if($this->_db === null)
330
-			$this->_db = $this->createDbConnection();
338
+		if($this->_db === null) {
339
+					$this->_db = $this->createDbConnection();
340
+		}
331 341
 
332 342
 		$this->_db->setActive(true);
333 343
 		return $this->_db;
@@ -463,13 +473,14 @@  discard block
 block discarded – undo
463 473
 	 */
464 474
 	protected function getValue($key)
465 475
 	{
466
-		if(!$this->_cacheInitialized) $this->initializeCache();
476
+		if(!$this->_cacheInitialized) {
477
+			$this->initializeCache();
478
+		}
467 479
 		try {
468 480
 			$sql = 'SELECT value FROM ' . $this->_cacheTable . ' WHERE itemkey=\'' . $key . '\' AND (expire=0 OR expire>' . time() . ') ORDER BY expire DESC';
469 481
 			$command = $this->getDbConnection()->createCommand($sql);
470 482
 			return unserialize($command->queryScalar());
471
-		}
472
-		catch(\Exception $e)
483
+		} catch(\Exception $e)
473 484
 		{
474 485
 			$this->initializeCache(true);
475 486
 			return unserialize($command->queryScalar());
@@ -502,7 +513,9 @@  discard block
 block discarded – undo
502 513
 	 */
503 514
 	protected function addValue($key, $value, $expire)
504 515
 	{
505
-		if(!$this->_cacheInitialized) $this->initializeCache();
516
+		if(!$this->_cacheInitialized) {
517
+			$this->initializeCache();
518
+		}
506 519
 		$expire = ($expire <= 0)?0:time() + $expire;
507 520
 		$sql = "INSERT INTO {$this->_cacheTable} (itemkey,value,expire) VALUES(:key,:value,$expire)";
508 521
 		try
@@ -512,16 +525,14 @@  discard block
 block discarded – undo
512 525
 			$command->bindValue(':value', serialize($value), \PDO::PARAM_LOB);
513 526
 			$command->execute();
514 527
 			return true;
515
-		}
516
-		catch(\Exception $e)
528
+		} catch(\Exception $e)
517 529
 		{
518 530
 			try
519 531
 			{
520 532
 				$this->initializeCache(true);
521 533
 				$command->execute();
522 534
 				return true;
523
-			}
524
-			catch(\Exception $e)
535
+			} catch(\Exception $e)
525 536
 			{
526 537
 				return false;
527 538
 			}
@@ -536,15 +547,16 @@  discard block
 block discarded – undo
536 547
 	 */
537 548
 	protected function deleteValue($key)
538 549
 	{
539
-		if(!$this->_cacheInitialized) $this->initializeCache();
550
+		if(!$this->_cacheInitialized) {
551
+			$this->initializeCache();
552
+		}
540 553
 		try
541 554
 		{
542 555
 			$command = $this->getDbConnection()->createCommand("DELETE FROM {$this->_cacheTable} WHERE itemkey=:key");
543 556
 			$command->bindValue(':key', $key, \PDO::PARAM_STR);
544 557
 			$command->execute();
545 558
 			return true;
546
-		}
547
-		catch(\Exception $e)
559
+		} catch(\Exception $e)
548 560
 		{
549 561
 			$this->initializeCache(true);
550 562
 			$command->execute();
@@ -558,21 +570,21 @@  discard block
 block discarded – undo
558 570
 	 */
559 571
 	public function flush()
560 572
 	{
561
-		if(!$this->_cacheInitialized) $this->initializeCache();
573
+		if(!$this->_cacheInitialized) {
574
+			$this->initializeCache();
575
+		}
562 576
 		try
563 577
 		{
564 578
 			$command = $this->getDbConnection()->createCommand("DELETE FROM {$this->_cacheTable}");
565 579
 			$command->execute();
566
-		}
567
-		catch(\Exception $e)
580
+		} catch(\Exception $e)
568 581
 		{
569 582
 			try
570 583
 			{
571 584
 				$this->initializeCache(true);
572 585
 				$command->execute();
573 586
 				return true;
574
-			}
575
-			catch(\Exception $e)
587
+			} catch(\Exception $e)
576 588
 			{
577 589
 				return false;
578 590
 			}
Please login to merge, or discard this patch.
framework/Caching/TDirectoryCacheDependency.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
 	 */
64 64
 	public function setDirectory($directory)
65 65
 	{
66
-		if(($path = realpath($directory)) === false || !is_dir($path))
66
+		if (($path = realpath($directory)) === false || !is_dir($path))
67 67
 			throw new TInvalidDataValueException('directorycachedependency_directory_invalid', $directory);
68 68
 		$this->_directory = $path;
69 69
 		$this->_timestamps = $this->generateTimestamps($path);
@@ -154,20 +154,20 @@  discard block
 block discarded – undo
154 154
 	 */
155 155
 	protected function generateTimestamps($directory, $level = 0)
156 156
 	{
157
-		if(($dir = opendir($directory)) === false)
157
+		if (($dir = opendir($directory)) === false)
158 158
 			throw new TIOException('directorycachedependency_directory_invalid', $directory);
159 159
 		$timestamps = [];
160
-		while(($file = readdir($dir)) !== false)
160
+		while (($file = readdir($dir)) !== false)
161 161
 		{
162
-			$path = $directory . DIRECTORY_SEPARATOR . $file;
163
-			if($file === '.' || $file === '..')
162
+			$path = $directory.DIRECTORY_SEPARATOR.$file;
163
+			if ($file === '.' || $file === '..')
164 164
 				continue;
165
-			elseif(is_dir($path))
165
+			elseif (is_dir($path))
166 166
 			{
167
-				if(($this->_recursiveLevel < 0 || $level < $this->_recursiveLevel) && $this->validateDirectory($path))
167
+				if (($this->_recursiveLevel < 0 || $level < $this->_recursiveLevel) && $this->validateDirectory($path))
168 168
 					$timestamps = array_merge($this->generateTimestamps($path, $level + 1));
169 169
 			}
170
-			elseif($this->validateFile($path))
170
+			elseif ($this->validateFile($path))
171 171
 				$timestamps[$path] = filemtime($path);
172 172
 		}
173 173
 		closedir($dir);
Please login to merge, or discard this patch.
Braces   +14 added lines, -11 removed lines patch added patch discarded remove patch
@@ -63,8 +63,9 @@  discard block
 block discarded – undo
63 63
 	 */
64 64
 	public function setDirectory($directory)
65 65
 	{
66
-		if(($path = realpath($directory)) === false || !is_dir($path))
67
-			throw new TInvalidDataValueException('directorycachedependency_directory_invalid', $directory);
66
+		if(($path = realpath($directory)) === false || !is_dir($path)) {
67
+					throw new TInvalidDataValueException('directorycachedependency_directory_invalid', $directory);
68
+		}
68 69
 		$this->_directory = $path;
69 70
 		$this->_timestamps = $this->generateTimestamps($path);
70 71
 	}
@@ -154,21 +155,23 @@  discard block
 block discarded – undo
154 155
 	 */
155 156
 	protected function generateTimestamps($directory, $level = 0)
156 157
 	{
157
-		if(($dir = opendir($directory)) === false)
158
-			throw new TIOException('directorycachedependency_directory_invalid', $directory);
158
+		if(($dir = opendir($directory)) === false) {
159
+					throw new TIOException('directorycachedependency_directory_invalid', $directory);
160
+		}
159 161
 		$timestamps = [];
160 162
 		while(($file = readdir($dir)) !== false)
161 163
 		{
162 164
 			$path = $directory . DIRECTORY_SEPARATOR . $file;
163
-			if($file === '.' || $file === '..')
164
-				continue;
165
-			elseif(is_dir($path))
165
+			if($file === '.' || $file === '..') {
166
+							continue;
167
+			} elseif(is_dir($path))
166 168
 			{
167
-				if(($this->_recursiveLevel < 0 || $level < $this->_recursiveLevel) && $this->validateDirectory($path))
168
-					$timestamps = array_merge($this->generateTimestamps($path, $level + 1));
169
+				if(($this->_recursiveLevel < 0 || $level < $this->_recursiveLevel) && $this->validateDirectory($path)) {
170
+									$timestamps = array_merge($this->generateTimestamps($path, $level + 1));
171
+				}
172
+			} elseif($this->validateFile($path)) {
173
+							$timestamps[$path] = filemtime($path);
169 174
 			}
170
-			elseif($this->validateFile($path))
171
-				$timestamps[$path] = filemtime($path);
172 175
 		}
173 176
 		closedir($dir);
174 177
 		return $timestamps;
Please login to merge, or discard this patch.
framework/Util/TLogRouter.php 2 patches
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -64,11 +64,11 @@  discard block
 block discarded – undo
64 64
 	 */
65 65
 	public function init($config)
66 66
 	{
67
-		if($this->_configFile !== null)
67
+		if ($this->_configFile !== null)
68 68
 		{
69
-			if(is_file($this->_configFile))
69
+			if (is_file($this->_configFile))
70 70
 			{
71
-				if($this->getApplication()->getConfigurationType() == TApplication::CONFIG_TYPE_PHP)
71
+				if ($this->getApplication()->getConfigurationType() == TApplication::CONFIG_TYPE_PHP)
72 72
 				{
73 73
 					$phpConfig = include $this->_configFile;
74 74
 					$this->loadConfig($phpConfig);
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 				throw new TConfigurationException('logrouter_configfile_invalid', $this->_configFile);
85 85
 		}
86 86
 		$this->loadConfig($config);
87
-		$this->getApplication()->attachEventHandler('OnEndRequest', [$this,'collectLogs']);
87
+		$this->getApplication()->attachEventHandler('OnEndRequest', [$this, 'collectLogs']);
88 88
 	}
89 89
 
90 90
 	/**
@@ -94,19 +94,19 @@  discard block
 block discarded – undo
94 94
 	 */
95 95
 	private function loadConfig($config)
96 96
 	{
97
-		if(is_array($config))
97
+		if (is_array($config))
98 98
 		{
99
-			if(isset($config['routes']) && is_array($config['routes']))
99
+			if (isset($config['routes']) && is_array($config['routes']))
100 100
 			{
101
-				foreach($config['routes'] as $route)
101
+				foreach ($config['routes'] as $route)
102 102
 				{
103
-					$properties = isset($route['properties'])?$route['properties']:[];
104
-					if(!isset($route['class']))
103
+					$properties = isset($route['properties']) ? $route['properties'] : [];
104
+					if (!isset($route['class']))
105 105
 						throw new TConfigurationException('logrouter_routeclass_required');
106 106
 					$route = Prado::createComponent($route['class']);
107
-					if(!($route instanceof TLogRoute))
107
+					if (!($route instanceof TLogRoute))
108 108
 						throw new TConfigurationException('logrouter_routetype_invalid');
109
-					foreach($properties as $name => $value)
109
+					foreach ($properties as $name => $value)
110 110
 						$route->setSubproperty($name, $value);
111 111
 					$this->_routes[] = $route;
112 112
 					$route->init($route);
@@ -115,15 +115,15 @@  discard block
 block discarded – undo
115 115
 		}
116 116
 		else
117 117
 		{
118
-			foreach($config->getElementsByTagName('route') as $routeConfig)
118
+			foreach ($config->getElementsByTagName('route') as $routeConfig)
119 119
 			{
120 120
 				$properties = $routeConfig->getAttributes();
121
-				if(($class = $properties->remove('class')) === null)
121
+				if (($class = $properties->remove('class')) === null)
122 122
 					throw new TConfigurationException('logrouter_routeclass_required');
123 123
 				$route = Prado::createComponent($class);
124
-				if(!($route instanceof TLogRoute))
124
+				if (!($route instanceof TLogRoute))
125 125
 					throw new TConfigurationException('logrouter_routetype_invalid');
126
-				foreach($properties as $name => $value)
126
+				foreach ($properties as $name => $value)
127 127
 					$route->setSubproperty($name, $value);
128 128
 				$this->_routes[] = $route;
129 129
 				$route->init($routeConfig);
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
 	 */
140 140
 	public function addRoute($route)
141 141
 	{
142
-		if(!($route instanceof TLogRoute))
142
+		if (!($route instanceof TLogRoute))
143 143
 			throw new TInvalidDataTypeException('logrouter_routetype_invalid');
144 144
 		$this->_routes[] = $route;
145 145
 		$route->init(null);
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
 	 */
161 161
 	public function setConfigFile($value)
162 162
 	{
163
-		if(($this->_configFile = Prado::getPathOfNamespace($value, $this->getApplication()->getConfigurationFileExt())) === null)
163
+		if (($this->_configFile = Prado::getPathOfNamespace($value, $this->getApplication()->getConfigurationFileExt())) === null)
164 164
 			throw new TConfigurationException('logrouter_configfile_invalid', $value);
165 165
 	}
166 166
 
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
 	public function collectLogs($param)
173 173
 	{
174 174
 		$logger = Prado::getLogger();
175
-		foreach($this->_routes as $route)
175
+		foreach ($this->_routes as $route)
176 176
 			$route->collectLogs($logger);
177 177
 	}
178 178
 }
179 179
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +31 added lines, -24 removed lines patch added patch discarded remove patch
@@ -72,16 +72,15 @@  discard block
 block discarded – undo
72 72
 				{
73 73
 					$phpConfig = include $this->_configFile;
74 74
 					$this->loadConfig($phpConfig);
75
-				}
76
-				else
75
+				} else
77 76
 				{
78 77
 					$dom = new TXmlDocument;
79 78
 					$dom->loadFromFile($this->_configFile);
80 79
 					$this->loadConfig($dom);
81 80
 				}
81
+			} else {
82
+							throw new TConfigurationException('logrouter_configfile_invalid', $this->_configFile);
82 83
 			}
83
-			else
84
-				throw new TConfigurationException('logrouter_configfile_invalid', $this->_configFile);
85 84
 		}
86 85
 		$this->loadConfig($config);
87 86
 		$this->getApplication()->attachEventHandler('OnEndRequest', [$this,'collectLogs']);
@@ -101,30 +100,35 @@  discard block
 block discarded – undo
101 100
 				foreach($config['routes'] as $route)
102 101
 				{
103 102
 					$properties = isset($route['properties'])?$route['properties']:[];
104
-					if(!isset($route['class']))
105
-						throw new TConfigurationException('logrouter_routeclass_required');
103
+					if(!isset($route['class'])) {
104
+											throw new TConfigurationException('logrouter_routeclass_required');
105
+					}
106 106
 					$route = Prado::createComponent($route['class']);
107
-					if(!($route instanceof TLogRoute))
108
-						throw new TConfigurationException('logrouter_routetype_invalid');
109
-					foreach($properties as $name => $value)
110
-						$route->setSubproperty($name, $value);
107
+					if(!($route instanceof TLogRoute)) {
108
+											throw new TConfigurationException('logrouter_routetype_invalid');
109
+					}
110
+					foreach($properties as $name => $value) {
111
+											$route->setSubproperty($name, $value);
112
+					}
111 113
 					$this->_routes[] = $route;
112 114
 					$route->init($route);
113 115
 				}
114 116
 			}
115
-		}
116
-		else
117
+		} else
117 118
 		{
118 119
 			foreach($config->getElementsByTagName('route') as $routeConfig)
119 120
 			{
120 121
 				$properties = $routeConfig->getAttributes();
121
-				if(($class = $properties->remove('class')) === null)
122
-					throw new TConfigurationException('logrouter_routeclass_required');
122
+				if(($class = $properties->remove('class')) === null) {
123
+									throw new TConfigurationException('logrouter_routeclass_required');
124
+				}
123 125
 				$route = Prado::createComponent($class);
124
-				if(!($route instanceof TLogRoute))
125
-					throw new TConfigurationException('logrouter_routetype_invalid');
126
-				foreach($properties as $name => $value)
127
-					$route->setSubproperty($name, $value);
126
+				if(!($route instanceof TLogRoute)) {
127
+									throw new TConfigurationException('logrouter_routetype_invalid');
128
+				}
129
+				foreach($properties as $name => $value) {
130
+									$route->setSubproperty($name, $value);
131
+				}
128 132
 				$this->_routes[] = $route;
129 133
 				$route->init($routeConfig);
130 134
 			}
@@ -139,8 +143,9 @@  discard block
 block discarded – undo
139 143
 	 */
140 144
 	public function addRoute($route)
141 145
 	{
142
-		if(!($route instanceof TLogRoute))
143
-			throw new TInvalidDataTypeException('logrouter_routetype_invalid');
146
+		if(!($route instanceof TLogRoute)) {
147
+					throw new TInvalidDataTypeException('logrouter_routetype_invalid');
148
+		}
144 149
 		$this->_routes[] = $route;
145 150
 		$route->init(null);
146 151
 	}
@@ -160,8 +165,9 @@  discard block
 block discarded – undo
160 165
 	 */
161 166
 	public function setConfigFile($value)
162 167
 	{
163
-		if(($this->_configFile = Prado::getPathOfNamespace($value, $this->getApplication()->getConfigurationFileExt())) === null)
164
-			throw new TConfigurationException('logrouter_configfile_invalid', $value);
168
+		if(($this->_configFile = Prado::getPathOfNamespace($value, $this->getApplication()->getConfigurationFileExt())) === null) {
169
+					throw new TConfigurationException('logrouter_configfile_invalid', $value);
170
+		}
165 171
 	}
166 172
 
167 173
 	/**
@@ -172,7 +178,8 @@  discard block
 block discarded – undo
172 178
 	public function collectLogs($param)
173 179
 	{
174 180
 		$logger = Prado::getLogger();
175
-		foreach($this->_routes as $route)
176
-			$route->collectLogs($logger);
181
+		foreach($this->_routes as $route) {
182
+					$route->collectLogs($logger);
183
+		}
177 184
 	}
178 185
 }
179 186
\ No newline at end of file
Please login to merge, or discard this patch.
framework/Util/TEmailLogRoute.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -68,9 +68,9 @@  discard block
 block discarded – undo
68 68
 	 */
69 69
 	public function init($config)
70 70
 	{
71
-		if($this->_from === '')
71
+		if ($this->_from === '')
72 72
 			$this->_from = ini_get('sendmail_from');
73
-		if($this->_from === '')
73
+		if ($this->_from === '')
74 74
 			throw new TConfigurationException('emaillogroute_sentfrom_required');
75 75
 	}
76 76
 
@@ -81,11 +81,11 @@  discard block
 block discarded – undo
81 81
 	protected function processLogs($logs)
82 82
 	{
83 83
 		$message = '';
84
-		foreach($logs as $log)
84
+		foreach ($logs as $log)
85 85
 			$message .= $this->formatLogMessage($log[0], $log[1], $log[2], $log[3]);
86 86
 		$message = wordwrap($message, 70);
87 87
 		$returnPath = ini_get('sendmail_path') ? "Return-Path:{$this->_from}\r\n" : '';
88
-		foreach($this->_emails as $email)
88
+		foreach ($this->_emails as $email)
89 89
 			mail($email, $this->getSubject(), $message, "From:{$this->_from}\r\n{$returnPath}");
90 90
 
91 91
 	}
@@ -104,15 +104,15 @@  discard block
 block discarded – undo
104 104
 	 */
105 105
 	public function setEmails($emails)
106 106
 	{
107
-		if(is_array($emails))
107
+		if (is_array($emails))
108 108
 			$this->_emails = $emails;
109 109
 		else
110 110
 		{
111 111
 			$this->_emails = [];
112
-			foreach(explode(',', $emails) as $email)
112
+			foreach (explode(',', $emails) as $email)
113 113
 			{
114 114
 				$email = trim($email);
115
-				if(preg_match(self::EMAIL_PATTERN, $email))
115
+				if (preg_match(self::EMAIL_PATTERN, $email))
116 116
 					$this->_emails[] = $email;
117 117
 			}
118 118
 		}
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
 	 */
124 124
 	public function getSubject()
125 125
 	{
126
-		if($this->_subject === null)
126
+		if ($this->_subject === null)
127 127
 			$this->_subject = self::DEFAULT_SUBJECT;
128 128
 		return $this->_subject;
129 129
 	}
Please login to merge, or discard this patch.
Braces   +21 added lines, -15 removed lines patch added patch discarded remove patch
@@ -68,10 +68,12 @@  discard block
 block discarded – undo
68 68
 	 */
69 69
 	public function init($config)
70 70
 	{
71
-		if($this->_from === '')
72
-			$this->_from = ini_get('sendmail_from');
73
-		if($this->_from === '')
74
-			throw new TConfigurationException('emaillogroute_sentfrom_required');
71
+		if($this->_from === '') {
72
+					$this->_from = ini_get('sendmail_from');
73
+		}
74
+		if($this->_from === '') {
75
+					throw new TConfigurationException('emaillogroute_sentfrom_required');
76
+		}
75 77
 	}
76 78
 
77 79
 	/**
@@ -81,12 +83,14 @@  discard block
 block discarded – undo
81 83
 	protected function processLogs($logs)
82 84
 	{
83 85
 		$message = '';
84
-		foreach($logs as $log)
85
-			$message .= $this->formatLogMessage($log[0], $log[1], $log[2], $log[3]);
86
+		foreach($logs as $log) {
87
+					$message .= $this->formatLogMessage($log[0], $log[1], $log[2], $log[3]);
88
+		}
86 89
 		$message = wordwrap($message, 70);
87 90
 		$returnPath = ini_get('sendmail_path') ? "Return-Path:{$this->_from}\r\n" : '';
88
-		foreach($this->_emails as $email)
89
-			mail($email, $this->getSubject(), $message, "From:{$this->_from}\r\n{$returnPath}");
91
+		foreach($this->_emails as $email) {
92
+					mail($email, $this->getSubject(), $message, "From:{$this->_from}\r\n{$returnPath}");
93
+		}
90 94
 
91 95
 	}
92 96
 
@@ -104,16 +108,17 @@  discard block
 block discarded – undo
104 108
 	 */
105 109
 	public function setEmails($emails)
106 110
 	{
107
-		if(is_array($emails))
108
-			$this->_emails = $emails;
109
-		else
111
+		if(is_array($emails)) {
112
+					$this->_emails = $emails;
113
+		} else
110 114
 		{
111 115
 			$this->_emails = [];
112 116
 			foreach(explode(',', $emails) as $email)
113 117
 			{
114 118
 				$email = trim($email);
115
-				if(preg_match(self::EMAIL_PATTERN, $email))
116
-					$this->_emails[] = $email;
119
+				if(preg_match(self::EMAIL_PATTERN, $email)) {
120
+									$this->_emails[] = $email;
121
+				}
117 122
 			}
118 123
 		}
119 124
 	}
@@ -123,8 +128,9 @@  discard block
 block discarded – undo
123 128
 	 */
124 129
 	public function getSubject()
125 130
 	{
126
-		if($this->_subject === null)
127
-			$this->_subject = self::DEFAULT_SUBJECT;
131
+		if($this->_subject === null) {
132
+					$this->_subject = self::DEFAULT_SUBJECT;
133
+		}
128 134
 		return $this->_subject;
129 135
 	}
130 136
 
Please login to merge, or discard this patch.
framework/Util/TLogRoute.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -90,16 +90,16 @@  discard block
 block discarded – undo
90 90
 	 */
91 91
 	public function setLevels($levels)
92 92
 	{
93
-		if(is_int($levels))
93
+		if (is_int($levels))
94 94
 			$this->_levels = $levels;
95 95
 		else
96 96
 		{
97 97
 			$this->_levels = null;
98 98
 			$levels = strtolower($levels);
99
-			foreach(explode(',', $levels) as $level)
99
+			foreach (explode(',', $levels) as $level)
100 100
 			{
101 101
 				$level = trim($level);
102
-				if(isset(self::$_levelValues[$level]))
102
+				if (isset(self::$_levelValues[$level]))
103 103
 					$this->_levels |= self::$_levelValues[$level];
104 104
 			}
105 105
 		}
@@ -119,14 +119,14 @@  discard block
 block discarded – undo
119 119
 	 */
120 120
 	public function setCategories($categories)
121 121
 	{
122
-		if(is_array($categories))
122
+		if (is_array($categories))
123 123
 			$this->_categories = $categories;
124 124
 		else
125 125
 		{
126 126
 			$this->_categories = null;
127
-			foreach(explode(',', $categories) as $category)
127
+			foreach (explode(',', $categories) as $category)
128 128
 			{
129
-				if(($category = trim($category)) !== '')
129
+				if (($category = trim($category)) !== '')
130 130
 					$this->_categories[] = $category;
131 131
 			}
132 132
 		}
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
 	 */
139 139
 	protected function getLevelName($level)
140 140
 	{
141
-		return isset(self::$_levelNames[$level])?self::$_levelNames[$level]:'Unknown';
141
+		return isset(self::$_levelNames[$level]) ?self::$_levelNames[$level] : 'Unknown';
142 142
 	}
143 143
 
144 144
 	/**
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
 	 */
148 148
 	protected function getLevelValue($level)
149 149
 	{
150
-		return isset(self::$_levelValues[$level])?self::$_levelValues[$level]:0;
150
+		return isset(self::$_levelValues[$level]) ?self::$_levelValues[$level] : 0;
151 151
 	}
152 152
 
153 153
 	/**
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
 	 */
161 161
 	protected function formatLogMessage($message, $level, $category, $time)
162 162
 	{
163
-		return @date('M d H:i:s', $time) . ' [' . $this->getLevelName($level) . '] [' . $category . '] ' . $message . "\n";
163
+		return @date('M d H:i:s', $time).' ['.$this->getLevelName($level).'] ['.$category.'] '.$message."\n";
164 164
 	}
165 165
 
166 166
 	/**
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
 	public function collectLogs(TLogger $logger)
171 171
 	{
172 172
 		$logs = $logger->getLogs($this->getLevels(), $this->getCategories());
173
-		if(!empty($logs))
173
+		if (!empty($logs))
174 174
 			$this->processLogs($logs);
175 175
 	}
176 176
 
Please login to merge, or discard this patch.
Braces   +15 added lines, -12 removed lines patch added patch discarded remove patch
@@ -90,17 +90,18 @@  discard block
 block discarded – undo
90 90
 	 */
91 91
 	public function setLevels($levels)
92 92
 	{
93
-		if(is_int($levels))
94
-			$this->_levels = $levels;
95
-		else
93
+		if(is_int($levels)) {
94
+					$this->_levels = $levels;
95
+		} else
96 96
 		{
97 97
 			$this->_levels = null;
98 98
 			$levels = strtolower($levels);
99 99
 			foreach(explode(',', $levels) as $level)
100 100
 			{
101 101
 				$level = trim($level);
102
-				if(isset(self::$_levelValues[$level]))
103
-					$this->_levels |= self::$_levelValues[$level];
102
+				if(isset(self::$_levelValues[$level])) {
103
+									$this->_levels |= self::$_levelValues[$level];
104
+				}
104 105
 			}
105 106
 		}
106 107
 	}
@@ -119,15 +120,16 @@  discard block
 block discarded – undo
119 120
 	 */
120 121
 	public function setCategories($categories)
121 122
 	{
122
-		if(is_array($categories))
123
-			$this->_categories = $categories;
124
-		else
123
+		if(is_array($categories)) {
124
+					$this->_categories = $categories;
125
+		} else
125 126
 		{
126 127
 			$this->_categories = null;
127 128
 			foreach(explode(',', $categories) as $category)
128 129
 			{
129
-				if(($category = trim($category)) !== '')
130
-					$this->_categories[] = $category;
130
+				if(($category = trim($category)) !== '') {
131
+									$this->_categories[] = $category;
132
+				}
131 133
 			}
132 134
 		}
133 135
 	}
@@ -170,8 +172,9 @@  discard block
 block discarded – undo
170 172
 	public function collectLogs(TLogger $logger)
171 173
 	{
172 174
 		$logs = $logger->getLogs($this->getLevels(), $this->getCategories());
173
-		if(!empty($logs))
174
-			$this->processLogs($logs);
175
+		if(!empty($logs)) {
176
+					$this->processLogs($logs);
177
+		}
175 178
 	}
176 179
 
177 180
 	/**
Please login to merge, or discard this patch.
framework/Util/TFileLogRoute.php 2 patches
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
 	 */
57 57
 	public function getLogPath()
58 58
 	{
59
-		if($this->_logPath === null)
59
+		if ($this->_logPath === null)
60 60
 			$this->_logPath = $this->getApplication()->getRuntimePath();
61 61
 		return $this->_logPath;
62 62
 	}
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 	 */
68 68
 	public function setLogPath($value)
69 69
 	{
70
-		if(($this->_logPath = Prado::getPathOfNamespace($value)) === null || !is_dir($this->_logPath) || !is_writable($this->_logPath))
70
+		if (($this->_logPath = Prado::getPathOfNamespace($value)) === null || !is_dir($this->_logPath) || !is_writable($this->_logPath))
71 71
 			throw new TConfigurationException('filelogroute_logpath_invalid', $value);
72 72
 	}
73 73
 
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 	public function setMaxFileSize($value)
103 103
 	{
104 104
 		$this->_maxFileSize = TPropertyValue::ensureInteger($value);
105
-		if($this->_maxFileSize <= 0)
105
+		if ($this->_maxFileSize <= 0)
106 106
 			throw new TInvalidDataValueException('filelogroute_maxfilesize_invalid');
107 107
 	}
108 108
 
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
 	public function setMaxLogFiles($value)
121 121
 	{
122 122
 		$this->_maxLogFiles = TPropertyValue::ensureInteger($value);
123
-		if($this->_maxLogFiles < 1)
123
+		if ($this->_maxLogFiles < 1)
124 124
 			throw new TInvalidDataValueException('filelogroute_maxlogfiles_invalid');
125 125
 	}
126 126
 
@@ -130,10 +130,10 @@  discard block
 block discarded – undo
130 130
 	 */
131 131
 	protected function processLogs($logs)
132 132
 	{
133
-		$logFile = $this->getLogPath() . DIRECTORY_SEPARATOR . $this->getLogFile();
134
-		if(@filesize($logFile) > $this->_maxFileSize * 1024)
133
+		$logFile = $this->getLogPath().DIRECTORY_SEPARATOR.$this->getLogFile();
134
+		if (@filesize($logFile) > $this->_maxFileSize * 1024)
135 135
 			$this->rotateFiles();
136
-		foreach($logs as $log)
136
+		foreach ($logs as $log)
137 137
 			error_log($this->formatLogMessage($log[0], $log[1], $log[2], $log[3]), 3, $logFile);
138 138
 	}
139 139
 
@@ -142,19 +142,19 @@  discard block
 block discarded – undo
142 142
 	 */
143 143
 	protected function rotateFiles()
144 144
 	{
145
-		$file = $this->getLogPath() . DIRECTORY_SEPARATOR . $this->getLogFile();
146
-		for($i = $this->_maxLogFiles;$i > 0;--$i)
145
+		$file = $this->getLogPath().DIRECTORY_SEPARATOR.$this->getLogFile();
146
+		for ($i = $this->_maxLogFiles; $i > 0; --$i)
147 147
 		{
148
-			$rotateFile = $file . '.' . $i;
149
-			if(is_file($rotateFile))
148
+			$rotateFile = $file.'.'.$i;
149
+			if (is_file($rotateFile))
150 150
 			{
151
-				if($i === $this->_maxLogFiles)
151
+				if ($i === $this->_maxLogFiles)
152 152
 					unlink($rotateFile);
153 153
 				else
154
-					rename($rotateFile, $file . '.' . ($i + 1));
154
+					rename($rotateFile, $file.'.'.($i + 1));
155 155
 			}
156 156
 		}
157
-		if(is_file($file))
158
-			rename($file, $file . '.1');
157
+		if (is_file($file))
158
+			rename($file, $file.'.1');
159 159
 	}
160 160
 }
161 161
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +26 added lines, -18 removed lines patch added patch discarded remove patch
@@ -56,8 +56,9 @@  discard block
 block discarded – undo
56 56
 	 */
57 57
 	public function getLogPath()
58 58
 	{
59
-		if($this->_logPath === null)
60
-			$this->_logPath = $this->getApplication()->getRuntimePath();
59
+		if($this->_logPath === null) {
60
+					$this->_logPath = $this->getApplication()->getRuntimePath();
61
+		}
61 62
 		return $this->_logPath;
62 63
 	}
63 64
 
@@ -67,8 +68,9 @@  discard block
 block discarded – undo
67 68
 	 */
68 69
 	public function setLogPath($value)
69 70
 	{
70
-		if(($this->_logPath = Prado::getPathOfNamespace($value)) === null || !is_dir($this->_logPath) || !is_writable($this->_logPath))
71
-			throw new TConfigurationException('filelogroute_logpath_invalid', $value);
71
+		if(($this->_logPath = Prado::getPathOfNamespace($value)) === null || !is_dir($this->_logPath) || !is_writable($this->_logPath)) {
72
+					throw new TConfigurationException('filelogroute_logpath_invalid', $value);
73
+		}
72 74
 	}
73 75
 
74 76
 	/**
@@ -102,8 +104,9 @@  discard block
 block discarded – undo
102 104
 	public function setMaxFileSize($value)
103 105
 	{
104 106
 		$this->_maxFileSize = TPropertyValue::ensureInteger($value);
105
-		if($this->_maxFileSize <= 0)
106
-			throw new TInvalidDataValueException('filelogroute_maxfilesize_invalid');
107
+		if($this->_maxFileSize <= 0) {
108
+					throw new TInvalidDataValueException('filelogroute_maxfilesize_invalid');
109
+		}
107 110
 	}
108 111
 
109 112
 	/**
@@ -120,8 +123,9 @@  discard block
 block discarded – undo
120 123
 	public function setMaxLogFiles($value)
121 124
 	{
122 125
 		$this->_maxLogFiles = TPropertyValue::ensureInteger($value);
123
-		if($this->_maxLogFiles < 1)
124
-			throw new TInvalidDataValueException('filelogroute_maxlogfiles_invalid');
126
+		if($this->_maxLogFiles < 1) {
127
+					throw new TInvalidDataValueException('filelogroute_maxlogfiles_invalid');
128
+		}
125 129
 	}
126 130
 
127 131
 	/**
@@ -131,10 +135,12 @@  discard block
 block discarded – undo
131 135
 	protected function processLogs($logs)
132 136
 	{
133 137
 		$logFile = $this->getLogPath() . DIRECTORY_SEPARATOR . $this->getLogFile();
134
-		if(@filesize($logFile) > $this->_maxFileSize * 1024)
135
-			$this->rotateFiles();
136
-		foreach($logs as $log)
137
-			error_log($this->formatLogMessage($log[0], $log[1], $log[2], $log[3]), 3, $logFile);
138
+		if(@filesize($logFile) > $this->_maxFileSize * 1024) {
139
+					$this->rotateFiles();
140
+		}
141
+		foreach($logs as $log) {
142
+					error_log($this->formatLogMessage($log[0], $log[1], $log[2], $log[3]), 3, $logFile);
143
+		}
138 144
 	}
139 145
 
140 146
 	/**
@@ -148,13 +154,15 @@  discard block
 block discarded – undo
148 154
 			$rotateFile = $file . '.' . $i;
149 155
 			if(is_file($rotateFile))
150 156
 			{
151
-				if($i === $this->_maxLogFiles)
152
-					unlink($rotateFile);
153
-				else
154
-					rename($rotateFile, $file . '.' . ($i + 1));
157
+				if($i === $this->_maxLogFiles) {
158
+									unlink($rotateFile);
159
+				} else {
160
+									rename($rotateFile, $file . '.' . ($i + 1));
161
+				}
155 162
 			}
156 163
 		}
157
-		if(is_file($file))
158
-			rename($file, $file . '.1');
164
+		if(is_file($file)) {
165
+					rename($file, $file . '.1');
166
+		}
159 167
 	}
160 168
 }
161 169
\ No newline at end of file
Please login to merge, or discard this patch.