Test Failed
Push — 1.0.0-dev ( 92a7f9...7e13dc )
by nguereza
04:45
created
tests/hmvc/models/DBSessionModel.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-	class DBSessionModel extends DBSessionHandlerModel{
2
+	class DBSessionModel extends DBSessionHandlerModel {
3 3
 		
4 4
 		protected $_table = 'ses';
5 5
 		protected $primary_key = 's_id';
@@ -14,14 +14,14 @@  discard block
 block discarded – undo
14 14
 			'skey' => 'test_id' //VARCHAR(255) 
15 15
 		);
16 16
 		
17
-		public function deleteByTime($time){
17
+		public function deleteByTime($time) {
18 18
 			$this->_database->from($this->_table)
19 19
 						->where('s_time', '<', $time)
20 20
 						->delete();
21 21
 		}
22 22
 
23 23
 		
24
-		public function getKeyValue(){
24
+		public function getKeyValue() {
25 25
 			$user_id = 0;
26 26
 			return $user_id;
27 27
 		}
Please login to merge, or discard this patch.
tests/include/common.php 1 patch
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -29,14 +29,14 @@  discard block
 block discarded – undo
29 29
 		//put the first letter of class to upper case 
30 30
 		$class = ucfirst($class);
31 31
 		static $classes = array();
32
-		if(isset($classes[$class]) /*hack for duplicate log Logger name*/ && $class != 'Log'){
32
+		if (isset($classes[$class]) /*hack for duplicate log Logger name*/ && $class != 'Log') {
33 33
 			return $classes[$class];
34 34
 		}
35 35
 		$found = false;
36 36
 		foreach (array(ROOT_PATH, CORE_PATH) as $path) {
37 37
 			$file = $path . $dir . '/' . $class . '.php';
38
-			if(file_exists($file)){
39
-				if(class_exists($class, false) == false){
38
+			if (file_exists($file)) {
39
+				if (class_exists($class, false) == false) {
40 40
 					require_once $file;
41 41
 				}
42 42
 				//already found
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
 				break;
45 45
 			}
46 46
 		}
47
-		if(! $found){
47
+		if (!$found) {
48 48
 			//can't use show_error() at this time because some dependencies not yet loaded
49 49
 			set_http_status_header(503);
50 50
 			echo 'Cannot find the class [' . $class . ']';
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 		/*
55 55
 		   TODO use the best method to get the Log instance
56 56
 		 */
57
-		if($class == 'Log'){
57
+		if ($class == 'Log') {
58 58
 			//can't use the instruction like "return new Log()" 
59 59
 			//because we need return the reference instance of the loaded class.
60 60
 			$log = new Log();
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 
73 73
 	function & class_loaded($class = null){
74 74
 		static $list = array();
75
-		if($class != null){
75
+		if ($class != null) {
76 76
 			$list[strtolower($class)] = $class;
77 77
 		}
78 78
 		return $list;
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
 
81 81
 	function & load_configurations(array $overwrite_values = array()){
82 82
 		static $config;
83
-		if(empty($config)){
83
+		if (empty($config)) {
84 84
 			$file = CONFIG_PATH . 'config.php';
85 85
 			require_once $file;
86 86
 		
@@ -94,50 +94,50 @@  discard block
 block discarded – undo
94 94
 	/**
95 95
 	*  @test
96 96
 	*/
97
-	function get_config($key, $default = null){
97
+	function get_config($key, $default = null) {
98 98
 		static $cfg;
99
-		if(empty($cfg)){
99
+		if (empty($cfg)) {
100 100
 			$cfg[0] = & load_configurations();
101 101
 		}
102 102
 		return array_key_exists($key, $cfg[0]) ? $cfg[0][$key] : $default;
103 103
 	}
104 104
 
105
-	function save_to_log($level, $message, $logger = null){
105
+	function save_to_log($level, $message, $logger = null) {
106 106
 		return true;
107 107
 	}
108 108
 
109 109
 	
110
-	function set_http_status_header($code = 200, $text = null){
110
+	function set_http_status_header($code = 200, $text = null) {
111 111
 		return true;
112 112
 	}
113 113
 
114 114
 	
115
-	function show_error($msg, $title = 'error', $logging = true){
115
+	function show_error($msg, $title = 'error', $logging = true) {
116 116
 		//show only and continue to help track of some error occured
117
-		echo 'TNHFW Error: '.$msg . "\n";
117
+		echo 'TNHFW Error: ' . $msg . "\n";
118 118
 	}
119 119
 
120
-	function is_https(){
120
+	function is_https() {
121 121
 		return false;
122 122
 	}
123 123
 	
124 124
 	/**
125 125
 	*  @test
126 126
 	*/
127
-	function is_url($url){
127
+	function is_url($url) {
128 128
 		return preg_match('/^(http|https|ftp):\/\/(.*)/', $url);
129 129
 	}
130 130
 		
131
-	function php_exception_handler($ex){
132
-		throw new RuntimeException('PHP Exception : '.$ex->getMessage().' | '.$ex->getFile().' | '.$ex->getLine());
131
+	function php_exception_handler($ex) {
132
+		throw new RuntimeException('PHP Exception : ' . $ex->getMessage() . ' | ' . $ex->getFile() . ' | ' . $ex->getLine());
133 133
 	}
134 134
 	
135 135
 	
136
-	function php_error_handler($errno , $errstr, $errfile , $errline, array $errcontext = array()){
137
-		throw new RuntimeException('TNHFW Exception Error : '.$errstr.' | '.$errfile.' | '.$errline);
136
+	function php_error_handler($errno, $errstr, $errfile, $errline, array $errcontext = array()) {
137
+		throw new RuntimeException('TNHFW Exception Error : ' . $errstr . ' | ' . $errfile . ' | ' . $errline);
138 138
 	}
139 139
 
140
-	function php_shudown_handler(){
140
+	function php_shudown_handler() {
141 141
 		return true;
142 142
 	}
143 143
 
@@ -145,11 +145,11 @@  discard block
 block discarded – undo
145 145
 	/**
146 146
 	*  @test
147 147
 	*/
148
-	function attributes_to_string(array $attributes){
148
+	function attributes_to_string(array $attributes) {
149 149
 		$str = ' ';
150 150
 		//we check that the array passed as an argument is not empty.
151
-		if(! empty($attributes)){
152
-			foreach($attributes as $key => $value){
151
+		if (!empty($attributes)) {
152
+			foreach ($attributes as $key => $value) {
153 153
 				$key = trim(htmlspecialchars($key));
154 154
 				$value = trim(htmlspecialchars($value));
155 155
 				/*
@@ -159,35 +159,35 @@  discard block
 block discarded – undo
159 159
 				* 	$attr = array('placeholder' => 'I am a "puple"')
160 160
 				* 	$str = attributes_to_string($attr); => placeholder = "I am a \"puple\""
161 161
 				 */
162
-				if($value && strpos('"', $value) !== false){
162
+				if ($value && strpos('"', $value) !== false) {
163 163
 					$value = addslashes($value);
164 164
 				}
165
-				$str .= $key.' = "'.$value.'" ';
165
+				$str .= $key . ' = "' . $value . '" ';
166 166
 			}
167 167
 		}
168 168
 		//remove the space after using rtrim()
169 169
 		return rtrim($str);
170 170
 	}
171 171
 
172
-	function stringfy_vars($var){
172
+	function stringfy_vars($var) {
173 173
 		return print_r($var, true);
174 174
 	}
175 175
 
176 176
 	/**
177 177
 	*  @test
178 178
 	*/
179
-	function clean_input($str){
180
-		if(is_array($str)){
179
+	function clean_input($str) {
180
+		if (is_array($str)) {
181 181
 			$str = array_map('clean_input', $str);
182 182
 		}
183
-		else if(is_object($str)){
183
+		else if (is_object($str)) {
184 184
 			$obj = $str;
185 185
 			foreach ($str as $var => $value) {
186 186
 				$obj->$var = clean_input($value);
187 187
 			}
188 188
 			$str = $obj;
189 189
 		}
190
-		else{
190
+		else {
191 191
 			$str = htmlspecialchars(strip_tags($str), ENT_QUOTES, 'UTF-8');
192 192
 		}
193 193
 		return $str;
@@ -196,11 +196,11 @@  discard block
 block discarded – undo
196 196
 	/**
197 197
 	*  @test
198 198
 	*/
199
-	function string_hidden($str, $startCount = 0, $endCount = 0, $hiddenChar = '*'){
199
+	function string_hidden($str, $startCount = 0, $endCount = 0, $hiddenChar = '*') {
200 200
 		//get the string length
201 201
 		$len = strlen($str);
202 202
 		//if str is empty
203
-		if($len <= 0){
203
+		if ($len <= 0) {
204 204
 			return str_repeat($hiddenChar, 6);
205 205
 		}
206 206
 		//if the length is less than startCount and endCount
@@ -208,14 +208,14 @@  discard block
 block discarded – undo
208 208
 		//or startCount is negative or endCount is negative
209 209
 		//return the full string hidden
210 210
 		
211
-		if((($startCount + $endCount) > $len) || ($startCount == 0 && $endCount == 0) || ($startCount < 0 || $endCount < 0)){
211
+		if ((($startCount + $endCount) > $len) || ($startCount == 0 && $endCount == 0) || ($startCount < 0 || $endCount < 0)) {
212 212
 			return str_repeat($hiddenChar, $len);
213 213
 		}
214 214
 		//the start non hidden string
215 215
 		$startNonHiddenStr = substr($str, 0, $startCount);
216 216
 		//the end non hidden string
217 217
 		$endNonHiddenStr = null;
218
-		if($endCount > 0){
218
+		if ($endCount > 0) {
219 219
 			$endNonHiddenStr = substr($str, - $endCount);
220 220
 		}
221 221
 		//the hidden string
@@ -224,12 +224,12 @@  discard block
 block discarded – undo
224 224
 		return $startNonHiddenStr . $hiddenStr . $endNonHiddenStr;
225 225
 	}
226 226
 	
227
-	function set_session_config(){
227
+	function set_session_config() {
228 228
 		return true;
229 229
 	}
230 230
 	
231 231
 	function & get_instance(){
232
-		if(! Controller::get_instance()){
232
+		if (!Controller::get_instance()) {
233 233
 			$c = new Controller();
234 234
 		}
235 235
 		return Controller::get_instance();
Please login to merge, or discard this patch.
tests/bootstrap.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 	/**
61 61
 	* Custom application path for tests 
62 62
 	*/
63
-	define('APPS_PATH', TESTS_PATH .'hmvc' . DS);
63
+	define('APPS_PATH', TESTS_PATH . 'hmvc' . DS);
64 64
 
65 65
 	/**
66 66
 	* The path to the controller directory of your application.
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
 	* It contains your modules used files (config, controllers, libraries, etc.) that is to say which contains your files of the modules, 
197 197
 	* in HMVC architecture (hierichical, controllers, models, views).
198 198
 	*/
199
-	define('MODULE_PATH', dirname(realpath(__FILE__)) . DS .'hmvc' . DS . 'modules' . DS);
199
+	define('MODULE_PATH', dirname(realpath(__FILE__)) . DS . 'hmvc' . DS . 'modules' . DS);
200 200
 
201 201
 	/**
202 202
 	* The path to the directory of sources external to your application.
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
 	//Fix to allow test as if application is running in CLI mode $_SESSION global variable is not available
236 236
 	$_SESSION = array();
237 237
 	
238
-	if(! isset($_SERVER['REMOTE_ADDR'])){ 
238
+	if (!isset($_SERVER['REMOTE_ADDR'])) { 
239 239
 		$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
240 240
 	}
241 241
 
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
 	require_once  'include/autoloader.php';
244 244
 	
245 245
 	//check for composer autoload file if exists include it
246
-	if(file_exists(VENDOR_PATH . 'autoload.php')){
246
+	if (file_exists(VENDOR_PATH . 'autoload.php')) {
247 247
 		require_once VENDOR_PATH . 'autoload.php';
248 248
 		
249 249
 		//define the class alias for vstream
Please login to merge, or discard this patch.
tests/tnhfw/CommonTest.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -24,20 +24,20 @@
 block discarded – undo
24 24
 		}
25 25
 
26 26
 		
27
-		public function testFunctionGetConfigKeyNotExist(){
27
+		public function testFunctionGetConfigKeyNotExist() {
28 28
 			$key = 'foo';
29 29
 			$cfg = get_config($key);
30 30
 			$this->assertNull($cfg);
31 31
 		}
32 32
 		
33
-		public function testFunctionGetConfigKeyNotExistUsingDefaultValue(){
33
+		public function testFunctionGetConfigKeyNotExistUsingDefaultValue() {
34 34
 			$key = 'foo';
35 35
 			$expected = 'bar';
36 36
 			$cfg = get_config($key, $expected);
37 37
 			$this->assertEquals($cfg, $expected);
38 38
 		}
39 39
 		
40
-		public function testFunctionGetConfigAfterSet(){
40
+		public function testFunctionGetConfigAfterSet() {
41 41
 			$key = 'foo';
42 42
 			$expected = 'bar';
43 43
 			$c = new Config();
Please login to merge, or discard this patch.
core/classes/Database.php 1 patch
Spacing   +257 added lines, -257 removed lines patch added patch discarded remove patch
@@ -23,158 +23,158 @@  discard block
 block discarded – undo
23 23
    * along with this program; if not, write to the Free Software
24 24
    * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
   */
26
-  class Database{
26
+  class Database {
27 27
 	
28 28
 	/**
29 29
 	 * The PDO instance
30 30
 	 * @var object
31 31
 	*/
32
-    private $pdo                 = null;
32
+    private $pdo = null;
33 33
     
34 34
 	/**
35 35
 	 * The database name used for the application
36 36
 	 * @var string
37 37
 	*/
38
-	private $databaseName        = null;
38
+	private $databaseName = null;
39 39
     
40 40
 	/**
41 41
 	 * The SQL SELECT statment
42 42
 	 * @var string
43 43
 	*/
44
-	private $select              = '*';
44
+	private $select = '*';
45 45
 	
46 46
 	/**
47 47
 	 * The SQL FROM statment
48 48
 	 * @var string
49 49
 	*/
50
-    private $from                = null;
50
+    private $from = null;
51 51
 	
52 52
 	/**
53 53
 	 * The SQL WHERE statment
54 54
 	 * @var string
55 55
 	*/
56
-    private $where               = null;
56
+    private $where = null;
57 57
 	
58 58
 	/**
59 59
 	 * The SQL LIMIT statment
60 60
 	 * @var string
61 61
 	*/
62
-    private $limit               = null;
62
+    private $limit = null;
63 63
 	
64 64
 	/**
65 65
 	 * The SQL JOIN statment
66 66
 	 * @var string
67 67
 	*/
68
-    private $join                = null;
68
+    private $join = null;
69 69
 	
70 70
 	/**
71 71
 	 * The SQL ORDER BY statment
72 72
 	 * @var string
73 73
 	*/
74
-    private $orderBy             = null;
74
+    private $orderBy = null;
75 75
 	
76 76
 	/**
77 77
 	 * The SQL GROUP BY statment
78 78
 	 * @var string
79 79
 	*/
80
-    private $groupBy             = null;
80
+    private $groupBy = null;
81 81
 	
82 82
 	/**
83 83
 	 * The SQL HAVING statment
84 84
 	 * @var string
85 85
 	*/
86
-    private $having              = null;
86
+    private $having = null;
87 87
 	
88 88
 	/**
89 89
 	 * The number of rows returned by the last query
90 90
 	 * @var int
91 91
 	*/
92
-    private $numRows             = 0;
92
+    private $numRows = 0;
93 93
 	
94 94
 	/**
95 95
 	 * The last insert id for the primary key column that have auto increment or sequence
96 96
 	 * @var mixed
97 97
 	*/
98
-    private $insertId            = null;
98
+    private $insertId = null;
99 99
 	
100 100
 	/**
101 101
 	 * The full SQL query statment after build for each command
102 102
 	 * @var string
103 103
 	*/
104
-    private $query               = null;
104
+    private $query = null;
105 105
 	
106 106
 	/**
107 107
 	 * The error returned for the last query
108 108
 	 * @var string
109 109
 	*/
110
-    private $error               = null;
110
+    private $error = null;
111 111
 	
112 112
 	/**
113 113
 	 * The result returned for the last query
114 114
 	 * @var mixed
115 115
 	*/
116
-    private $result              = array();
116
+    private $result = array();
117 117
 	
118 118
 	/**
119 119
 	 * The prefix used in each database table
120 120
 	 * @var string
121 121
 	*/
122
-    private $prefix              = null;
122
+    private $prefix = null;
123 123
 	
124 124
 	/**
125 125
 	 * The list of SQL valid operators
126 126
 	 * @var array
127 127
 	*/
128
-    private $operatorList        = array('=','!=','<','>','<=','>=','<>');
128
+    private $operatorList = array('=', '!=', '<', '>', '<=', '>=', '<>');
129 129
     
130 130
 	/**
131 131
 	 * The cache default time to live in second. 0 means no need to use the cache feature
132 132
 	 * @var int
133 133
 	*/
134
-	private $cacheTtl              = 0;
134
+	private $cacheTtl = 0;
135 135
 	
136 136
 	/**
137 137
 	 * The cache current time to live. 0 means no need to use the cache feature
138 138
 	 * @var int
139 139
 	*/
140
-    private $temporaryCacheTtl   = 0;
140
+    private $temporaryCacheTtl = 0;
141 141
 	
142 142
 	/**
143 143
 	 * The number of executed query for the current request
144 144
 	 * @var int
145 145
 	*/
146
-    private $queryCount          = 0;
146
+    private $queryCount = 0;
147 147
 	
148 148
 	/**
149 149
 	 * The default data to be used in the statments query INSERT, UPDATE
150 150
 	 * @var array
151 151
 	*/
152
-    private $data                = array();
152
+    private $data = array();
153 153
 	
154 154
 	/**
155 155
 	 * The database configuration
156 156
 	 * @var array
157 157
 	*/
158
-    private $config              = array();
158
+    private $config = array();
159 159
 	
160 160
 	/**
161 161
 	 * The logger instance
162 162
 	 * @var Log
163 163
 	 */
164
-    private $logger              = null;
164
+    private $logger = null;
165 165
 
166 166
 
167 167
     /**
168 168
     * The cache instance
169 169
     * @var CacheInterface
170 170
     */
171
-    private $cacheInstance       = null;
171
+    private $cacheInstance = null;
172 172
 
173 173
      /**
174 174
     * The benchmark instance
175 175
     * @var Benchmark
176 176
     */
177
-    private $benchmarkInstance   = null;
177
+    private $benchmarkInstance = null;
178 178
 
179 179
 
180 180
     /**
@@ -182,25 +182,25 @@  discard block
 block discarded – undo
182 182
      * @param array $overwriteConfig the config to overwrite with the config set in database.php
183 183
      * @param object $logger the log instance
184 184
      */
185
-    public function __construct($overwriteConfig = array(), Log $logger = null){
185
+    public function __construct($overwriteConfig = array(), Log $logger = null) {
186 186
         /**
187 187
          * instance of the Log class
188 188
          */
189
-        if(is_object($logger)){
189
+        if (is_object($logger)) {
190 190
           $this->logger = $logger;
191 191
         }
192
-        else{
193
-            $this->logger =& class_loader('Log', 'classes');
192
+        else {
193
+            $this->logger = & class_loader('Log', 'classes');
194 194
             $this->logger->setLogger('Library::Database');
195 195
         }
196 196
 
197 197
         $db = array();
198
-      	if(file_exists(CONFIG_PATH . 'database.php')){
198
+      	if (file_exists(CONFIG_PATH . 'database.php')) {
199 199
           //here don't use require_once because somewhere user can create database instance directly
200 200
       	  require CONFIG_PATH . 'database.php';
201 201
         }
202 202
           
203
-				if(! empty($overwriteConfig)){
203
+				if (!empty($overwriteConfig)) {
204 204
 				  $db = array_merge($db, $overwriteConfig);
205 205
 				}
206 206
         $config = array();
@@ -213,12 +213,12 @@  discard block
 block discarded – undo
213 213
 				$config['collation'] = isset($db['collation']) ? $db['collation'] : 'utf8_general_ci';
214 214
 				$config['prefix']    = isset($db['prefix']) ? $db['prefix'] : '';
215 215
         $port = '';
216
-        if(strstr($config['hostname'], ':')){
216
+        if (strstr($config['hostname'], ':')) {
217 217
           $p = explode(':', $config['hostname']);
218 218
           $port = isset($p[1]) ? $p[1] : '';
219 219
           $config['hostname'] = isset($p[0]) ? $p[0] : '';
220 220
         }
221
-				$config['port']      = $port;
221
+				$config['port'] = $port;
222 222
 				
223 223
 		  	$this->setDatabaseConfiguration($config);
224 224
     		$this->temporaryCacheTtl = $this->cacheTtl;
@@ -228,10 +228,10 @@  discard block
 block discarded – undo
228 228
      * This is used to connect to database
229 229
      * @return bool 
230 230
      */
231
-    public function connect(){
231
+    public function connect() {
232 232
       $config = $this->getDatabaseConfiguration();
233
-      if(! empty($config)){
234
-        try{
233
+      if (!empty($config)) {
234
+        try {
235 235
             $driverDsnMap = array(
236 236
               'mysql' => 'mysql:host=' . $config['hostname'] . ';' 
237 237
                           . (($config['port']) != '' ? 'port=' . $config['port'] . ';' : '') 
@@ -252,13 +252,13 @@  discard block
 block discarded – undo
252 252
             $this->pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
253 253
             return true;
254 254
           }
255
-          catch (PDOException $e){
255
+          catch (PDOException $e) {
256 256
             $this->logger->fatal($e->getMessage());
257 257
             show_error('Cannot connect to Database.');
258 258
             return false;
259 259
           }
260 260
       }
261
-      else{
261
+      else {
262 262
         show_error('Database configuration is not set.');
263 263
         return false;
264 264
       }
@@ -269,15 +269,15 @@  discard block
 block discarded – undo
269 269
      * @param  string|array $table the table name or array of table list
270 270
      * @return object        the current Database instance
271 271
      */
272
-    public function from($table){
273
-      if(is_array($table)){
272
+    public function from($table) {
273
+      if (is_array($table)) {
274 274
         $froms = '';
275
-        foreach($table as $key){
275
+        foreach ($table as $key) {
276 276
           $froms .= $this->prefix . $key . ', ';
277 277
         }
278 278
         $this->from = rtrim($froms, ', ');
279 279
       }
280
-      else{
280
+      else {
281 281
         $this->from = $this->prefix . $table;
282 282
       }
283 283
       return $this;
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
      * @param  string|array $fields the field name or array of field list
289 289
      * @return object        the current Database instance
290 290
      */
291
-    public function select($fields){
291
+    public function select($fields) {
292 292
       $select = (is_array($fields) ? implode(', ', $fields) : $fields);
293 293
       $this->select = ($this->select == '*' ? $select : $this->select . ', ' . $select);
294 294
       return $this;
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
      * @param  string $field the field name to distinct
300 300
      * @return object        the current Database instance
301 301
      */
302
-    public function distinct($field){
302
+    public function distinct($field) {
303 303
       $distinct = ' DISTINCT ' . $field;
304 304
       $this->select = ($this->select == '*' ? $distinct : $this->select . ', ' . $distinct);
305 305
 
@@ -312,7 +312,7 @@  discard block
 block discarded – undo
312 312
      * @param  string $name  if is not null represent the alias used for this field in the result
313 313
      * @return object        the current Database instance
314 314
      */
315
-    public function max($field, $name = null){
315
+    public function max($field, $name = null) {
316 316
       $func = 'MAX(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : '');
317 317
       $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func);
318 318
       return $this;
@@ -324,7 +324,7 @@  discard block
 block discarded – undo
324 324
      * @param  string $name  if is not null represent the alias used for this field in the result
325 325
      * @return object        the current Database instance
326 326
      */
327
-    public function min($field, $name = null){
327
+    public function min($field, $name = null) {
328 328
       $func = 'MIN(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : '');
329 329
       $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func);
330 330
       return $this;
@@ -336,7 +336,7 @@  discard block
 block discarded – undo
336 336
      * @param  string $name  if is not null represent the alias used for this field in the result
337 337
      * @return object        the current Database instance
338 338
      */
339
-    public function sum($field, $name = null){
339
+    public function sum($field, $name = null) {
340 340
       $func = 'SUM(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : '');
341 341
       $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func);
342 342
       return $this;
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
      * @param  string $name  if is not null represent the alias used for this field in the result
349 349
      * @return object        the current Database instance
350 350
      */
351
-    public function count($field = '*', $name = null){
351
+    public function count($field = '*', $name = null) {
352 352
       $func = 'COUNT(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : '');
353 353
       $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func);
354 354
       return $this;
@@ -360,7 +360,7 @@  discard block
 block discarded – undo
360 360
      * @param  string $name  if is not null represent the alias used for this field in the result
361 361
      * @return object        the current Database instance
362 362
      */
363
-    public function avg($field, $name = null){
363
+    public function avg($field, $name = null) {
364 364
       $func = 'AVG(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : '');
365 365
       $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func);
366 366
       return $this;
@@ -375,16 +375,16 @@  discard block
 block discarded – undo
375 375
      * @param  string $type   the type of join (INNER, LEFT, RIGHT)
376 376
      * @return object        the current Database instance
377 377
      */
378
-    public function join($table, $field1 = null, $op = null, $field2 = null, $type = ''){
378
+    public function join($table, $field1 = null, $op = null, $field2 = null, $type = '') {
379 379
       $on = $field1;
380 380
       $table = $this->prefix . $table;
381
-      if(! is_null($op)){
382
-        $on = (! in_array($op, $this->operatorList) ? $this->prefix . $field1 . ' = ' . $this->prefix . $op : $this->prefix . $field1 . ' ' . $op . ' ' . $this->prefix . $field2);
381
+      if (!is_null($op)) {
382
+        $on = (!in_array($op, $this->operatorList) ? $this->prefix . $field1 . ' = ' . $this->prefix . $op : $this->prefix . $field1 . ' ' . $op . ' ' . $this->prefix . $field2);
383 383
       }
384
-      if (is_null($this->join)){
384
+      if (is_null($this->join)) {
385 385
         $this->join = ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on;
386 386
       }
387
-      else{
387
+      else {
388 388
         $this->join = $this->join . ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on;
389 389
       }
390 390
       return $this;
@@ -395,7 +395,7 @@  discard block
 block discarded – undo
395 395
      * @see  Database::join()
396 396
      * @return object        the current Database instance
397 397
      */
398
-    public function innerJoin($table, $field1, $op = null, $field2 = ''){
398
+    public function innerJoin($table, $field1, $op = null, $field2 = '') {
399 399
       return $this->join($table, $field1, $op, $field2, 'INNER ');
400 400
     }
401 401
 
@@ -404,7 +404,7 @@  discard block
 block discarded – undo
404 404
      * @see  Database::join()
405 405
      * @return object        the current Database instance
406 406
      */
407
-    public function leftJoin($table, $field1, $op = null, $field2 = ''){
407
+    public function leftJoin($table, $field1, $op = null, $field2 = '') {
408 408
       return $this->join($table, $field1, $op, $field2, 'LEFT ');
409 409
 	}
410 410
 
@@ -413,7 +413,7 @@  discard block
 block discarded – undo
413 413
      * @see  Database::join()
414 414
      * @return object        the current Database instance
415 415
      */
416
-    public function rightJoin($table, $field1, $op = null, $field2 = ''){
416
+    public function rightJoin($table, $field1, $op = null, $field2 = '') {
417 417
       return $this->join($table, $field1, $op, $field2, 'RIGHT ');
418 418
     }
419 419
 
@@ -422,7 +422,7 @@  discard block
 block discarded – undo
422 422
      * @see  Database::join()
423 423
      * @return object        the current Database instance
424 424
      */
425
-    public function fullOuterJoin($table, $field1, $op = null, $field2 = ''){
425
+    public function fullOuterJoin($table, $field1, $op = null, $field2 = '') {
426 426
     	return $this->join($table, $field1, $op, $field2, 'FULL OUTER ');
427 427
     }
428 428
 
@@ -431,7 +431,7 @@  discard block
 block discarded – undo
431 431
      * @see  Database::join()
432 432
      * @return object        the current Database instance
433 433
      */
434
-    public function leftOuterJoin($table, $field1, $op = null, $field2 = ''){
434
+    public function leftOuterJoin($table, $field1, $op = null, $field2 = '') {
435 435
       return $this->join($table, $field1, $op, $field2, 'LEFT OUTER ');
436 436
     }
437 437
 
@@ -440,7 +440,7 @@  discard block
 block discarded – undo
440 440
      * @see  Database::join()
441 441
      * @return object        the current Database instance
442 442
      */
443
-    public function rightOuterJoin($table, $field1, $op = null, $field2 = ''){
443
+    public function rightOuterJoin($table, $field1, $op = null, $field2 = '') {
444 444
       return $this->join($table, $field1, $op, $field2, 'RIGHT OUTER ');
445 445
     }
446 446
 
@@ -450,18 +450,18 @@  discard block
 block discarded – undo
450 450
      * @param  string $andOr the separator type used 'AND', 'OR', etc.
451 451
      * @return object        the current Database instance
452 452
      */
453
-    public function whereIsNull($field, $andOr = 'AND'){
454
-      if(is_array($field)){
455
-        foreach($field as $f){
453
+    public function whereIsNull($field, $andOr = 'AND') {
454
+      if (is_array($field)) {
455
+        foreach ($field as $f) {
456 456
         	$this->whereIsNull($f, $andOr);
457 457
         }
458 458
       }
459
-      else{
460
-        if (! $this->where){
461
-          $this->where = $field.' IS NULL ';
459
+      else {
460
+        if (!$this->where) {
461
+          $this->where = $field . ' IS NULL ';
462 462
         }
463
-        else{
464
-            $this->where = $this->where . ' '.$andOr.' ' . $field.' IS NULL ';
463
+        else {
464
+            $this->where = $this->where . ' ' . $andOr . ' ' . $field . ' IS NULL ';
465 465
           }
466 466
       }
467 467
       return $this;
@@ -473,18 +473,18 @@  discard block
 block discarded – undo
473 473
      * @param  string $andOr the separator type used 'AND', 'OR', etc.
474 474
      * @return object        the current Database instance
475 475
      */
476
-    public function whereIsNotNull($field, $andOr = 'AND'){
477
-      if(is_array($field)){
478
-        foreach($field as $f){
476
+    public function whereIsNotNull($field, $andOr = 'AND') {
477
+      if (is_array($field)) {
478
+        foreach ($field as $f) {
479 479
           $this->whereIsNotNull($f, $andOr);
480 480
         }
481 481
       }
482
-      else{
483
-        if (! $this->where){
484
-          $this->where = $field.' IS NOT NULL ';
482
+      else {
483
+        if (!$this->where) {
484
+          $this->where = $field . ' IS NOT NULL ';
485 485
         }
486
-        else{
487
-            $this->where = $this->where . ' '.$andOr.' ' . $field.' IS NOT NULL ';
486
+        else {
487
+            $this->where = $this->where . ' ' . $andOr . ' ' . $field . ' IS NOT NULL ';
488 488
           }
489 489
       }
490 490
       return $this;
@@ -500,24 +500,24 @@  discard block
 block discarded – undo
500 500
      * @param  boolean $escape whether to escape or not the $val
501 501
      * @return object        the current Database instance
502 502
      */
503
-    public function where($where, $op = null, $val = null, $type = '', $andOr = 'AND', $escape = true){
504
-      if (is_array($where)){
503
+    public function where($where, $op = null, $val = null, $type = '', $andOr = 'AND', $escape = true) {
504
+      if (is_array($where)) {
505 505
         $_where = array();
506
-        foreach ($where as $column => $data){
507
-          if(is_null($data)){
506
+        foreach ($where as $column => $data) {
507
+          if (is_null($data)) {
508 508
             $data = '';
509 509
           }
510 510
           $_where[] = $type . $column . '=' . ($escape ? $this->escape($data) : $data);
511 511
         }
512
-        $where = implode(' '.$andOr.' ', $_where);
512
+        $where = implode(' ' . $andOr . ' ', $_where);
513 513
       }
514
-      else{
515
-        if(is_array($op)){
514
+      else {
515
+        if (is_array($op)) {
516 516
           $x = explode('?', $where);
517 517
           $w = '';
518
-          foreach($x as $k => $v){
519
-            if(! empty($v)){
520
-                if(isset($op[$k]) && is_null($op[$k])){
518
+          foreach ($x as $k => $v) {
519
+            if (!empty($v)) {
520
+                if (isset($op[$k]) && is_null($op[$k])) {
521 521
                   $op[$k] = '';
522 522
                 }
523 523
                 $w .= $type . $v . (isset($op[$k]) ? ($escape ? $this->escape($op[$k]) : $op[$k]) : '');
@@ -525,28 +525,28 @@  discard block
 block discarded – undo
525 525
           }
526 526
           $where = $w;
527 527
         }
528
-        else if (! in_array((string)$op, $this->operatorList)){
529
-          if(is_null($op)){
528
+        else if (!in_array((string) $op, $this->operatorList)) {
529
+          if (is_null($op)) {
530 530
             $op = '';
531 531
           }
532 532
         	$where = $type . $where . ' = ' . ($escape ? $this->escape($op) : $op);
533 533
         }
534
-        else{
535
-          if(is_null($val)){
534
+        else {
535
+          if (is_null($val)) {
536 536
             $val = '';
537 537
           }
538 538
         	$where = $type . $where . $op . ($escape ? $this->escape($val) : $val);
539 539
         }
540 540
       }
541
-      if (is_null($this->where)){
541
+      if (is_null($this->where)) {
542 542
         $this->where = $where;
543 543
       }
544
-      else{
545
-        if(substr($this->where, -1) == '('){
544
+      else {
545
+        if (substr($this->where, -1) == '(') {
546 546
           $this->where = $this->where . ' ' . $where;
547 547
         }
548
-        else{
549
-          $this->where = $this->where . ' '.$andOr.' ' . $where;
548
+        else {
549
+          $this->where = $this->where . ' ' . $andOr . ' ' . $where;
550 550
         }
551 551
       }
552 552
       return $this;
@@ -557,7 +557,7 @@  discard block
 block discarded – undo
557 557
      * @see  Database::where()
558 558
      * @return object        the current Database instance
559 559
      */
560
-    public function orWhere($where, $op = null, $val = null, $escape = true){
560
+    public function orWhere($where, $op = null, $val = null, $escape = true) {
561 561
       return $this->where($where, $op, $val, '', 'OR', $escape);
562 562
     }
563 563
 
@@ -567,7 +567,7 @@  discard block
 block discarded – undo
567 567
      * @see  Database::where()
568 568
      * @return object        the current Database instance
569 569
      */
570
-    public function notWhere($where, $op = null, $val = null, $escape = true){
570
+    public function notWhere($where, $op = null, $val = null, $escape = true) {
571 571
       return $this->where($where, $op, $val, 'NOT ', 'AND', $escape);
572 572
     }
573 573
 
@@ -576,7 +576,7 @@  discard block
 block discarded – undo
576 576
      * @see  Database::where()
577 577
      * @return object        the current Database instance
578 578
      */
579
-    public function orNotWhere($where, $op = null, $val = null, $escape = true){
579
+    public function orNotWhere($where, $op = null, $val = null, $escape = true) {
580 580
     	return $this->where($where, $op, $val, 'NOT ', 'OR', $escape);
581 581
     }
582 582
 
@@ -586,15 +586,15 @@  discard block
 block discarded – undo
586 586
      * @param  string $andOr the multiple conditions separator (AND, OR, etc.)
587 587
      * @return object        the current Database instance
588 588
      */
589
-    public function groupStart($type = '', $andOr = ' AND'){
590
-      if (is_null($this->where)){
589
+    public function groupStart($type = '', $andOr = ' AND') {
590
+      if (is_null($this->where)) {
591 591
         $this->where = $type . ' (';
592 592
       }
593
-      else{
594
-          if(substr($this->where, -1) == '('){
593
+      else {
594
+          if (substr($this->where, -1) == '(') {
595 595
             $this->where .= $type . ' (';
596 596
           }
597
-          else{
597
+          else {
598 598
           	$this->where .= $andOr . ' ' . $type . ' (';
599 599
           }
600 600
       }
@@ -606,7 +606,7 @@  discard block
 block discarded – undo
606 606
      * @see  Database::groupStart()
607 607
      * @return object        the current Database instance
608 608
      */
609
-    public function notGroupStart(){
609
+    public function notGroupStart() {
610 610
       return $this->groupStart('NOT');
611 611
     }
612 612
 
@@ -615,7 +615,7 @@  discard block
 block discarded – undo
615 615
      * @see  Database::groupStart()
616 616
      * @return object        the current Database instance
617 617
      */
618
-    public function orGroupStart(){
618
+    public function orGroupStart() {
619 619
       return $this->groupStart('', ' OR');
620 620
     }
621 621
 
@@ -624,7 +624,7 @@  discard block
 block discarded – undo
624 624
      * @see  Database::groupStart()
625 625
      * @return object        the current Database instance
626 626
      */
627
-    public function orNotGroupStart(){
627
+    public function orNotGroupStart() {
628 628
       return $this->groupStart('NOT', ' OR');
629 629
     }
630 630
 
@@ -632,7 +632,7 @@  discard block
 block discarded – undo
632 632
      * Close the parenthesis for the grouped SQL
633 633
      * @return object        the current Database instance
634 634
      */
635
-    public function groupEnd(){
635
+    public function groupEnd() {
636 636
       $this->where .= ')';
637 637
       return $this;
638 638
     }
@@ -646,25 +646,25 @@  discard block
 block discarded – undo
646 646
      * @param  boolean $escape whether to escape or not the values
647 647
      * @return object        the current Database instance
648 648
      */
649
-    public function in($field, array $keys, $type = '', $andOr = 'AND', $escape = true){
650
-      if (is_array($keys)){
649
+    public function in($field, array $keys, $type = '', $andOr = 'AND', $escape = true) {
650
+      if (is_array($keys)) {
651 651
         $_keys = array();
652
-        foreach ($keys as $k => $v){
653
-          if(is_null($v)){
652
+        foreach ($keys as $k => $v) {
653
+          if (is_null($v)) {
654 654
             $v = '';
655 655
           }
656 656
           $_keys[] = (is_numeric($v) ? $v : ($escape ? $this->escape($v) : $v));
657 657
         }
658 658
         $keys = implode(', ', $_keys);
659
-        if (is_null($this->where)){
659
+        if (is_null($this->where)) {
660 660
           $this->where = $field . ' ' . $type . 'IN (' . $keys . ')';
661 661
         }
662
-        else{
663
-          if(substr($this->where, -1) == '('){
664
-            $this->where = $this->where . ' ' . $field . ' '.$type.'IN (' . $keys . ')';
662
+        else {
663
+          if (substr($this->where, -1) == '(') {
664
+            $this->where = $this->where . ' ' . $field . ' ' . $type . 'IN (' . $keys . ')';
665 665
           }
666
-          else{
667
-            $this->where = $this->where . ' ' . $andOr . ' ' . $field . ' '.$type.'IN (' . $keys . ')';
666
+          else {
667
+            $this->where = $this->where . ' ' . $andOr . ' ' . $field . ' ' . $type . 'IN (' . $keys . ')';
668 668
           }
669 669
         }
670 670
       }
@@ -676,7 +676,7 @@  discard block
 block discarded – undo
676 676
      * @see  Database::in()
677 677
      * @return object        the current Database instance
678 678
      */
679
-    public function notIn($field, array $keys, $escape = true){
679
+    public function notIn($field, array $keys, $escape = true) {
680 680
       return $this->in($field, $keys, 'NOT ', 'AND', $escape);
681 681
     }
682 682
 
@@ -685,7 +685,7 @@  discard block
 block discarded – undo
685 685
      * @see  Database::in()
686 686
      * @return object        the current Database instance
687 687
      */
688
-    public function orIn($field, array $keys, $escape = true){
688
+    public function orIn($field, array $keys, $escape = true) {
689 689
       return $this->in($field, $keys, '', 'OR', $escape);
690 690
     }
691 691
 
@@ -694,7 +694,7 @@  discard block
 block discarded – undo
694 694
      * @see  Database::in()
695 695
      * @return object        the current Database instance
696 696
      */
697
-    public function orNotIn($field, array $keys, $escape = true){
697
+    public function orNotIn($field, array $keys, $escape = true) {
698 698
       return $this->in($field, $keys, 'NOT ', 'OR', $escape);
699 699
     }
700 700
 
@@ -708,21 +708,21 @@  discard block
 block discarded – undo
708 708
      * @param  boolean $escape whether to escape or not the values
709 709
      * @return object        the current Database instance
710 710
      */
711
-    public function between($field, $value1, $value2, $type = '', $andOr = 'AND', $escape = true){
712
-      if(is_null($value1)){
711
+    public function between($field, $value1, $value2, $type = '', $andOr = 'AND', $escape = true) {
712
+      if (is_null($value1)) {
713 713
         $value1 = '';
714 714
       }
715
-      if(is_null($value2)){
715
+      if (is_null($value2)) {
716 716
         $value2 = '';
717 717
       }
718
-      if (is_null($this->where)){
718
+      if (is_null($this->where)) {
719 719
       	$this->where = $field . ' ' . $type . 'BETWEEN ' . ($escape ? $this->escape($value1) : $value1) . ' AND ' . ($escape ? $this->escape($value2) : $value2);
720 720
       }
721
-      else{
722
-        if(substr($this->where, -1) == '('){
721
+      else {
722
+        if (substr($this->where, -1) == '(') {
723 723
           $this->where = $this->where . ' ' . $field . ' ' . $type . 'BETWEEN ' . ($escape ? $this->escape($value1) : $value1) . ' AND ' . ($escape ? $this->escape($value2) : $value2);
724 724
         }
725
-        else{
725
+        else {
726 726
           $this->where = $this->where . ' ' . $andOr . ' ' . $field . ' ' . $type . 'BETWEEN ' . ($escape ? $this->escape($value1) : $value1) . ' AND ' . ($escape ? $this->escape($value2) : $value2);
727 727
         }
728 728
       }
@@ -734,7 +734,7 @@  discard block
 block discarded – undo
734 734
      * @see  Database::between()
735 735
      * @return object        the current Database instance
736 736
      */
737
-    public function notBetween($field, $value1, $value2, $escape = true){
737
+    public function notBetween($field, $value1, $value2, $escape = true) {
738 738
       return $this->between($field, $value1, $value2, 'NOT ', 'AND', $escape);
739 739
     }
740 740
 
@@ -743,7 +743,7 @@  discard block
 block discarded – undo
743 743
      * @see  Database::between()
744 744
      * @return object        the current Database instance
745 745
      */
746
-    public function orBetween($field, $value1, $value2, $escape = true){
746
+    public function orBetween($field, $value1, $value2, $escape = true) {
747 747
       return $this->between($field, $value1, $value2, '', 'OR', $escape);
748 748
     }
749 749
 
@@ -752,7 +752,7 @@  discard block
 block discarded – undo
752 752
      * @see  Database::between()
753 753
      * @return object        the current Database instance
754 754
      */
755
-    public function orNotBetween($field, $value1, $value2, $escape = true){
755
+    public function orNotBetween($field, $value1, $value2, $escape = true) {
756 756
       return $this->between($field, $value1, $value2, 'NOT ', 'OR', $escape);
757 757
     }
758 758
 
@@ -765,20 +765,20 @@  discard block
 block discarded – undo
765 765
      * @param  boolean $escape whether to escape or not the values
766 766
      * @return object        the current Database instance
767 767
      */
768
-    public function like($field, $data, $type = '', $andOr = 'AND', $escape = true){
769
-      if(is_null($data)){
768
+    public function like($field, $data, $type = '', $andOr = 'AND', $escape = true) {
769
+      if (is_null($data)) {
770 770
         $data = '';
771 771
       }
772 772
       $like = $escape ? $this->escape($data) : $data;
773
-      if (is_null($this->where)){
773
+      if (is_null($this->where)) {
774 774
         $this->where = $field . ' ' . $type . 'LIKE ' . $like;
775 775
       }
776
-      else{
777
-        if(substr($this->where, -1) == '('){
776
+      else {
777
+        if (substr($this->where, -1) == '(') {
778 778
           $this->where = $this->where . ' ' . $field . ' ' . $type . 'LIKE ' . $like;
779 779
         }
780
-        else{
781
-          $this->where = $this->where . ' '.$andOr.' ' . $field . ' ' . $type . 'LIKE ' . $like;
780
+        else {
781
+          $this->where = $this->where . ' ' . $andOr . ' ' . $field . ' ' . $type . 'LIKE ' . $like;
782 782
         }
783 783
       }
784 784
       return $this;
@@ -789,7 +789,7 @@  discard block
 block discarded – undo
789 789
      * @see  Database::like()
790 790
      * @return object        the current Database instance
791 791
      */
792
-    public function orLike($field, $data, $escape = true){
792
+    public function orLike($field, $data, $escape = true) {
793 793
       return $this->like($field, $data, '', 'OR', $escape);
794 794
     }
795 795
 
@@ -798,7 +798,7 @@  discard block
 block discarded – undo
798 798
      * @see  Database::like()
799 799
      * @return object        the current Database instance
800 800
      */
801
-    public function notLike($field, $data, $escape = true){
801
+    public function notLike($field, $data, $escape = true) {
802 802
       return $this->like($field, $data, 'NOT ', 'AND', $escape);
803 803
     }
804 804
 
@@ -807,7 +807,7 @@  discard block
 block discarded – undo
807 807
      * @see  Database::like()
808 808
      * @return object        the current Database instance
809 809
      */
810
-    public function orNotLike($field, $data, $escape = true){
810
+    public function orNotLike($field, $data, $escape = true) {
811 811
       return $this->like($field, $data, 'NOT ', 'OR', $escape);
812 812
     }
813 813
 
@@ -818,14 +818,14 @@  discard block
 block discarded – undo
818 818
      * @param  int $limitEnd the limit count
819 819
      * @return object        the current Database instance
820 820
      */
821
-    public function limit($limit, $limitEnd = null){
822
-      if(is_null($limit)){
821
+    public function limit($limit, $limitEnd = null) {
822
+      if (is_null($limit)) {
823 823
         return;
824 824
       }
825
-      if (! is_null($limitEnd)){
825
+      if (!is_null($limitEnd)) {
826 826
         $this->limit = $limit . ', ' . $limitEnd;
827 827
       }
828
-      else{
828
+      else {
829 829
         $this->limit = $limit;
830 830
       }
831 831
       return $this;
@@ -837,16 +837,16 @@  discard block
 block discarded – undo
837 837
      * @param  string $orderDir the order direction (ASC or DESC)
838 838
      * @return object        the current Database instance
839 839
      */
840
-    public function orderBy($orderBy, $orderDir = ' ASC'){
841
-      if (! is_null($orderDir)){
842
-        $this->orderBy = ! $this->orderBy ? ($orderBy . ' ' . strtoupper($orderDir)) : $this->orderBy . ', ' . $orderBy . ' ' . strtoupper($orderDir);
840
+    public function orderBy($orderBy, $orderDir = ' ASC') {
841
+      if (!is_null($orderDir)) {
842
+        $this->orderBy = !$this->orderBy ? ($orderBy . ' ' . strtoupper($orderDir)) : $this->orderBy . ', ' . $orderBy . ' ' . strtoupper($orderDir);
843 843
       }
844
-      else{
845
-        if(stristr($orderBy, ' ') || $orderBy == 'rand()'){
846
-          $this->orderBy = ! $this->orderBy ? $orderBy : $this->orderBy . ', ' . $orderBy;
844
+      else {
845
+        if (stristr($orderBy, ' ') || $orderBy == 'rand()') {
846
+          $this->orderBy = !$this->orderBy ? $orderBy : $this->orderBy . ', ' . $orderBy;
847 847
         }
848
-        else{
849
-          $this->orderBy = ! $this->orderBy ? ($orderBy . ' ASC') : $this->orderBy . ', ' . ($orderBy . ' ASC');
848
+        else {
849
+          $this->orderBy = !$this->orderBy ? ($orderBy . ' ASC') : $this->orderBy . ', ' . ($orderBy . ' ASC');
850 850
         }
851 851
       }
852 852
       return $this;
@@ -857,11 +857,11 @@  discard block
 block discarded – undo
857 857
      * @param  string|array $field the field name used or array of field list
858 858
      * @return object        the current Database instance
859 859
      */
860
-    public function groupBy($field){
861
-      if(is_array($field)){
860
+    public function groupBy($field) {
861
+      if (is_array($field)) {
862 862
         $this->groupBy = implode(', ', $field);
863 863
       }
864
-      else{
864
+      else {
865 865
         $this->groupBy = $field;
866 866
       }
867 867
       return $this;
@@ -875,13 +875,13 @@  discard block
 block discarded – undo
875 875
      * @param  boolean $escape whether to escape or not the values
876 876
      * @return object        the current Database instance
877 877
      */
878
-    public function having($field, $op = null, $val = null, $escape = true){
879
-      if(is_array($op)){
878
+    public function having($field, $op = null, $val = null, $escape = true) {
879
+      if (is_array($op)) {
880 880
         $x = explode('?', $field);
881 881
         $w = '';
882
-        foreach($x as $k => $v){
883
-  	      if(!empty($v)){
884
-            if(isset($op[$k]) && is_null($op[$k])){
882
+        foreach ($x as $k => $v) {
883
+  	      if (!empty($v)) {
884
+            if (isset($op[$k]) && is_null($op[$k])) {
885 885
               $op[$k] = '';
886 886
             }
887 887
   	      	$w .= $v . (isset($op[$k]) ? ($escape ? $this->escape($op[$k]) : $op[$k]) : '');
@@ -889,14 +889,14 @@  discard block
 block discarded – undo
889 889
       	}
890 890
         $this->having = $w;
891 891
       }
892
-      else if (! in_array($op, $this->operatorList)){
893
-        if(is_null($op)){
892
+      else if (!in_array($op, $this->operatorList)) {
893
+        if (is_null($op)) {
894 894
           $op = '';
895 895
         }
896 896
         $this->having = $field . ' > ' . ($escape ? $this->escape($op) : $op);
897 897
       }
898
-      else{
899
-        if(is_null($val)){
898
+      else {
899
+        if (is_null($val)) {
900 900
           $val = '';
901 901
         }
902 902
         $this->having = $field . ' ' . $op . ' ' . ($escape ? $this->escape($val) : $val);
@@ -908,7 +908,7 @@  discard block
 block discarded – undo
908 908
      * Return the number of rows returned by the current query
909 909
      * @return int
910 910
      */
911
-    public function numRows(){
911
+    public function numRows() {
912 912
       return $this->numRows;
913 913
     }
914 914
 
@@ -916,15 +916,15 @@  discard block
 block discarded – undo
916 916
      * Return the last insert id value
917 917
      * @return mixed
918 918
      */
919
-    public function insertId(){
919
+    public function insertId() {
920 920
       return $this->insertId;
921 921
     }
922 922
 
923 923
     /**
924 924
      * Show an error got from the current query (SQL command synthax error, database driver returned error, etc.)
925 925
      */
926
-    public function error(){
927
-  		if($this->error){
926
+    public function error() {
927
+  		if ($this->error) {
928 928
   			show_error('Query: "' . $this->query . '" Error: ' . $this->error, 'Database Error');
929 929
   		}
930 930
     }
@@ -935,14 +935,14 @@  discard block
 block discarded – undo
935 935
      * If is string will determine the result type "array" or "object"
936 936
      * @return mixed       the query SQL string or the record result
937 937
      */
938
-    public function get($returnSQLQueryOrResultType = false){
938
+    public function get($returnSQLQueryOrResultType = false) {
939 939
       $this->limit = 1;
940 940
       $query = $this->getAll(true);
941
-      if($returnSQLQueryOrResultType === true){
941
+      if ($returnSQLQueryOrResultType === true) {
942 942
         return $query;
943 943
       }
944
-      else{
945
-        return $this->query( $query, false, (($returnSQLQueryOrResultType == 'array') ? true : false) );
944
+      else {
945
+        return $this->query($query, false, (($returnSQLQueryOrResultType == 'array') ? true : false));
946 946
       }
947 947
     }
948 948
 
@@ -952,37 +952,37 @@  discard block
 block discarded – undo
952 952
      * If is string will determine the result type "array" or "object"
953 953
      * @return mixed       the query SQL string or the record result
954 954
      */
955
-    public function getAll($returnSQLQueryOrResultType = false){
955
+    public function getAll($returnSQLQueryOrResultType = false) {
956 956
       $query = 'SELECT ' . $this->select . ' FROM ' . $this->from;
957
-      if (! is_null($this->join)){
957
+      if (!is_null($this->join)) {
958 958
         $query .= $this->join;
959 959
       }
960 960
 	  
961
-      if (! is_null($this->where)){
961
+      if (!is_null($this->where)) {
962 962
         $query .= ' WHERE ' . $this->where;
963 963
       }
964 964
 
965
-      if (! is_null($this->groupBy)){
965
+      if (!is_null($this->groupBy)) {
966 966
         $query .= ' GROUP BY ' . $this->groupBy;
967 967
       }
968 968
 
969
-      if (! is_null($this->having)){
969
+      if (!is_null($this->having)) {
970 970
         $query .= ' HAVING ' . $this->having;
971 971
       }
972 972
 
973
-      if (! is_null($this->orderBy)){
973
+      if (!is_null($this->orderBy)) {
974 974
           $query .= ' ORDER BY ' . $this->orderBy;
975 975
       }
976 976
 
977
-      if(! is_null($this->limit)){
977
+      if (!is_null($this->limit)) {
978 978
       	$query .= ' LIMIT ' . $this->limit;
979 979
       }
980 980
 	  
981
-	  if($returnSQLQueryOrResultType === true){
981
+	  if ($returnSQLQueryOrResultType === true) {
982 982
     	return $query;
983 983
       }
984
-      else{
985
-    	return $this->query($query, true, (($returnSQLQueryOrResultType == 'array') ? true : false) );
984
+      else {
985
+    	return $this->query($query, true, (($returnSQLQueryOrResultType == 'array') ? true : false));
986 986
       }
987 987
     }
988 988
 
@@ -992,15 +992,15 @@  discard block
 block discarded – undo
992 992
      * @param  boolean $escape  whether to escape or not the values
993 993
      * @return mixed          the insert id of the new record or null
994 994
      */
995
-    public function insert($data = array(), $escape = true){
995
+    public function insert($data = array(), $escape = true) {
996 996
       $column = array();
997 997
       $val = array();
998
-      if(! $data && $this->getData()){
998
+      if (!$data && $this->getData()) {
999 999
         $columns = array_keys($this->getData());
1000 1000
         $column = implode(',', $columns);
1001 1001
         $val = implode(', ', $this->getData());
1002 1002
       }
1003
-      else{
1003
+      else {
1004 1004
         $columns = array_keys($data);
1005 1005
         $column = implode(',', $columns);
1006 1006
         $val = implode(', ', ($escape ? array_map(array($this, 'escape'), $data) : $data));
@@ -1009,14 +1009,14 @@  discard block
 block discarded – undo
1009 1009
       $query = 'INSERT INTO ' . $this->from . ' (' . $column . ') VALUES (' . $val . ')';
1010 1010
       $query = $this->query($query);
1011 1011
 
1012
-      if ($query){
1013
-        if(! $this->pdo){
1012
+      if ($query) {
1013
+        if (!$this->pdo) {
1014 1014
           $this->connect();
1015 1015
         }
1016 1016
         $this->insertId = $this->pdo->lastInsertId();
1017 1017
         return $this->insertId();
1018 1018
       }
1019
-      else{
1019
+      else {
1020 1020
 		  return false;
1021 1021
       }
1022 1022
     }
@@ -1027,29 +1027,29 @@  discard block
 block discarded – undo
1027 1027
      * @param  boolean $escape  whether to escape or not the values
1028 1028
      * @return mixed          the update status
1029 1029
      */
1030
-    public function update($data = array(), $escape = true){
1030
+    public function update($data = array(), $escape = true) {
1031 1031
       $query = 'UPDATE ' . $this->from . ' SET ';
1032 1032
       $values = array();
1033
-      if(! $data && $this->getData()){
1034
-        foreach ($this->getData() as $column => $val){
1033
+      if (!$data && $this->getData()) {
1034
+        foreach ($this->getData() as $column => $val) {
1035 1035
           $values[] = $column . ' = ' . $val;
1036 1036
         }
1037 1037
       }
1038
-      else{
1039
-        foreach ($data as $column => $val){
1038
+      else {
1039
+        foreach ($data as $column => $val) {
1040 1040
           $values[] = $column . '=' . ($escape ? $this->escape($val) : $val);
1041 1041
         }
1042 1042
       }
1043 1043
       $query .= (is_array($data) ? implode(', ', $values) : $data);
1044
-      if (! is_null($this->where)){
1044
+      if (!is_null($this->where)) {
1045 1045
         $query .= ' WHERE ' . $this->where;
1046 1046
       }
1047 1047
 
1048
-      if (! is_null($this->orderBy)){
1048
+      if (!is_null($this->orderBy)) {
1049 1049
         $query .= ' ORDER BY ' . $this->orderBy;
1050 1050
       }
1051 1051
 
1052
-      if (! is_null($this->limit)){
1052
+      if (!is_null($this->limit)) {
1053 1053
         $query .= ' LIMIT ' . $this->limit;
1054 1054
       }
1055 1055
       return $this->query($query);
@@ -1059,22 +1059,22 @@  discard block
 block discarded – undo
1059 1059
      * Delete the record in database
1060 1060
      * @return mixed the delete status
1061 1061
      */
1062
-    public function delete(){
1062
+    public function delete() {
1063 1063
     	$query = 'DELETE FROM ' . $this->from;
1064 1064
 
1065
-    	if (! is_null($this->where)){
1065
+    	if (!is_null($this->where)) {
1066 1066
     		$query .= ' WHERE ' . $this->where;
1067 1067
       	}
1068 1068
 
1069
-    	if (! is_null($this->orderBy)){
1069
+    	if (!is_null($this->orderBy)) {
1070 1070
     	  $query .= ' ORDER BY ' . $this->orderBy;
1071 1071
       	}
1072 1072
 
1073
-    	if (! is_null($this->limit)){
1073
+    	if (!is_null($this->limit)) {
1074 1074
     		$query .= ' LIMIT ' . $this->limit;
1075 1075
       	}
1076 1076
 
1077
-    	if($query == 'DELETE FROM ' . $this->from && $this->config['driver'] != 'sqlite'){  
1077
+    	if ($query == 'DELETE FROM ' . $this->from && $this->config['driver'] != 'sqlite') {  
1078 1078
     		$query = 'TRUNCATE TABLE ' . $this->from;
1079 1079
       }
1080 1080
     	return $this->query($query);
@@ -1087,13 +1087,13 @@  discard block
 block discarded – undo
1087 1087
      * @param  boolean $array return the result as array
1088 1088
      * @return mixed         the query result
1089 1089
      */
1090
-    public function query($query, $all = true, $array = false){
1090
+    public function query($query, $all = true, $array = false) {
1091 1091
       $this->reset();
1092
-      if(is_array($all)){
1092
+      if (is_array($all)) {
1093 1093
         $x = explode('?', $query);
1094 1094
         $q = '';
1095
-        foreach($x as $k => $v){
1096
-          if(! empty($v)){
1095
+        foreach ($x as $k => $v) {
1096
+          if (!empty($v)) {
1097 1097
             $q .= $v . (isset($all[$k]) ? $this->escape($all[$k]) : '');
1098 1098
           }
1099 1099
         }
@@ -1102,7 +1102,7 @@  discard block
 block discarded – undo
1102 1102
 
1103 1103
       $this->query = preg_replace('/\s\s+|\t\t+/', ' ', trim($query));
1104 1104
       $sqlSELECTQuery = stristr($this->query, 'SELECT');
1105
-      $this->logger->info('Execute SQL query ['.$this->query.'], return type: ' . ($array?'ARRAY':'OBJECT') .', return as list: ' . ($all ? 'YES':'NO'));
1105
+      $this->logger->info('Execute SQL query [' . $this->query . '], return type: ' . ($array ? 'ARRAY' : 'OBJECT') . ', return as list: ' . ($all ? 'YES' : 'NO'));
1106 1106
       //cache expire time
1107 1107
   	  $cacheExpire = $this->temporaryCacheTtl;
1108 1108
   	  
@@ -1124,34 +1124,34 @@  discard block
 block discarded – undo
1124 1124
   	  //if can use cache feature for this query
1125 1125
   	  $dbCacheStatus = $cacheEnable && $cacheExpire > 0;
1126 1126
 	  
1127
-      if ($dbCacheStatus && $sqlSELECTQuery){
1127
+      if ($dbCacheStatus && $sqlSELECTQuery) {
1128 1128
         $this->logger->info('The cache is enabled for this query, try to get result from cache'); 
1129 1129
         $cacheKey = md5($query . $all . $array);
1130
-        if(is_object($this->cacheInstance)){
1130
+        if (is_object($this->cacheInstance)) {
1131 1131
           $cacheInstance = $this->cacheInstance;
1132 1132
         }
1133
-        else{
1133
+        else {
1134 1134
           $obj = & get_instance();
1135 1135
           $cacheInstance = $obj->cache;  
1136 1136
         }
1137 1137
         $cacheContent = $cacheInstance->get($cacheKey);        
1138 1138
       }
1139
-      else{
1139
+      else {
1140 1140
 		  $this->logger->info('The cache is not enabled for this query or is not the SELECT query, get the result directly from real database');
1141 1141
       }
1142 1142
 
1143
-      if(! $this->pdo){
1143
+      if (!$this->pdo) {
1144 1144
         $this->connect();
1145 1145
       }
1146 1146
       
1147
-      if (! $cacheContent && $sqlSELECTQuery){
1147
+      if (!$cacheContent && $sqlSELECTQuery) {
1148 1148
 		    //for database query execution time
1149 1149
         $benchmarkMarkerKey = md5($query . $all . $array);
1150 1150
         $bench = null;
1151
-        if(is_object($this->benchmarkInstance)){
1151
+        if (is_object($this->benchmarkInstance)) {
1152 1152
           $bench = $this->benchmarkInstance;
1153 1153
         }
1154
-        else{
1154
+        else {
1155 1155
           $obj = & get_instance();
1156 1156
           $bench = $obj->benchmark;  
1157 1157
         }
@@ -1162,64 +1162,64 @@  discard block
 block discarded – undo
1162 1162
     		//get response time for this query
1163 1163
         $responseTime = $bench->elapsedTime('DATABASE_QUERY_START(' . $benchmarkMarkerKey . ')', 'DATABASE_QUERY_END(' . $benchmarkMarkerKey . ')');
1164 1164
 	     	//TODO use the configuration value for the high response time currently is 1 second
1165
-        if($responseTime >= 1 ){
1166
-            $this->logger->warning('High response time while processing database query [' .$query. ']. The response time is [' .$responseTime. '] sec.');
1165
+        if ($responseTime >= 1) {
1166
+            $this->logger->warning('High response time while processing database query [' . $query . ']. The response time is [' . $responseTime . '] sec.');
1167 1167
         }
1168
-        if ($sqlQuery){
1168
+        if ($sqlQuery) {
1169 1169
             //if need return all result like list of record
1170
-            if ($all){
1170
+            if ($all) {
1171 1171
     				    $this->result = ($array == false) ? $sqlQuery->fetchAll(PDO::FETCH_OBJ) : $sqlQuery->fetchAll(PDO::FETCH_ASSOC);
1172 1172
     		    }
1173
-            else{
1173
+            else {
1174 1174
 				        $this->result = ($array == false) ? $sqlQuery->fetch(PDO::FETCH_OBJ) : $sqlQuery->fetch(PDO::FETCH_ASSOC);
1175 1175
             }
1176 1176
             //Sqlite and pgsql always return 0 when using rowCount()
1177
-            if(in_array($this->config['driver'], array('sqlite', 'pgsql'))){
1177
+            if (in_array($this->config['driver'], array('sqlite', 'pgsql'))) {
1178 1178
               $this->numRows = count($this->result);  
1179 1179
             }
1180
-            else{
1180
+            else {
1181 1181
               $this->numRows = $sqlQuery->rowCount(); 
1182 1182
             }
1183 1183
 
1184
-          if ($dbCacheStatus && $sqlSELECTQuery){
1185
-              $this->logger->info('Save the result for query [' .$this->query. '] into cache for future use');
1184
+          if ($dbCacheStatus && $sqlSELECTQuery) {
1185
+              $this->logger->info('Save the result for query [' . $this->query . '] into cache for future use');
1186 1186
               $cacheInstance->set($cacheKey, $this->result, $cacheExpire);
1187 1187
           }
1188 1188
         }
1189
-        else{
1189
+        else {
1190 1190
           $error = $this->pdo->errorInfo();
1191 1191
           $this->error = isset($error[2]) ? $error[2] : '';
1192 1192
           $this->logger->fatal('The database query execution got error: ' . stringfy_vars($error));
1193 1193
           $this->error();
1194 1194
         }
1195 1195
       }
1196
-      else if ((! $cacheContent && !$sqlSELECTQuery) || ($cacheContent && !$sqlSELECTQuery)){
1196
+      else if ((!$cacheContent && !$sqlSELECTQuery) || ($cacheContent && !$sqlSELECTQuery)) {
1197 1197
     		$queryStr = $this->pdo->query($this->query);
1198
-    		if($queryStr){
1198
+    		if ($queryStr) {
1199 1199
           //Sqlite and pgsql always return 0 when using rowCount()
1200
-          if(in_array($this->config['driver'], array('sqlite', 'pgsql'))){
1200
+          if (in_array($this->config['driver'], array('sqlite', 'pgsql'))) {
1201 1201
             $this->result = 1; //to test the result for the query like UPDATE, INSERT, DELETE
1202 1202
             $this->numRows = 1;  
1203 1203
           }
1204
-          else{
1204
+          else {
1205 1205
               $this->result = $queryStr->rowCount() >= 0; //to test the result for the query like UPDATE, INSERT, DELETE
1206 1206
               $this->numRows = $queryStr->rowCount(); 
1207 1207
           }
1208 1208
     		}
1209
-        if (! $this->result){
1209
+        if (!$this->result) {
1210 1210
           $error = $this->pdo->errorInfo();
1211 1211
           $this->error = isset($error[2]) ? $error[2] : '';
1212 1212
           $this->logger->fatal('The database query execution got error: ' . stringfy_vars($error));
1213 1213
           $this->error();
1214 1214
         }
1215 1215
       }
1216
-      else{
1217
-        $this->logger->info('The result for query [' .$this->query. '] already cached use it');
1216
+      else {
1217
+        $this->logger->info('The result for query [' . $this->query . '] already cached use it');
1218 1218
         $this->result = $cacheContent;
1219 1219
 	     	$this->numRows = count($this->result);
1220 1220
       }
1221 1221
       $this->queryCount++;
1222
-      if(! $this->result){
1222
+      if (!$this->result) {
1223 1223
         $this->logger->info('No result where found for the query [' . $query . ']');
1224 1224
       }
1225 1225
       return $this->result;
@@ -1230,8 +1230,8 @@  discard block
 block discarded – undo
1230 1230
      * @param integer $ttl the cache time to live in second
1231 1231
      * @return object        the current Database instance
1232 1232
      */
1233
-    public function setCache($ttl = 0){
1234
-      if($ttl > 0){
1233
+    public function setCache($ttl = 0) {
1234
+      if ($ttl > 0) {
1235 1235
         $this->cacheTtl = $ttl;
1236 1236
 		    $this->temporaryCacheTtl = $ttl;
1237 1237
       }
@@ -1243,8 +1243,8 @@  discard block
 block discarded – undo
1243 1243
 	 * @param  integer $ttl the cache time to live in second
1244 1244
 	 * @return object        the current Database instance
1245 1245
 	 */
1246
-	public function cached($ttl = 0){
1247
-      if($ttl > 0){
1246
+	public function cached($ttl = 0) {
1247
+      if ($ttl > 0) {
1248 1248
         $this->temporaryCacheTtl = $ttl;
1249 1249
       }
1250 1250
 	  return $this;
@@ -1255,11 +1255,11 @@  discard block
 block discarded – undo
1255 1255
      * @param  mixed $data the data to be escaped
1256 1256
      * @return mixed       the data after escaped
1257 1257
      */
1258
-    public function escape($data){
1259
-      if(is_null($data)){
1258
+    public function escape($data) {
1259
+      if (is_null($data)) {
1260 1260
         return null;
1261 1261
       }
1262
-      if(! $this->pdo){
1262
+      if (!$this->pdo) {
1263 1263
         $this->connect();
1264 1264
       }
1265 1265
       return $this->pdo->quote(trim($data));
@@ -1269,7 +1269,7 @@  discard block
 block discarded – undo
1269 1269
      * Return the number query executed count for the current request
1270 1270
      * @return int
1271 1271
      */
1272
-    public function queryCount(){
1272
+    public function queryCount() {
1273 1273
       return $this->queryCount;
1274 1274
     }
1275 1275
 
@@ -1277,7 +1277,7 @@  discard block
 block discarded – undo
1277 1277
      * Return the current query SQL string
1278 1278
      * @return string
1279 1279
      */
1280
-    public function getQuery(){
1280
+    public function getQuery() {
1281 1281
       return $this->query;
1282 1282
     }
1283 1283
 
@@ -1285,7 +1285,7 @@  discard block
 block discarded – undo
1285 1285
      * Return the application database name
1286 1286
      * @return string
1287 1287
      */
1288
-    public function getDatabaseName(){
1288
+    public function getDatabaseName() {
1289 1289
       return $this->databaseName;
1290 1290
     }
1291 1291
 
@@ -1293,7 +1293,7 @@  discard block
 block discarded – undo
1293 1293
      * Return the database configuration
1294 1294
      * @return array
1295 1295
      */
1296
-    public  function getDatabaseConfiguration(){
1296
+    public  function getDatabaseConfiguration() {
1297 1297
       return $this->config;
1298 1298
     }
1299 1299
 
@@ -1301,7 +1301,7 @@  discard block
 block discarded – undo
1301 1301
      * set the database configuration
1302 1302
      * @param array $config the configuration
1303 1303
      */
1304
-    public function setDatabaseConfiguration(array $config){
1304
+    public function setDatabaseConfiguration(array $config) {
1305 1305
       $this->config = array_merge($this->config, $config);
1306 1306
       $this->prefix = $this->config['prefix'];
1307 1307
       $this->databaseName = $this->config['database'];
@@ -1313,7 +1313,7 @@  discard block
 block discarded – undo
1313 1313
      * Return the PDO instance
1314 1314
      * @return PDO
1315 1315
      */
1316
-    public function getPdo(){
1316
+    public function getPdo() {
1317 1317
       return $this->pdo;
1318 1318
     }
1319 1319
 
@@ -1321,7 +1321,7 @@  discard block
 block discarded – undo
1321 1321
      * Set the PDO instance
1322 1322
      * @param PDO $pdo the pdo object
1323 1323
      */
1324
-    public function setPdo(PDO $pdo){
1324
+    public function setPdo(PDO $pdo) {
1325 1325
       $this->pdo = $pdo;
1326 1326
       return $this;
1327 1327
     }
@@ -1331,7 +1331,7 @@  discard block
 block discarded – undo
1331 1331
      * Return the Log instance
1332 1332
      * @return Log
1333 1333
      */
1334
-    public function getLogger(){
1334
+    public function getLogger() {
1335 1335
       return $this->logger;
1336 1336
     }
1337 1337
 
@@ -1339,7 +1339,7 @@  discard block
 block discarded – undo
1339 1339
      * Set the log instance
1340 1340
      * @param Log $logger the log object
1341 1341
      */
1342
-    public function setLogger($logger){
1342
+    public function setLogger($logger) {
1343 1343
       $this->logger = $logger;
1344 1344
       return $this;
1345 1345
     }
@@ -1348,7 +1348,7 @@  discard block
 block discarded – undo
1348 1348
      * Return the cache instance
1349 1349
      * @return CacheInterface
1350 1350
      */
1351
-    public function getCacheInstance(){
1351
+    public function getCacheInstance() {
1352 1352
       return $this->cacheInstance;
1353 1353
     }
1354 1354
 
@@ -1356,7 +1356,7 @@  discard block
 block discarded – undo
1356 1356
      * Set the cache instance
1357 1357
      * @param CacheInterface $cache the cache object
1358 1358
      */
1359
-    public function setCacheInstance($cache){
1359
+    public function setCacheInstance($cache) {
1360 1360
       $this->cacheInstance = $cache;
1361 1361
       return $this;
1362 1362
     }
@@ -1365,7 +1365,7 @@  discard block
 block discarded – undo
1365 1365
      * Return the benchmark instance
1366 1366
      * @return Benchmark
1367 1367
      */
1368
-    public function getBenchmark(){
1368
+    public function getBenchmark() {
1369 1369
       return $this->benchmarkInstance;
1370 1370
     }
1371 1371
 
@@ -1373,7 +1373,7 @@  discard block
 block discarded – undo
1373 1373
      * Set the benchmark instance
1374 1374
      * @param Benchmark $cache the cache object
1375 1375
      */
1376
-    public function setBenchmark($benchmark){
1376
+    public function setBenchmark($benchmark) {
1377 1377
       $this->benchmarkInstance = $benchmark;
1378 1378
       return $this;
1379 1379
     }
@@ -1382,7 +1382,7 @@  discard block
 block discarded – undo
1382 1382
      * Return the data to be used for insert, update, etc.
1383 1383
      * @return array
1384 1384
      */
1385
-    public function getData(){
1385
+    public function getData() {
1386 1386
       return $this->data;
1387 1387
     }
1388 1388
 
@@ -1393,7 +1393,7 @@  discard block
 block discarded – undo
1393 1393
      * @param boolean $escape whether to escape or not the $value
1394 1394
      * @return object        the current Database instance
1395 1395
      */
1396
-    public function setData($key, $value, $escape = true){
1396
+    public function setData($key, $value, $escape = true) {
1397 1397
       $this->data[$key] = $escape ? $this->escape($value) : $value;
1398 1398
       return $this;
1399 1399
     }
@@ -1402,7 +1402,7 @@  discard block
 block discarded – undo
1402 1402
   /**
1403 1403
    * Reset the database class attributs to the initail values before each query.
1404 1404
    */
1405
-  private function reset(){
1405
+  private function reset() {
1406 1406
     $this->select   = '*';
1407 1407
     $this->from     = null;
1408 1408
     $this->where    = null;
@@ -1422,7 +1422,7 @@  discard block
 block discarded – undo
1422 1422
   /**
1423 1423
    * The class destructor
1424 1424
    */
1425
-  function __destruct(){
1425
+  function __destruct() {
1426 1426
     $this->pdo = null;
1427 1427
   }
1428 1428
 
Please login to merge, or discard this patch.
core/libraries/Upload.php 1 patch
Spacing   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
     *    @package FileUpload
38 38
     *    @version 1.5
39 39
     */
40
-    class Upload{
40
+    class Upload {
41 41
 
42 42
         /**
43 43
         *   Version
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
         *    @version    1.0
70 70
         *    @var        array
71 71
         */
72
-        private $file_array    = array();
72
+        private $file_array = array();
73 73
 
74 74
         /**
75 75
         *    If the file you are trying to upload already exists it will
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
         *    @version    1.0
120 120
         *    @var        float
121 121
         */
122
-        private $max_file_size= 0.0;
122
+        private $max_file_size = 0.0;
123 123
 
124 124
         /**
125 125
         *    List of allowed mime types
@@ -217,12 +217,12 @@  discard block
 block discarded – undo
217 217
         *    @return    object
218 218
         *    @method    object    __construct
219 219
         */
220
-        public function __construct(){
221
-            $this->logger =& class_loader('Log', 'classes');
220
+        public function __construct() {
221
+            $this->logger = & class_loader('Log', 'classes');
222 222
             $this->logger->setLogger('Library::Upload');
223 223
 
224 224
             Loader::lang('file_upload');
225
-            $obj =& get_instance();
225
+            $obj = & get_instance();
226 226
 
227 227
             $this->error_messages = array(
228 228
                 'upload_err_ini_size' => $obj->lang->get('fu_upload_err_ini_size'),
@@ -239,15 +239,15 @@  discard block
 block discarded – undo
239 239
             );
240 240
 
241 241
             $this->file = array(
242
-                'status'                =>    false,    // True: success upload
243
-                'mime'                  =>    '',       // Empty string
244
-                'filename'              =>    '',       // Empty string
245
-                'original'              =>    '',       // Empty string
246
-                'size'                  =>    0,        // 0 Bytes
247
-                'sizeFormated'          =>    '0B',     // 0 Bytes
248
-                'destination'           =>    './',     // Default: ./
249
-                'allowed_mime_types'    =>    array(),  // Allowed mime types
250
-                'error'                 =>    null,        // File error
242
+                'status'                =>    false, // True: success upload
243
+                'mime'                  =>    '', // Empty string
244
+                'filename'              =>    '', // Empty string
245
+                'original'              =>    '', // Empty string
246
+                'size'                  =>    0, // 0 Bytes
247
+                'sizeFormated'          =>    '0B', // 0 Bytes
248
+                'destination'           =>    './', // Default: ./
249
+                'allowed_mime_types'    =>    array(), // Allowed mime types
250
+                'error'                 =>    null, // File error
251 251
             );
252 252
 
253 253
             // Change dir to current dir
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
             } elseif (isset($HTTP_POST_FILES) && is_array($HTTP_POST_FILES)) {
260 260
                 $this->file_array = $HTTP_POST_FILES;
261 261
             }
262
-            $this->logger->info('The upload file information are : ' .stringfy_vars($this->file_array));
262
+            $this->logger->info('The upload file information are : ' . stringfy_vars($this->file_array));
263 263
         }
264 264
         /**
265 265
         *    Set input.
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
         */
276 276
         public function setInput($input)
277 277
         {
278
-            if (!empty($input) && (is_string($input) || is_numeric($input) )) {
278
+            if (!empty($input) && (is_string($input) || is_numeric($input))) {
279 279
                 $this->input = $input;
280 280
             }
281 281
             return $this;
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
         */
312 312
         public function setAutoFilename()
313 313
         {
314
-            $this->filename = sha1(mt_rand(1, 9999).uniqid());
314
+            $this->filename = sha1(mt_rand(1, 9999) . uniqid());
315 315
             $this->filename .= time();
316 316
             return $this;
317 317
         }
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
                 $php_size = $this->sizeInBytes(ini_get('upload_max_filesize'));
333 333
                 // Calculate difference
334 334
                 if ($php_size < $file_size) {
335
-                    $this->logger->warning('The upload max file size you set [' .$file_size. '] is greather than the PHP configuration for upload max file size [' .$php_size. ']');
335
+                    $this->logger->warning('The upload max file size you set [' . $file_size . '] is greather than the PHP configuration for upload max file size [' . $php_size . ']');
336 336
                 }
337 337
                 $this->max_file_size = $file_size;
338 338
             }
@@ -350,7 +350,7 @@  discard block
 block discarded – undo
350 350
         public function setAllowedMimeTypes(array $mimes)
351 351
         {
352 352
             if (count($mimes) > 0) {
353
-                array_map(array($this , 'setAllowMimeType'), $mimes);
353
+                array_map(array($this, 'setAllowMimeType'), $mimes);
354 354
             }
355 355
             return $this;
356 356
         }
@@ -415,7 +415,7 @@  discard block
 block discarded – undo
415 415
         {
416 416
             if (!empty($name) && is_string($name)) {
417 417
                 if (array_key_exists($name, $this->mime_helping)) {
418
-                    return $this->setAllowedMimeTypes($this->mime_helping[ $name ]);
418
+                    return $this->setAllowedMimeTypes($this->mime_helping[$name]);
419 419
                 }
420 420
             }
421 421
             return $this;
@@ -434,8 +434,8 @@  discard block
 block discarded – undo
434 434
         */
435 435
         public function setUploadFunction($function)
436 436
         {
437
-            if (!empty($function) && (is_array($function) || is_string($function) )) {
438
-                if (is_callable( $function)) {
437
+            if (!empty($function) && (is_array($function) || is_string($function))) {
438
+                if (is_callable($function)) {
439 439
                     $this->upload_function = $function;
440 440
                 }
441 441
             }
@@ -488,8 +488,8 @@  discard block
 block discarded – undo
488 488
                             chdir($destination_directory);
489 489
                         }
490 490
                     }
491
-                    else{
492
-                        $this->logger->warning('Can not create the upload directory [' .$destination_directory. ']');
491
+                    else {
492
+                        $this->logger->warning('Can not create the upload directory [' . $destination_directory . ']');
493 493
                     }
494 494
                 }
495 495
             }
@@ -539,7 +539,7 @@  discard block
 block discarded – undo
539 539
         public function isFilename($filename)
540 540
         {
541 541
             $filename = basename($filename);
542
-            return (!empty($filename) && (is_string( $filename) || is_numeric($filename)));
542
+            return (!empty($filename) && (is_string($filename) || is_numeric($filename)));
543 543
         }
544 544
         /**
545 545
         *    Validate mime type with allowed mime types,
@@ -581,11 +581,11 @@  discard block
 block discarded – undo
581 581
         */
582 582
         public function isDirpath($path)
583 583
         {
584
-            if (!empty( $path) && (is_string( $path) || is_numeric($path) )) {
584
+            if (!empty($path) && (is_string($path) || is_numeric($path))) {
585 585
                 if (DIRECTORY_SEPARATOR == '/') {
586
-                    return (preg_match( '/^[^*?"<>|:]*$/' , $path) == 1 );
586
+                    return (preg_match('/^[^*?"<>|:]*$/', $path) == 1);
587 587
                 } else {
588
-                    return (preg_match( "/^[^*?\"<>|:]*$/" , substr($path,2) ) == 1);
588
+                    return (preg_match("/^[^*?\"<>|:]*$/", substr($path, 2)) == 1);
589 589
                 }
590 590
             }
591 591
             return false;
@@ -613,10 +613,10 @@  discard block
 block discarded – undo
613 613
         */
614 614
         public function getInfo()
615 615
         {
616
-            return (object)$this->file;
616
+            return (object) $this->file;
617 617
         }
618 618
 
619
-        public function isUploaded(){
619
+        public function isUploaded() {
620 620
             return isset($this->file_array[$this->input])
621 621
             &&
622 622
             is_uploaded_file($this->file_array[$this->input]['tmp_name']);
@@ -629,9 +629,9 @@  discard block
 block discarded – undo
629 629
         *    @return    boolean
630 630
         *    @method    boolean    save
631 631
         */
632
-        public function save(){
632
+        public function save() {
633 633
             //check if file upload is  allowed in the configuration
634
-            if(! ini_get('file_uploads')){
634
+            if (!ini_get('file_uploads')) {
635 635
                 $this->setError($this->error_messages['file_uploads']);
636 636
                 return false;
637 637
             }
@@ -641,7 +641,7 @@  discard block
 block discarded – undo
641 641
                     if (empty($this->filename)) {
642 642
                         $this->filename = $this->file_array[$this->input]['name'];
643 643
                     }
644
-                    else{
644
+                    else {
645 645
                         // Replace %s for extension in filename
646 646
                         // Before: /[\w\d]*(.[\d\w]+)$/i
647 647
                         // After: /^[\s[:alnum:]\-\_\.]*\.([\d\w]+)$/iu
@@ -652,7 +652,7 @@  discard block
 block discarded – undo
652 652
                             '$1',
653 653
                             $this->file_array[$this->input]['name']
654 654
                         );
655
-                        $this->filename = $this->filename.'.'.$extension;
655
+                        $this->filename = $this->filename . '.' . $extension;
656 656
                     }
657 657
 
658 658
                     // set file info
@@ -665,10 +665,10 @@  discard block
 block discarded – undo
665 665
                     $this->file['filename']     = $this->filename;
666 666
                     $this->file['error']        = $this->file_array[$this->input]['error'];
667 667
 
668
-                    $this->logger->info('The upload file information to process is : ' .stringfy_vars($this->file));
668
+                    $this->logger->info('The upload file information to process is : ' . stringfy_vars($this->file));
669 669
 
670 670
                     //check for php upload error
671
-                    if(is_numeric($this->file['error']) && $this->file['error'] > 0){
671
+                    if (is_numeric($this->file['error']) && $this->file['error'] > 0) {
672 672
                         $this->setError($this->getPhpUploadErrorMessageByCode($this->file['error']));
673 673
                         return false;
674 674
                     }
@@ -697,8 +697,8 @@  discard block
 block discarded – undo
697 697
                     }
698 698
 
699 699
                     // Execute input callback
700
-                    if (!empty( $this->callbacks['input'])) {
701
-                        call_user_func($this->callbacks['input'], (object)$this->file);
700
+                    if (!empty($this->callbacks['input'])) {
701
+                        call_user_func($this->callbacks['input'], (object) $this->file);
702 702
                     }
703 703
                    
704 704
 
@@ -710,8 +710,8 @@  discard block
 block discarded – undo
710 710
                     );
711 711
 
712 712
                     // Execute output callback
713
-                    if (!empty( $this->callbacks['output'])) {
714
-                        call_user_func($this->callbacks['output'], (object)$this->file);
713
+                    if (!empty($this->callbacks['output'])) {
714
+                        call_user_func($this->callbacks['output'], (object) $this->file);
715 715
                     }
716 716
                     return $this->file['status'];
717 717
                 }
@@ -730,10 +730,10 @@  discard block
 block discarded – undo
730 730
         */
731 731
         public function sizeFormat($size, $precision = 2)
732 732
         {
733
-            if($size > 0){
733
+            if ($size > 0) {
734 734
                 $base       = log($size) / log(1024);
735 735
                 $suffixes   = array('B', 'K', 'M', 'G', 'T');
736
-                return round(pow(1024, $base - floor($base)), $precision) . ( isset($suffixes[floor($base)]) ? $suffixes[floor($base)] : '');
736
+                return round(pow(1024, $base - floor($base)), $precision) . (isset($suffixes[floor($base)]) ? $suffixes[floor($base)] : '');
737 737
             }
738 738
             return null;
739 739
         }
@@ -757,14 +757,14 @@  discard block
 block discarded – undo
757 757
             if (array_key_exists('unit', $matches)) {
758 758
                 $unit = strtoupper($matches['unit']);
759 759
             }
760
-            return (floatval($matches['size']) * pow(1024, $units[$unit]) ) ;
760
+            return (floatval($matches['size']) * pow(1024, $units[$unit]));
761 761
         }
762 762
 
763 763
         /**
764 764
          * Get the upload error message
765 765
          * @return string
766 766
          */
767
-        public function getError(){
767
+        public function getError() {
768 768
             return $this->error;
769 769
         }
770 770
 
@@ -772,7 +772,7 @@  discard block
 block discarded – undo
772 772
          * Set the upload error message
773 773
          * @param string $message the upload error message to set
774 774
          */
775
-        public function setError($message){
775
+        public function setError($message) {
776 776
             $this->logger->info('The upload got error : ' . $message);
777 777
             $this->error = $message;
778 778
         }
@@ -782,7 +782,7 @@  discard block
 block discarded – undo
782 782
          * @param  int $code the error code
783 783
          * @return string the error message
784 784
          */
785
-        private function getPhpUploadErrorMessageByCode($code){
785
+        private function getPhpUploadErrorMessageByCode($code) {
786 786
             $codeMessageMaps = array(
787 787
                 1 => $this->error_messages['upload_err_ini_size'],
788 788
                 2 => $this->error_messages['upload_err_form_size'],
Please login to merge, or discard this patch.
tests/tnhfw/classes/DBSessionHandlerTest.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 
48 48
 		
49 49
 		
50
-		public function testUsingSessionConfiguration(){
50
+		public function testUsingSessionConfiguration() {
51 51
 			//using value in the configuration
52 52
 			static::$config->set('session_save_path', 'DBSessionModel');
53 53
 			static::$config->set('session_secret', $this->secret);
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 			$this->assertEquals($dbsh->decode($encoded), 'foo');
74 74
 		}
75 75
 		
76
-		public function testWhenDataIsExpired(){
76
+		public function testWhenDataIsExpired() {
77 77
 			$dbsh = new DBSessionHandler($this->model);
78 78
 			$dbsh->setSessionSecret($this->secret);
79 79
 			
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
 			$this->assertFalse($dbsh->read('foo'));
87 87
 		}
88 88
 		
89
-		public function testWhenDataAlreadyExistDoUpdate(){
89
+		public function testWhenDataAlreadyExistDoUpdate() {
90 90
 			$dbsh = new DBSessionHandler($this->model);
91 91
 			$dbsh->setSessionSecret($this->secret);
92 92
 			
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
 			$this->assertEquals($dbsh->read('foo'), '445');	
100 100
 		}
101 101
 		
102
-		public function testUsingCustomModelInstance(){
102
+		public function testUsingCustomModelInstance() {
103 103
 			$dbsh = new DBSessionHandler($this->model);
104 104
 			$dbsh->setSessionSecret($this->secret);
105 105
 			
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
 		}
128 128
 			
129 129
 			
130
-		public function testUsingCustomLogInstance(){
130
+		public function testUsingCustomLogInstance() {
131 131
 			$dbsh = new DBSessionHandler($this->model, new Log());
132 132
 			$dbsh->setSessionSecret($this->secret);
133 133
 			
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 			$this->assertEquals($dbsh->decode($encoded), 'foo');
155 155
 		}
156 156
 		
157
-		public function testUsingCustomLoaderInstance(){
157
+		public function testUsingCustomLoaderInstance() {
158 158
 			$dbsh = new DBSessionHandler($this->model, null, new Loader());
159 159
 			$dbsh->setSessionSecret($this->secret);
160 160
 			
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
 		}
183 183
 		
184 184
 		
185
-		public function testWhenModelInsanceIsNotSet(){
185
+		public function testWhenModelInsanceIsNotSet() {
186 186
 			$dbsh = new DBSessionHandler(null, null, new Loader());
187 187
 			$dbsh->setSessionSecret($this->secret);
188 188
 			
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
 			$this->assertEquals($dbsh->decode($encoded), 'foo');
211 211
 		}
212 212
 		
213
-		public function testWhenModelTableColumnsIsNotSet(){
213
+		public function testWhenModelTableColumnsIsNotSet() {
214 214
 			//session table is empty
215 215
 			$this->model->setSessionTableColumns(array());
216 216
 			$dbsh = new DBSessionHandler($this->model);
Please login to merge, or discard this patch.
core/classes/Config.php 1 patch
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
 	*/
26 26
 
27
-	class Config{
27
+	class Config {
28 28
 		
29 29
 		/**
30 30
 		 * The list of loaded configuration
@@ -42,10 +42,10 @@  discard block
 block discarded – undo
42 42
 		 * The signleton of the logger
43 43
 		 * @return Object the Log instance
44 44
 		 */
45
-		private static function getLogger(){
46
-			if(self::$logger == null){
45
+		private static function getLogger() {
46
+			if (self::$logger == null) {
47 47
 				$logger = array();
48
-				$logger[0] =& class_loader('Log', 'classes');
48
+				$logger[0] = & class_loader('Log', 'classes');
49 49
 				$logger[0]->setLogger('Library::Config');
50 50
 				self::$logger = $logger[0];
51 51
 			}
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 		 * @param Log $logger the log object
58 58
 		 * @return Log the log instance
59 59
 		 */
60
-		public static function setLogger($logger){
60
+		public static function setLogger($logger) {
61 61
 			self::$logger = $logger;
62 62
 			return self::$logger;
63 63
 		}
@@ -65,35 +65,35 @@  discard block
 block discarded – undo
65 65
 		/**
66 66
 		 * Initialize the configuration by loading all the configuration from config file
67 67
 		 */
68
-		public static function init(){
68
+		public static function init() {
69 69
 			$logger = static::getLogger();
70 70
 			$logger->debug('Initialization of the configuration');
71 71
 			self::$config = & load_configurations();
72
-			if(! self::$config['base_url'] || ! is_url(self::$config['base_url'])){
73
-				if(ENVIRONMENT == 'production'){
72
+			if (!self::$config['base_url'] || !is_url(self::$config['base_url'])) {
73
+				if (ENVIRONMENT == 'production') {
74 74
 					$logger->warning('Application base URL is not set or invalid, please set application base URL to increase the application loading time');
75 75
 				}
76 76
 				$baseUrl = null;
77
-				if (isset($_SERVER['SERVER_ADDR'])){
77
+				if (isset($_SERVER['SERVER_ADDR'])) {
78 78
 					//check if the server is running under IPv6
79
-					if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE){
80
-						$baseUrl = '['.$_SERVER['SERVER_ADDR'].']';
79
+					if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE) {
80
+						$baseUrl = '[' . $_SERVER['SERVER_ADDR'] . ']';
81 81
 					}
82
-					else{
82
+					else {
83 83
 						$baseUrl = $_SERVER['SERVER_ADDR'];
84 84
 					}
85
-					$port = ((isset($_SERVER['SERVER_PORT']) && ($_SERVER['SERVER_PORT'] != '80' && ! is_https() || $_SERVER['SERVER_PORT'] != '443' && is_https()) ) ? ':' . $_SERVER['SERVER_PORT'] : '');
86
-					$baseUrl = (is_https() ? 'https' : 'http').'://' . $baseUrl . $port
85
+					$port = ((isset($_SERVER['SERVER_PORT']) && ($_SERVER['SERVER_PORT'] != '80' && !is_https() || $_SERVER['SERVER_PORT'] != '443' && is_https())) ? ':' . $_SERVER['SERVER_PORT'] : '');
86
+					$baseUrl = (is_https() ? 'https' : 'http') . '://' . $baseUrl . $port
87 87
 						. substr($_SERVER['SCRIPT_NAME'], 0, strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME'])));
88 88
 				}
89
-				else{
89
+				else {
90 90
 					$logger->warning('Can not determine the application base URL automatically, use http://localhost as default');
91 91
 					$baseUrl = 'http://localhost/';
92 92
 				}
93 93
 				self::set('base_url', $baseUrl);
94 94
 			}
95
-			self::$config['base_url'] = rtrim(self::$config['base_url'], '/') .'/';
96
-			if(ENVIRONMENT == 'production' && in_array(strtolower(self::$config['log_level']), array('debug', 'info','all'))){
95
+			self::$config['base_url'] = rtrim(self::$config['base_url'], '/') . '/';
96
+			if (ENVIRONMENT == 'production' && in_array(strtolower(self::$config['log_level']), array('debug', 'info', 'all'))) {
97 97
 				$logger->warning('You are in production environment, please set log level to WARNING, ERROR, FATAL to increase the application performance');
98 98
 			}
99 99
 			$logger->info('Configuration initialized successfully');
@@ -106,12 +106,12 @@  discard block
 block discarded – undo
106 106
 		 * @param  mixed $default the default value to use if can not find the config item in the list
107 107
 		 * @return mixed          the config value if exist or the default value
108 108
 		 */
109
-		public static function get($item, $default = null){
109
+		public static function get($item, $default = null) {
110 110
 			$logger = static::getLogger();
111
-			if(array_key_exists($item, self::$config)){
111
+			if (array_key_exists($item, self::$config)) {
112 112
 				return self::$config[$item];
113 113
 			}
114
-			$logger->warning('Cannot find config item ['.$item.'] using the default value ['.$default.']');
114
+			$logger->warning('Cannot find config item [' . $item . '] using the default value [' . $default . ']');
115 115
 			return $default;
116 116
 		}
117 117
 
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
 		 * @param string $item  the config item name to set
121 121
 		 * @param mixed $value the config item value
122 122
 		 */
123
-		public static function set($item, $value){
123
+		public static function set($item, $value) {
124 124
 			self::$config[$item] = $value;
125 125
 		}
126 126
 
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 		 * Get all the configuration values
129 129
 		 * @return array the config values
130 130
 		 */
131
-		public static function getAll(){
131
+		public static function getAll() {
132 132
 			return self::$config;
133 133
 		}
134 134
 
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
 		 * Set the configuration values bu merged with the existing configuration
137 137
 		 * @param array $config the config values to add in the configuration list
138 138
 		 */
139
-		public static function setAll(array $config = array()){
139
+		public static function setAll(array $config = array()) {
140 140
 			self::$config = array_merge(self::$config, $config);
141 141
 		}
142 142
 
@@ -145,15 +145,15 @@  discard block
 block discarded – undo
145 145
 		 * @param  string $item the config item name to be deleted
146 146
 		 * @return boolean true if the item exists and is deleted successfully otherwise will return false.
147 147
 		 */
148
-		public static function delete($item){
148
+		public static function delete($item) {
149 149
 			$logger = static::getLogger();
150
-			if(array_key_exists($item, self::$config)){
151
-				$logger->info('Delete config item ['.$item.']');
150
+			if (array_key_exists($item, self::$config)) {
151
+				$logger->info('Delete config item [' . $item . ']');
152 152
 				unset(self::$config[$item]);
153 153
 				return true;
154 154
 			}
155
-			else{
156
-				$logger->warning('Config item ['.$item.'] to be deleted does not exists');
155
+			else {
156
+				$logger->warning('Config item [' . $item . '] to be deleted does not exists');
157 157
 				return false;
158 158
 			}
159 159
 		}
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
 		 * Load the configuration file. This an alias to Loader::config()
163 163
 		 * @param  string $config the config name to be loaded
164 164
 		 */
165
-		public static function load($config){
165
+		public static function load($config) {
166 166
 			Loader::config($config);
167 167
 		}
168 168
 	}
Please login to merge, or discard this patch.
core/classes/DBSessionHandler.php 1 patch
Spacing   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -27,11 +27,11 @@  discard block
 block discarded – undo
27 27
 	/**
28 28
 	 * check if the interface "SessionHandlerInterface" exists (normally in PHP 5.4 this already exists)
29 29
 	 */
30
-	if( !interface_exists('SessionHandlerInterface')){
30
+	if (!interface_exists('SessionHandlerInterface')) {
31 31
 		show_error('"SessionHandlerInterface" interface does not exists or is disabled can not use it to handler database session.');
32 32
 	}
33 33
 
34
-	class DBSessionHandler implements SessionHandlerInterface{
34
+	class DBSessionHandler implements SessionHandlerInterface {
35 35
 		
36 36
 		/**
37 37
 		 * The encryption method to use to encrypt session data in database
@@ -81,25 +81,25 @@  discard block
 block discarded – undo
81 81
          */
82 82
         protected $loader = null;
83 83
 
84
-		public function __construct(DBSessionHandlerModel $modelInstance = null, Log $logger = null, Loader $loader = null){
84
+		public function __construct(DBSessionHandlerModel $modelInstance = null, Log $logger = null, Loader $loader = null) {
85 85
 			/**
86 86
 	         * instance of the Log class
87 87
 	         */
88
-	        if(is_object($logger)){
88
+	        if (is_object($logger)) {
89 89
 	          $this->setLogger($logger);
90 90
 	        }
91
-	        else{
92
-	            $this->logger =& class_loader('Log', 'classes');
91
+	        else {
92
+	            $this->logger = & class_loader('Log', 'classes');
93 93
 	            $this->logger->setLogger('Library::DBSessionHandler');
94 94
 	        }
95 95
 
96
-	        if(is_object($loader)){
96
+	        if (is_object($loader)) {
97 97
 	          $this->setLoader($loader);
98 98
 	        }
99 99
 		    $this->OBJ = & get_instance();
100 100
 
101 101
 		    
102
-			if(is_object($modelInstance)){
102
+			if (is_object($modelInstance)) {
103 103
 				$this->setModelInstance($modelInstance);
104 104
 			}
105 105
 		}
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
 		 * Set the session secret used to encrypt the data in database 
109 109
 		 * @param string $secret the base64 string secret
110 110
 		 */
111
-		public function setSessionSecret($secret){
111
+		public function setSessionSecret($secret) {
112 112
 			$this->sessionSecret = $secret;
113 113
 			return $this;
114 114
 		}
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
 		 * Return the session secret
118 118
 		 * @return string 
119 119
 		 */
120
-		public function getSessionSecret(){
120
+		public function getSessionSecret() {
121 121
 			return $this->sessionSecret;
122 122
 		}
123 123
 
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
 		 * Set the initializer vector for openssl 
127 127
 		 * @param string $key the session secret used
128 128
 		 */
129
-		public function setInitializerVector($key){
129
+		public function setInitializerVector($key) {
130 130
 			$iv_length = openssl_cipher_iv_length(self::DB_SESSION_HASH_METHOD);
131 131
 			$key = base64_decode($key);
132 132
 			$this->iv = substr(hash('sha256', $key), 0, $iv_length);
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
 		 * Return the initializer vector
138 138
 		 * @return string 
139 139
 		 */
140
-		public function getInitializerVector(){
140
+		public function getInitializerVector() {
141 141
 			return $this->iv;
142 142
 		}
143 143
 
@@ -147,16 +147,16 @@  discard block
 block discarded – undo
147 147
 		 * @param  string $sessionName the session name
148 148
 		 * @return boolean 
149 149
 		 */
150
-		public function open($savePath, $sessionName){
150
+		public function open($savePath, $sessionName) {
151 151
 			$this->logger->debug('Opening database session handler for [' . $sessionName . ']');
152 152
 			//try to check if session secret is set before
153
-			if(! $this->getSessionSecret()){
153
+			if (!$this->getSessionSecret()) {
154 154
 				$secret = get_config('session_secret', false);
155 155
 				$this->setSessionSecret($secret);
156 156
 			}
157 157
 			$this->logger->info('Session secret: ' . $this->getSessionSecret());
158 158
 
159
-			if(! $this->getModelInstance()){
159
+			if (!$this->getModelInstance()) {
160 160
 				$this->setModelInstanceFromConfig();
161 161
 			}
162 162
 			$this->setInitializerVector($this->getSessionSecret());
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
 			//set session tables columns
165 165
 			$this->sessionTableColumns = $this->getModelInstance()->getSessionTableColumns();
166 166
 
167
-			if(empty($this->sessionTableColumns)){
167
+			if (empty($this->sessionTableColumns)) {
168 168
 				show_error('The session handler is "database" but the table columns not set');
169 169
 			}
170 170
 			$this->logger->info('Database session, the model columns are listed below: ' . stringfy_vars($this->sessionTableColumns));
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
 		 * Close the session
181 181
 		 * @return boolean
182 182
 		 */
183
-		public function close(){
183
+		public function close() {
184 184
 			$this->logger->debug('Closing database session handler');
185 185
 			return true;
186 186
 		}
@@ -190,28 +190,28 @@  discard block
 block discarded – undo
190 190
 		 * @param  string $sid the session id to use
191 191
 		 * @return mixed      the session data in serialiaze format
192 192
 		 */
193
-		public function read($sid){
193
+		public function read($sid) {
194 194
 			$this->logger->debug('Reading database session data for SID: ' . $sid);
195 195
 			$instance = $this->getModelInstance();
196 196
 			$columns = $this->sessionTableColumns;
197
-			if($this->getLoader()){
197
+			if ($this->getLoader()) {
198 198
 				$this->getLoader()->functions('user_agent'); 
199 199
 				$this->getLoader()->library('Browser'); 
200 200
 			}
201
-			else{
201
+			else {
202 202
             	Loader::functions('user_agent');
203 203
             	Loader::library('Browser');
204 204
             }
205 205
 			
206 206
 			$ip = get_ip();
207 207
 			$host = @gethostbyaddr($ip) or null;
208
-			$browser = $this->OBJ->browser->getPlatform().', '.$this->OBJ->browser->getBrowser().' '.$this->OBJ->browser->getVersion();
208
+			$browser = $this->OBJ->browser->getPlatform() . ', ' . $this->OBJ->browser->getBrowser() . ' ' . $this->OBJ->browser->getVersion();
209 209
 			
210 210
 			$data = $instance->get_by(array($columns['sid'] => $sid, $columns['shost'] => $host, $columns['sbrowser'] => $browser));
211
-			if($data && isset($data->{$columns['sdata']})){
211
+			if ($data && isset($data->{$columns['sdata']})) {
212 212
 				//checking inactivity 
213 213
 				$timeInactivity = time() - get_config('session_inactivity_time', 100);
214
-				if($data->{$columns['stime']} < $timeInactivity){
214
+				if ($data->{$columns['stime']} < $timeInactivity) {
215 215
 					$this->logger->info('Database session data for SID: ' . $sid . ' already expired, destroy it');
216 216
 					$this->destroy($sid);
217 217
 					return false;
@@ -228,16 +228,16 @@  discard block
 block discarded – undo
228 228
 		 * @param  mixed $data the session data to save in serialize format
229 229
 		 * @return boolean 
230 230
 		 */
231
-		public function write($sid, $data){
231
+		public function write($sid, $data) {
232 232
 			$this->logger->debug('Saving database session data for SID: ' . $sid . ', data: ' . stringfy_vars($data));
233 233
 			$instance = $this->getModelInstance();
234 234
 			$columns = $this->sessionTableColumns;
235 235
 
236
-			if($this->getLoader()){
236
+			if ($this->getLoader()) {
237 237
 				$this->getLoader()->functions('user_agent'); 
238 238
 				$this->getLoader()->library('Browser'); 
239 239
 			}
240
-			else{
240
+			else {
241 241
             	Loader::functions('user_agent');
242 242
             	Loader::library('Browser');
243 243
             }
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
 			$ip = get_ip();
246 246
 			$keyValue = $instance->getKeyValue();
247 247
 			$host = @gethostbyaddr($ip) or null;
248
-			$browser = $this->OBJ->browser->getPlatform().', '.$this->OBJ->browser->getBrowser().' '.$this->OBJ->browser->getVersion();
248
+			$browser = $this->OBJ->browser->getPlatform() . ', ' . $this->OBJ->browser->getBrowser() . ' ' . $this->OBJ->browser->getVersion();
249 249
 			$data = $this->encode($data);
250 250
 			$params = array(
251 251
 							$columns['sid'] => $sid,
@@ -258,13 +258,13 @@  discard block
 block discarded – undo
258 258
 						);
259 259
 			$this->logger->info('Database session data to save are listed below :' . stringfy_vars($params));
260 260
 			$exists = $instance->get($sid);
261
-			if($exists){
261
+			if ($exists) {
262 262
 				$this->logger->info('Session data for SID: ' . $sid . ' already exists, just update it');
263 263
 				//update
264 264
 				unset($params[$columns['sid']]);
265 265
 				$instance->update($sid, $params);
266 266
 			}
267
-			else{
267
+			else {
268 268
 				$this->logger->info('Session data for SID: ' . $sid . ' not yet exists, insert it now');
269 269
 				$instance->insert($params);
270 270
 			}
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
 		 * @param  string $sid the session id value
278 278
 		 * @return boolean
279 279
 		 */
280
-		public function destroy($sid){
280
+		public function destroy($sid) {
281 281
 			$this->logger->debug('Destroy of session data for SID: ' . $sid);
282 282
 			$instance = $this->modelInstanceName;
283 283
 			$instance->delete($sid);
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
 		 * @param  integer $maxLifetime the max lifetime
290 290
 		 * @return boolean
291 291
 		 */
292
-		public function gc($maxLifetime){
292
+		public function gc($maxLifetime) {
293 293
 			$instance = $this->modelInstanceName;
294 294
 			$time = time() - $maxLifetime;
295 295
 			$this->logger->debug('Garbage collector of expired session. maxLifetime [' . $maxLifetime . '] sec, expired time [' . $time . ']');
@@ -302,9 +302,9 @@  discard block
 block discarded – undo
302 302
 		 * @param  mixed $data the session data to encode
303 303
 		 * @return mixed the encoded session data
304 304
 		 */
305
-		public function encode($data){
305
+		public function encode($data) {
306 306
 			$key = base64_decode($this->sessionSecret);
307
-			$dataEncrypted = openssl_encrypt($data , self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector());
307
+			$dataEncrypted = openssl_encrypt($data, self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector());
308 308
 			$output = base64_encode($dataEncrypted);
309 309
 			return $output;
310 310
 		}
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
 		 * @param  mixed $data the data to decode
316 316
 		 * @return mixed       the decoded data
317 317
 		 */
318
-		public function decode($data){
318
+		public function decode($data) {
319 319
 			$key = base64_decode($this->sessionSecret);
320 320
 			$data = base64_decode($data);
321 321
 			$data = openssl_decrypt($data, self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector());
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
          * Return the loader instance
328 328
          * @return object Loader the loader instance
329 329
          */
330
-        public function getLoader(){
330
+        public function getLoader() {
331 331
             return $this->loader;
332 332
         }
333 333
 
@@ -335,7 +335,7 @@  discard block
 block discarded – undo
335 335
          * set the loader instance for future use
336 336
          * @param object Loader $loader the loader object
337 337
          */
338
-         public function setLoader($loader){
338
+         public function setLoader($loader) {
339 339
             $this->loader = $loader;
340 340
             return $this;
341 341
         }
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
          * Return the model instance
345 345
          * @return object DBSessionHandlerModel the model instance
346 346
          */
347
-        public function getModelInstance(){
347
+        public function getModelInstance() {
348 348
             return $this->modelInstanceName;
349 349
         }
350 350
 
@@ -352,7 +352,7 @@  discard block
 block discarded – undo
352 352
          * set the model instance for future use
353 353
          * @param DBSessionHandlerModel $modelInstance the model object
354 354
          */
355
-         public function setModelInstance(DBSessionHandlerModel $modelInstance){
355
+         public function setModelInstance(DBSessionHandlerModel $modelInstance) {
356 356
             $this->modelInstanceName = $modelInstance;
357 357
             return $this;
358 358
         }
@@ -361,7 +361,7 @@  discard block
 block discarded – undo
361 361
 	     * Return the Log instance
362 362
 	     * @return Log
363 363
 	     */
364
-	    public function getLogger(){
364
+	    public function getLogger() {
365 365
 	      return $this->logger;
366 366
 	    }
367 367
 
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
 	     * Set the log instance
370 370
 	     * @param Log $logger the log object
371 371
 	     */
372
-	    public function setLogger(Log $logger){
372
+	    public function setLogger(Log $logger) {
373 373
 	      $this->logger = $logger;
374 374
 	      return $this;
375 375
 	    }
@@ -377,18 +377,18 @@  discard block
 block discarded – undo
377 377
 	    /**
378 378
 	     * Set the model instance using the configuration for session
379 379
 	     */
380
-	    private function setModelInstanceFromConfig(){
380
+	    private function setModelInstanceFromConfig() {
381 381
 	    	$modelName = get_config('session_save_path');
382 382
 			$this->logger->info('The database session model: ' . $modelName);
383
-			if($this->getLoader()){
383
+			if ($this->getLoader()) {
384 384
 				$this->getLoader()->model($modelName, 'dbsessionhandlerinstance'); 
385 385
 			}
386 386
 			//@codeCoverageIgnoreStart
387
-			else{
387
+			else {
388 388
             	Loader::model($modelName, 'dbsessionhandlerinstance'); 
389 389
             }
390
-            if(isset($this->OBJ->dbsessionhandlerinstance) && ! $this->OBJ->dbsessionhandlerinstance instanceof DBSessionHandlerModel){
391
-				show_error('To use database session handler, your class model "'.get_class($this->OBJ->dbsessionhandlerinstance).'" need extends "DBSessionHandlerModel"');
390
+            if (isset($this->OBJ->dbsessionhandlerinstance) && !$this->OBJ->dbsessionhandlerinstance instanceof DBSessionHandlerModel) {
391
+				show_error('To use database session handler, your class model "' . get_class($this->OBJ->dbsessionhandlerinstance) . '" need extends "DBSessionHandlerModel"');
392 392
 			}  
393 393
 			//@codeCoverageIgnoreEnd
394 394
 			
Please login to merge, or discard this patch.