Passed
Push — 1.0.0-dev ( b68981...00dab9 )
by nguereza
05:23
created
core/classes/database/DatabaseQueryRunner.php 1 patch
Spacing   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -23,19 +23,19 @@  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 DatabaseQueryRunner{
26
+  class DatabaseQueryRunner {
27 27
       
28 28
     /**
29 29
 	* The logger instance
30 30
 	* @var object
31 31
 	*/
32
-    private $logger            = null;
32
+    private $logger = null;
33 33
     
34 34
   	/**
35 35
   	 * The last query result
36 36
   	 * @var object
37 37
   	*/
38
-  	private $queryResult       = null;
38
+  	private $queryResult = null;
39 39
   	
40 40
   	/**
41 41
     * The benchmark instance
@@ -47,45 +47,45 @@  discard block
 block discarded – undo
47 47
 	 * The SQL query statment to execute
48 48
 	 * @var string
49 49
 	*/
50
-    private $query             = null;
50
+    private $query = null;
51 51
     
52 52
     /**
53 53
 	 * Indicate if we need return result as list (boolean) 
54 54
      * or the data used to replace the placeholder (array)
55 55
 	 * @var array|boolean
56 56
 	 */
57
-     private $returnAsList     = true;
57
+     private $returnAsList = true;
58 58
      
59 59
      
60 60
      /**
61 61
 	   * Indicate if we need return result as array or not
62 62
      * @var boolean
63 63
 	   */
64
-     private $returnAsArray     = true;
64
+     private $returnAsArray = true;
65 65
      
66 66
      /**
67 67
      * The last PDOStatment instance
68 68
      * @var object
69 69
      */
70
-     private $pdoStatment       = null;
70
+     private $pdoStatment = null;
71 71
      
72 72
      /**
73 73
   	 * The error returned for the last query
74 74
   	 * @var string
75 75
   	 */
76
-     private $error             = null;
76
+     private $error = null;
77 77
 	
78 78
     /**
79 79
      * The PDO instance
80 80
      * @var object
81 81
     */
82
-    private $pdo                = null;
82
+    private $pdo = null;
83 83
   
84 84
     /**
85 85
      * The database driver name used
86 86
      * @var string
87 87
     */
88
-    private $driver             = null;
88
+    private $driver = null;
89 89
 
90 90
 
91 91
 	
@@ -96,8 +96,8 @@  discard block
 block discarded – undo
96 96
      * @param boolean $returnAsList if need return as list or just one row
97 97
      * @param boolean $returnAsArray whether to return the result as array or not
98 98
      */
99
-    public function __construct(PDO $pdo = null, $query = null, $returnAsList = true, $returnAsArray = false){
100
-        if (is_object($pdo)){
99
+    public function __construct(PDO $pdo = null, $query = null, $returnAsList = true, $returnAsArray = false) {
100
+        if (is_object($pdo)) {
101 101
           $this->pdo = $pdo;
102 102
         }
103 103
         $this->query         = $query;
@@ -112,13 +112,13 @@  discard block
 block discarded – undo
112 112
      * 
113 113
      * @return object|void
114 114
      */
115
-    public function execute(){
115
+    public function execute() {
116 116
         //reset instance
117 117
         $this->reset();
118 118
        
119 119
        //for database query execution time
120 120
         $benchmarkMarkerKey = $this->getBenchmarkKey();
121
-        if (! is_object($this->benchmarkInstance)){
121
+        if (!is_object($this->benchmarkInstance)) {
122 122
           $this->benchmarkInstance = & class_loader('Benchmark');
123 123
         }
124 124
         
@@ -134,19 +134,19 @@  discard block
 block discarded – undo
134 134
                                                                 'DATABASE_QUERY_END(' . $benchmarkMarkerKey . ')'
135 135
                                                               );
136 136
 		    //TODO use the configuration value for the high response time currently is 1 second
137
-        if ($responseTime >= 1 ){
137
+        if ($responseTime >= 1) {
138 138
             $this->logger->warning(
139 139
                                     'High response time while processing database query [' . $this->query . ']. 
140
-                                     The response time is [' .$responseTime. '] sec.'
140
+                                     The response time is [' .$responseTime . '] sec.'
141 141
                                   );
142 142
         }
143 143
 		
144
-        if ($this->pdoStatment !== false){
144
+        if ($this->pdoStatment !== false) {
145 145
           $isSqlSELECTQuery = stristr($this->query, 'SELECT') !== false;
146
-          if($isSqlSELECTQuery){
146
+          if ($isSqlSELECTQuery) {
147 147
               $this->setResultForSelect();              
148 148
           }
149
-          else{
149
+          else {
150 150
               $this->setResultForNonSelect();
151 151
           }
152 152
           return $this->queryResult;
@@ -158,28 +158,28 @@  discard block
 block discarded – undo
158 158
    * Return the result for SELECT query
159 159
    * @see DatabaseQueryRunner::execute
160 160
    */
161
-    protected function setResultForSelect(){
161
+    protected function setResultForSelect() {
162 162
       //if need return all result like list of record
163 163
       $result = null;
164 164
       $numRows = 0;
165 165
       $fetchMode = PDO::FETCH_OBJ;
166
-      if($this->returnAsArray){
166
+      if ($this->returnAsArray) {
167 167
         $fetchMode = PDO::FETCH_ASSOC;
168 168
       }
169
-      if ($this->returnAsList){
169
+      if ($this->returnAsList) {
170 170
           $result = $this->pdoStatment->fetchAll($fetchMode);
171 171
       }
172
-      else{
172
+      else {
173 173
           $result = $this->pdoStatment->fetch($fetchMode);
174 174
       }
175 175
       //Sqlite and pgsql always return 0 when using rowCount()
176
-      if (in_array($this->driver, array('sqlite', 'pgsql'))){
176
+      if (in_array($this->driver, array('sqlite', 'pgsql'))) {
177 177
         $numRows = count($result);  
178 178
       }
179
-      else{
179
+      else {
180 180
         $numRows = $this->pdoStatment->rowCount(); 
181 181
       }
182
-      if(! is_object($this->queryResult)){
182
+      if (!is_object($this->queryResult)) {
183 183
           $this->queryResult = & class_loader('DatabaseQueryResult', 'classes/database');
184 184
       }
185 185
       $this->queryResult->setResult($result);
@@ -190,20 +190,20 @@  discard block
 block discarded – undo
190 190
    * Return the result for non SELECT query
191 191
    * @see DatabaseQueryRunner::execute
192 192
    */
193
-    protected function setResultForNonSelect(){
193
+    protected function setResultForNonSelect() {
194 194
       //Sqlite and pgsql always return 0 when using rowCount()
195 195
       $result = false;
196 196
       $numRows = 0;
197
-      if (in_array($this->driver, array('sqlite', 'pgsql'))){
197
+      if (in_array($this->driver, array('sqlite', 'pgsql'))) {
198 198
         $result = true; //to test the result for the query like UPDATE, INSERT, DELETE
199 199
         $numRows = 1; //TODO use the correct method to get the exact affected row
200 200
       }
201
-      else{
201
+      else {
202 202
           //to test the result for the query like UPDATE, INSERT, DELETE
203 203
           $result  = $this->pdoStatment->rowCount() >= 0; 
204 204
           $numRows = $this->pdoStatment->rowCount(); 
205 205
       }
206
-      if(! is_object($this->queryResult)){
206
+      if (!is_object($this->queryResult)) {
207 207
           $this->queryResult = & class_loader('DatabaseQueryResult', 'classes/database');
208 208
       }
209 209
       $this->queryResult->setResult($result);
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
      * Return the benchmark instance
216 216
      * @return Benchmark
217 217
      */
218
-    public function getBenchmark(){
218
+    public function getBenchmark() {
219 219
       return $this->benchmarkInstance;
220 220
     }
221 221
 
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
      * @param Benchmark $benchmark the benchmark object
225 225
 	 * @return object DatabaseQueryRunner
226 226
      */
227
-    public function setBenchmark($benchmark){
227
+    public function setBenchmark($benchmark) {
228 228
       $this->benchmarkInstance = $benchmark;
229 229
       return $this;
230 230
     }
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
      *
235 235
      * @return object DatabaseQueryResult
236 236
      */
237
-    public function getQueryResult(){
237
+    public function getQueryResult() {
238 238
       return $this->queryResult;
239 239
     }
240 240
 
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
      *
245 245
 	 * @return object DatabaseQueryRunner
246 246
      */
247
-    public function setQueryResult(DatabaseQueryResult $queryResult){
247
+    public function setQueryResult(DatabaseQueryResult $queryResult) {
248 248
       $this->queryResult = $queryResult;
249 249
       return $this;
250 250
     }
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
      * Return the Log instance
254 254
      * @return Log
255 255
      */
256
-    public function getLogger(){
256
+    public function getLogger() {
257 257
       return $this->logger;
258 258
     }
259 259
 
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
      * @param Log $logger the log object
263 263
 	 * @return object DatabaseQueryRunner
264 264
      */
265
-    public function setLogger($logger){
265
+    public function setLogger($logger) {
266 266
       $this->logger = $logger;
267 267
       return $this;
268 268
     }
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
      * Return the current query SQL string
272 272
      * @return string
273 273
      */
274
-    public function getQuery(){
274
+    public function getQuery() {
275 275
       return $this->query;
276 276
     }
277 277
     
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
      * @param string $query the SQL query to set
281 281
      * @return object DatabaseQueryRunner
282 282
      */
283
-    public function setQuery($query){
283
+    public function setQuery($query) {
284 284
        $this->query = $query;
285 285
        return $this;
286 286
     }
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
      * @param boolean $returnType
291 291
      * @return object DatabaseQueryRunner
292 292
      */
293
-    public function setReturnType($returnType){
293
+    public function setReturnType($returnType) {
294 294
        $this->returnAsList = $returnType;
295 295
        return $this;
296 296
     }
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
      * @param boolean $status the status if true will return as array
301 301
      * @return object DatabaseQueryRunner
302 302
      */
303
-    public function setReturnAsArray($status = true){
303
+    public function setReturnAsArray($status = true) {
304 304
        $this->returnAsArray = $status;
305 305
        return $this;
306 306
     }
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
      * Return the error for last query execution
310 310
      * @return string
311 311
      */
312
-    public function getQueryError(){
312
+    public function getQueryError() {
313 313
       return $this->error;
314 314
     }
315 315
 
@@ -317,7 +317,7 @@  discard block
 block discarded – undo
317 317
      * Return the PDO instance
318 318
      * @return object
319 319
      */
320
-    public function getPdo(){
320
+    public function getPdo() {
321 321
       return $this->pdo;
322 322
     }
323 323
 
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
      * @param PDO $pdo the pdo object
327 327
      * @return object DatabaseQueryRunner
328 328
      */
329
-    public function setPdo(PDO $pdo = null){
329
+    public function setPdo(PDO $pdo = null) {
330 330
       $this->pdo = $pdo;
331 331
       return $this;
332 332
     }
@@ -335,7 +335,7 @@  discard block
 block discarded – undo
335 335
      * Return the database driver
336 336
      * @return string
337 337
      */
338
-    public function getDriver(){
338
+    public function getDriver() {
339 339
       return $this->driver;
340 340
     }
341 341
 
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
      * @param string $driver the new driver
345 345
      * @return object DatabaseQueryRunner
346 346
      */
347
-    public function setDriver($driver){
347
+    public function setDriver($driver) {
348 348
       $this->driver = $driver;
349 349
       return $this;
350 350
     }
@@ -354,14 +354,14 @@  discard block
 block discarded – undo
354 354
      * 
355 355
      *  @return string
356 356
      */
357
-    protected function getBenchmarkKey(){
357
+    protected function getBenchmarkKey() {
358 358
       return md5($this->query . $this->returnAsList . $this->returnAsArray);
359 359
     }
360 360
     
361 361
     /**
362 362
      * Set error for database query execution
363 363
      */
364
-    protected function setQueryRunnerError(){
364
+    protected function setQueryRunnerError() {
365 365
       $error = $this->pdo->errorInfo();
366 366
       $this->error = isset($error[2]) ? $error[2] : '';
367 367
       $this->logger->error('The database query execution got an error: ' . stringfy_vars($error));
@@ -373,12 +373,12 @@  discard block
 block discarded – undo
373 373
      * Set the Log instance using argument or create new instance
374 374
      * @param object $logger the Log instance if not null
375 375
      */
376
-    protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){
377
-      if ($logger !== null){
376
+    protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null) {
377
+      if ($logger !== null) {
378 378
         $this->logger = $logger;
379 379
       }
380
-      else{
381
-          $this->logger =& class_loader('Log', 'classes');
380
+      else {
381
+          $this->logger = & class_loader('Log', 'classes');
382 382
           $this->logger->setLogger('Library::DatabaseQueryRunner');
383 383
       }
384 384
     }
@@ -387,7 +387,7 @@  discard block
 block discarded – undo
387 387
     /**
388 388
     * Reset the instance before run each query
389 389
     */
390
-    private function reset(){
390
+    private function reset() {
391 391
         $this->error = null;
392 392
         $this->pdoStatment = null;
393 393
     }
Please login to merge, or discard this patch.
core/classes/database/Database.php 1 patch
Spacing   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -23,105 +23,105 @@  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 number of rows returned by the last query
42 42
   	 * @var int
43 43
   	*/
44
-    private $numRows             = 0;
44
+    private $numRows = 0;
45 45
 	
46 46
   	/**
47 47
   	 * The last insert id for the primary key column that have auto increment or sequence
48 48
   	 * @var mixed
49 49
   	*/
50
-    private $insertId            = null;
50
+    private $insertId = null;
51 51
 	
52 52
   	/**
53 53
   	 * The full SQL query statment after build for each command
54 54
   	 * @var string
55 55
   	*/
56
-    private $query               = null;
56
+    private $query = null;
57 57
 	
58 58
   	/**
59 59
   	 * The result returned for the last query
60 60
   	 * @var mixed
61 61
   	*/
62
-    private $result              = array();
62
+    private $result = array();
63 63
 	
64 64
   	/**
65 65
   	 * The cache default time to live in second. 0 means no need to use the cache feature
66 66
   	 * @var int
67 67
   	*/
68
-  	private $cacheTtl             = 0;
68
+  	private $cacheTtl = 0;
69 69
 	
70 70
   	/**
71 71
   	 * The cache current time to live. 0 means no need to use the cache feature
72 72
   	 * @var int
73 73
   	*/
74
-    private $temporaryCacheTtl   = 0;
74
+    private $temporaryCacheTtl = 0;
75 75
 	
76 76
   	/**
77 77
   	 * The number of executed query for the current request
78 78
   	 * @var int
79 79
   	*/
80
-    private $queryCount          = 0;
80
+    private $queryCount = 0;
81 81
 	
82 82
   	/**
83 83
   	 * The default data to be used in the statments query INSERT, UPDATE
84 84
   	 * @var array
85 85
   	*/
86
-    private $data                = array();
86
+    private $data = array();
87 87
 	
88 88
   	/**
89 89
   	 * The database configuration
90 90
   	 * @var array
91 91
   	*/
92
-    private $config              = array();
92
+    private $config = array();
93 93
 	
94 94
   	/**
95 95
   	 * The logger instance
96 96
   	 * @var object
97 97
   	 */
98
-    private $logger              = null;
98
+    private $logger = null;
99 99
 
100 100
     /**
101 101
     * The cache instance
102 102
     * @var object
103 103
     */
104
-    private $cacheInstance       = null;
104
+    private $cacheInstance = null;
105 105
 
106 106
     
107 107
   	/**
108 108
     * The DatabaseQueryBuilder instance
109 109
     * @var object
110 110
     */
111
-    private $queryBuilder        = null;
111
+    private $queryBuilder = null;
112 112
     
113 113
     /**
114 114
     * The DatabaseQueryRunner instance
115 115
     * @var object
116 116
     */
117
-    private $queryRunner         = null;
117
+    private $queryRunner = null;
118 118
 
119 119
 
120 120
     /**
121 121
      * Construct new database
122 122
      * @param array $overwriteConfig the config to overwrite with the config set in database.php
123 123
      */
124
-    public function __construct($overwriteConfig = array()){
124
+    public function __construct($overwriteConfig = array()) {
125 125
         //Set Log instance to use
126 126
         $this->setLoggerFromParamOrCreateNewInstance(null);
127 127
 		
@@ -142,17 +142,17 @@  discard block
 block discarded – undo
142 142
      * This is used to connect to database
143 143
      * @return bool 
144 144
      */
145
-    public function connect(){
145
+    public function connect() {
146 146
       $config = $this->getDatabaseConfiguration();
147
-      if (! empty($config)){
148
-        try{
147
+      if (!empty($config)) {
148
+        try {
149 149
             $this->pdo = new PDO($this->getDsnFromDriver(), $config['username'], $config['password']);
150 150
             $this->pdo->exec("SET NAMES '" . $config['charset'] . "' COLLATE '" . $config['collation'] . "'");
151 151
             $this->pdo->exec("SET CHARACTER SET '" . $config['charset'] . "'");
152 152
             $this->pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
153 153
             return true;
154 154
           }
155
-          catch (PDOException $e){
155
+          catch (PDOException $e) {
156 156
             $this->logger->fatal($e->getMessage());
157 157
             show_error('Cannot connect to Database.');
158 158
             return false;
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
      * Return the number of rows returned by the current query
167 167
      * @return int
168 168
      */
169
-    public function numRows(){
169
+    public function numRows() {
170 170
       return $this->numRows;
171 171
     }
172 172
 
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
      * Return the last insert id value
175 175
      * @return mixed
176 176
      */
177
-    public function insertId(){
177
+    public function insertId() {
178 178
       return $this->insertId;
179 179
     }
180 180
 
@@ -185,10 +185,10 @@  discard block
 block discarded – undo
185 185
      * If is string will determine the result type "array" or "object"
186 186
      * @return mixed       the query SQL string or the record result
187 187
      */
188
-    public function get($returnSQLQueryOrResultType = false){
188
+    public function get($returnSQLQueryOrResultType = false) {
189 189
       $this->getQueryBuilder()->limit(1);
190 190
       $query = $this->getAll(true);
191
-      if ($returnSQLQueryOrResultType === true){
191
+      if ($returnSQLQueryOrResultType === true) {
192 192
         return $query;
193 193
       } else {
194 194
         return $this->query($query, false, $returnSQLQueryOrResultType == 'array');
@@ -201,9 +201,9 @@  discard block
 block discarded – undo
201 201
      * If is string will determine the result type "array" or "object"
202 202
      * @return mixed       the query SQL string or the record result
203 203
      */
204
-    public function getAll($returnSQLQueryOrResultType = false){
204
+    public function getAll($returnSQLQueryOrResultType = false) {
205 205
 	   $query = $this->getQueryBuilder()->getQuery();
206
-	   if ($returnSQLQueryOrResultType === true){
206
+	   if ($returnSQLQueryOrResultType === true) {
207 207
       	return $query;
208 208
       }
209 209
       return $this->query($query, true, $returnSQLQueryOrResultType == 'array');
@@ -215,18 +215,18 @@  discard block
 block discarded – undo
215 215
      * @param  boolean $escape  whether to escape or not the values
216 216
      * @return mixed          the insert id of the new record or null
217 217
      */
218
-    public function insert($data = array(), $escape = true){
219
-      if (empty($data) && $this->getData()){
218
+    public function insert($data = array(), $escape = true) {
219
+      if (empty($data) && $this->getData()) {
220 220
         //as when using $this->setData() may be the data already escaped
221 221
         $escape = false;
222 222
         $data = $this->getData();
223 223
       }
224 224
       $query = $this->getQueryBuilder()->insert($data, $escape)->getQuery();
225 225
       $result = $this->query($query);
226
-      if ($result){
226
+      if ($result) {
227 227
         $this->insertId = $this->pdo->lastInsertId();
228 228
 		    //if the table doesn't have the auto increment field or sequence, the value of 0 will be returned 
229
-        return ! $this->insertId() ? true : $this->insertId();
229
+        return !$this->insertId() ? true : $this->insertId();
230 230
       }
231 231
       return false;
232 232
     }
@@ -237,8 +237,8 @@  discard block
 block discarded – undo
237 237
      * @param  boolean $escape  whether to escape or not the values
238 238
      * @return mixed          the update status
239 239
      */
240
-    public function update($data = array(), $escape = true){
241
-      if (empty($data) && $this->getData()){
240
+    public function update($data = array(), $escape = true) {
241
+      if (empty($data) && $this->getData()) {
242 242
         //as when using $this->setData() may be the data already escaped
243 243
         $escape = false;
244 244
         $data = $this->getData();
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
      * Delete the record in database
252 252
      * @return mixed the delete status
253 253
      */
254
-    public function delete(){
254
+    public function delete() {
255 255
 		$query = $this->getQueryBuilder()->delete()->getQuery();
256 256
     	return $this->query($query);
257 257
     }
@@ -261,8 +261,8 @@  discard block
 block discarded – undo
261 261
      * @param integer $ttl the cache time to live in second
262 262
      * @return object        the current Database instance
263 263
      */
264
-    public function setCache($ttl = 0){
265
-      if ($ttl > 0){
264
+    public function setCache($ttl = 0) {
265
+      if ($ttl > 0) {
266 266
         $this->cacheTtl = $ttl;
267 267
         $this->temporaryCacheTtl = $ttl;
268 268
       }
@@ -274,8 +274,8 @@  discard block
 block discarded – undo
274 274
 	 * @param  integer $ttl the cache time to live in second
275 275
 	 * @return object        the current Database instance
276 276
 	 */
277
-  	public function cached($ttl = 0){
278
-        if ($ttl > 0){
277
+  	public function cached($ttl = 0) {
278
+        if ($ttl > 0) {
279 279
           $this->temporaryCacheTtl = $ttl;
280 280
         }
281 281
         return $this;
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
      * @param boolean $escaped whether we can do escape of not 
288 288
      * @return mixed       the data after escaped or the same data if not
289 289
      */
290
-    public function escape($data, $escaped = true){
290
+    public function escape($data, $escaped = true) {
291 291
       return $escaped ? 
292 292
                       $this->pdo->quote(trim($data)) 
293 293
                       : $data; 
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
      * Return the number query executed count for the current request
298 298
      * @return int
299 299
      */
300
-    public function queryCount(){
300
+    public function queryCount() {
301 301
       return $this->queryCount;
302 302
     }
303 303
 
@@ -305,7 +305,7 @@  discard block
 block discarded – undo
305 305
      * Return the current query SQL string
306 306
      * @return string
307 307
      */
308
-    public function getQuery(){
308
+    public function getQuery() {
309 309
       return $this->query;
310 310
     }
311 311
 
@@ -313,7 +313,7 @@  discard block
 block discarded – undo
313 313
      * Return the application database name
314 314
      * @return string
315 315
      */
316
-    public function getDatabaseName(){
316
+    public function getDatabaseName() {
317 317
       return $this->databaseName;
318 318
     }
319 319
 
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
      * Return the PDO instance
322 322
      * @return object
323 323
      */
324
-    public function getPdo(){
324
+    public function getPdo() {
325 325
       return $this->pdo;
326 326
     }
327 327
 
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
      * @param object $pdo the pdo object
331 331
 	 * @return object Database
332 332
      */
333
-    public function setPdo(PDO $pdo){
333
+    public function setPdo(PDO $pdo) {
334 334
       $this->pdo = $pdo;
335 335
       return $this;
336 336
     }
@@ -340,7 +340,7 @@  discard block
 block discarded – undo
340 340
      * Return the Log instance
341 341
      * @return Log
342 342
      */
343
-    public function getLogger(){
343
+    public function getLogger() {
344 344
       return $this->logger;
345 345
     }
346 346
 
@@ -349,7 +349,7 @@  discard block
 block discarded – undo
349 349
      * @param Log $logger the log object
350 350
 	 * @return object Database
351 351
      */
352
-    public function setLogger($logger){
352
+    public function setLogger($logger) {
353 353
       $this->logger = $logger;
354 354
       return $this;
355 355
     }
@@ -358,7 +358,7 @@  discard block
 block discarded – undo
358 358
      * Return the cache instance
359 359
      * @return CacheInterface
360 360
      */
361
-    public function getCacheInstance(){
361
+    public function getCacheInstance() {
362 362
       return $this->cacheInstance;
363 363
     }
364 364
 
@@ -367,7 +367,7 @@  discard block
 block discarded – undo
367 367
      * @param CacheInterface $cache the cache object
368 368
 	 * @return object Database
369 369
      */
370
-    public function setCacheInstance($cache){
370
+    public function setCacheInstance($cache) {
371 371
       $this->cacheInstance = $cache;
372 372
       return $this;
373 373
     }
@@ -377,7 +377,7 @@  discard block
 block discarded – undo
377 377
      * Return the DatabaseQueryBuilder instance
378 378
      * @return object DatabaseQueryBuilder
379 379
      */
380
-    public function getQueryBuilder(){
380
+    public function getQueryBuilder() {
381 381
       return $this->queryBuilder;
382 382
     }
383 383
 
@@ -385,7 +385,7 @@  discard block
 block discarded – undo
385 385
      * Set the DatabaseQueryBuilder instance
386 386
      * @param object DatabaseQueryBuilder $queryBuilder the DatabaseQueryBuilder object
387 387
      */
388
-    public function setQueryBuilder(DatabaseQueryBuilder $queryBuilder){
388
+    public function setQueryBuilder(DatabaseQueryBuilder $queryBuilder) {
389 389
       $this->queryBuilder = $queryBuilder;
390 390
       return $this;
391 391
     }
@@ -394,7 +394,7 @@  discard block
 block discarded – undo
394 394
      * Return the DatabaseQueryRunner instance
395 395
      * @return object DatabaseQueryRunner
396 396
      */
397
-    public function getQueryRunner(){
397
+    public function getQueryRunner() {
398 398
       return $this->queryRunner;
399 399
     }
400 400
 
@@ -402,7 +402,7 @@  discard block
 block discarded – undo
402 402
      * Set the DatabaseQueryRunner instance
403 403
      * @param object DatabaseQueryRunner $queryRunner the DatabaseQueryRunner object
404 404
      */
405
-    public function setQueryRunner(DatabaseQueryRunner $queryRunner){
405
+    public function setQueryRunner(DatabaseQueryRunner $queryRunner) {
406 406
       $this->queryRunner = $queryRunner;
407 407
       return $this;
408 408
     }
@@ -411,7 +411,7 @@  discard block
 block discarded – undo
411 411
      * Return the data to be used for insert, update, etc.
412 412
      * @return array
413 413
      */
414
-    public function getData(){
414
+    public function getData() {
415 415
       return $this->data;
416 416
     }
417 417
 
@@ -422,9 +422,9 @@  discard block
 block discarded – undo
422 422
      * @param boolean $escape whether to escape or not the $value
423 423
      * @return object        the current Database instance
424 424
      */
425
-    public function setData($key, $value = null, $escape = true){
426
-  	  if(is_array($key)){
427
-    		foreach($key as $k => $v){
425
+    public function setData($key, $value = null, $escape = true) {
426
+  	  if (is_array($key)) {
427
+    		foreach ($key as $k => $v) {
428 428
     			$this->setData($k, $v, $escape);
429 429
     		}	
430 430
   	  } else {
@@ -440,7 +440,7 @@  discard block
 block discarded – undo
440 440
      * @param  boolean $returnAsArray return the result as array or not
441 441
      * @return mixed         the query result
442 442
      */
443
-    public function query($query, $returnAsList = true, $returnAsArray = false){
443
+    public function query($query, $returnAsList = true, $returnAsArray = false) {
444 444
       $this->reset();
445 445
       $this->query = preg_replace('/\s\s+|\t\t+/', ' ', trim($query));
446 446
       //If is the SELECT query
@@ -461,12 +461,12 @@  discard block
 block discarded – undo
461 461
       //if can use cache feature for this query
462 462
       $dbCacheStatus = $cacheEnable && $cacheExpire > 0;
463 463
     
464
-      if ($dbCacheStatus && $isSqlSELECTQuery){
464
+      if ($dbCacheStatus && $isSqlSELECTQuery) {
465 465
           $this->logger->info('The cache is enabled for this query, try to get result from cache'); 
466 466
           $cacheContent = $this->getCacheContentForQuery($query, $returnAsList, $returnAsArray);  
467 467
       }
468 468
       
469
-      if ( !$cacheContent){
469
+      if (!$cacheContent) {
470 470
   	   	//count the number of query execution to server
471 471
         $this->queryCount++;
472 472
         
@@ -475,19 +475,19 @@  discard block
 block discarded – undo
475 475
         $this->queryRunner->setReturnAsArray($returnAsArray);
476 476
         
477 477
         $queryResult = $this->queryRunner->execute();
478
-        if (is_object($queryResult)){
478
+        if (is_object($queryResult)) {
479 479
             $this->result  = $queryResult->getResult();
480 480
             $this->numRows = $queryResult->getNumRows();
481
-            if ($isSqlSELECTQuery && $dbCacheStatus){
481
+            if ($isSqlSELECTQuery && $dbCacheStatus) {
482 482
                 $key = $this->getCacheKeyForQuery($this->query, $returnAsList, $returnAsArray);
483 483
                 $this->setCacheContentForQuery($this->query, $key, $this->result, $cacheExpire);
484
-            if (! $this->result){
484
+            if (!$this->result) {
485 485
               $this->logger->info('No result where found for the query [' . $query . ']');
486 486
             }
487 487
           }
488 488
         }
489
-      } else if ($isSqlSELECTQuery){
490
-          $this->logger->info('The result for query [' .$this->query. '] already cached use it');
489
+      } else if ($isSqlSELECTQuery) {
490
+          $this->logger->info('The result for query [' . $this->query . '] already cached use it');
491 491
           $this->result = $cacheContent;
492 492
           $this->numRows = count($this->result);
493 493
       }
@@ -499,7 +499,7 @@  discard block
 block discarded – undo
499 499
 	 * Return the database configuration
500 500
 	 * @return array
501 501
 	 */
502
-  	public  function getDatabaseConfiguration(){
502
+  	public  function getDatabaseConfiguration() {
503 503
   	  return $this->config;
504 504
   	}
505 505
 
@@ -509,9 +509,9 @@  discard block
 block discarded – undo
509 509
     * @param boolean $useConfigFile whether to use database configuration file
510 510
 	  * @return object Database
511 511
     */
512
-    public function setDatabaseConfiguration(array $overwriteConfig = array(), $useConfigFile = true){
512
+    public function setDatabaseConfiguration(array $overwriteConfig = array(), $useConfigFile = true) {
513 513
         $db = array();
514
-        if ($useConfigFile && file_exists(CONFIG_PATH . 'database.php')){
514
+        if ($useConfigFile && file_exists(CONFIG_PATH . 'database.php')) {
515 515
             //here don't use require_once because somewhere user can create database instance directly
516 516
             require CONFIG_PATH . 'database.php';
517 517
         }
@@ -536,7 +536,7 @@  discard block
 block discarded – undo
536 536
     	//determine the port using the hostname like localhost:3307
537 537
       //hostname will be "localhost", and port "3307"
538 538
       $p = explode(':', $config['hostname']);
539
-  	  if (count($p) >= 2){
539
+  	  if (count($p) >= 2) {
540 540
   		  $config['hostname'] = $p[0];
541 541
   		  $config['port'] = $p[1];
542 542
   		}
@@ -563,7 +563,7 @@  discard block
 block discarded – undo
563 563
     /**
564 564
      * Close the connexion
565 565
      */
566
-    public function close(){
566
+    public function close() {
567 567
       $this->pdo = null;
568 568
     }
569 569
 
@@ -571,16 +571,16 @@  discard block
 block discarded – undo
571 571
      * Update the DatabaseQueryBuilder and DatabaseQueryRunner properties
572 572
      * @return void
573 573
      */
574
-    protected function updateQueryBuilderAndRunnerProperties(){
574
+    protected function updateQueryBuilderAndRunnerProperties() {
575 575
        //update queryBuilder with some properties needed
576
-     if(is_object($this->queryBuilder)){
576
+     if (is_object($this->queryBuilder)) {
577 577
         $this->queryBuilder->setDriver($this->config['driver']);
578 578
         $this->queryBuilder->setPrefix($this->config['prefix']);
579 579
         $this->queryBuilder->setPdo($this->pdo);
580 580
      }
581 581
 
582 582
       //update queryRunner with some properties needed
583
-     if(is_object($this->queryRunner)){
583
+     if (is_object($this->queryRunner)) {
584 584
         $this->queryRunner->setDriver($this->config['driver']);
585 585
         $this->queryRunner->setPdo($this->pdo);
586 586
      }
@@ -591,9 +591,9 @@  discard block
 block discarded – undo
591 591
      * This method is used to get the PDO DSN string using the configured driver
592 592
      * @return string the DSN string
593 593
      */
594
-    protected function getDsnFromDriver(){
594
+    protected function getDsnFromDriver() {
595 595
       $config = $this->getDatabaseConfiguration();
596
-      if (! empty($config)){
596
+      if (!empty($config)) {
597 597
         $driver = $config['driver'];
598 598
         $driverDsnMap = array(
599 599
                               'mysql' => 'mysql:host=' . $config['hostname'] . ';' 
@@ -618,9 +618,9 @@  discard block
 block discarded – undo
618 618
      *      
619 619
      * @return mixed
620 620
      */
621
-    protected function getCacheContentForQuery($query, $returnAsList, $returnAsArray){
621
+    protected function getCacheContentForQuery($query, $returnAsList, $returnAsArray) {
622 622
         $cacheKey = $this->getCacheKeyForQuery($query, $returnAsList, $returnAsArray);
623
-        if (! is_object($this->cacheInstance)){
623
+        if (!is_object($this->cacheInstance)) {
624 624
     			//can not call method with reference in argument
625 625
     			//like $this->setCacheInstance(& get_instance()->cache);
626 626
     			//use temporary variable
@@ -637,9 +637,9 @@  discard block
 block discarded – undo
637 637
      * @param mixed $result the query result to save
638 638
      * @param int $expire the cache TTL
639 639
      */
640
-     protected function setCacheContentForQuery($query, $key, $result, $expire){
641
-        $this->logger->info('Save the result for query [' .$query. '] into cache for future use');
642
-        if (! is_object($this->cacheInstance)){
640
+     protected function setCacheContentForQuery($query, $key, $result, $expire) {
641
+        $this->logger->info('Save the result for query [' . $query . '] into cache for future use');
642
+        if (!is_object($this->cacheInstance)) {
643 643
   				//can not call method with reference in argument
644 644
   				//like $this->setCacheInstance(& get_instance()->cache);
645 645
   				//use temporary variable
@@ -656,7 +656,7 @@  discard block
 block discarded – undo
656 656
      * 
657 657
      *  @return string
658 658
      */
659
-    protected function getCacheKeyForQuery($query, $returnAsList, $returnAsArray){
659
+    protected function getCacheKeyForQuery($query, $returnAsList, $returnAsArray) {
660 660
       return md5($query . $returnAsList . $returnAsArray);
661 661
     }
662 662
     
@@ -664,12 +664,12 @@  discard block
 block discarded – undo
664 664
      * Set the Log instance using argument or create new instance
665 665
      * @param object $logger the Log instance if not null
666 666
      */
667
-    protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){
668
-      if ($logger !== null){
667
+    protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null) {
668
+      if ($logger !== null) {
669 669
         $this->logger = $logger;
670 670
       }
671
-      else{
672
-          $this->logger =& class_loader('Log', 'classes');
671
+      else {
672
+          $this->logger = & class_loader('Log', 'classes');
673 673
           $this->logger->setLogger('Library::Database');
674 674
       }
675 675
     }
@@ -678,12 +678,12 @@  discard block
 block discarded – undo
678 678
    * Set the DatabaseQueryBuilder instance using argument or create new instance
679 679
    * @param object $queryBuilder the DatabaseQueryBuilder instance if not null
680 680
    */
681
-	protected function setQueryBuilderFromParamOrCreateNewInstance(DatabaseQueryBuilder $queryBuilder = null){
682
-	  if ($queryBuilder !== null){
681
+	protected function setQueryBuilderFromParamOrCreateNewInstance(DatabaseQueryBuilder $queryBuilder = null) {
682
+	  if ($queryBuilder !== null) {
683 683
         $this->queryBuilder = $queryBuilder;
684 684
 	  }
685
-	  else{
686
-		  $this->queryBuilder =& class_loader('DatabaseQueryBuilder', 'classes/database');
685
+	  else {
686
+		  $this->queryBuilder = & class_loader('DatabaseQueryBuilder', 'classes/database');
687 687
 	  }
688 688
 	}
689 689
 
@@ -691,19 +691,19 @@  discard block
 block discarded – undo
691 691
    * Set the DatabaseQueryRunner instance using argument or create new instance
692 692
    * @param object $queryRunner the DatabaseQueryRunner instance if not null
693 693
    */
694
-  protected function setQueryRunnerFromParamOrCreateNewInstance(DatabaseQueryRunner $queryRunner = null){
695
-    if ($queryRunner !== null){
694
+  protected function setQueryRunnerFromParamOrCreateNewInstance(DatabaseQueryRunner $queryRunner = null) {
695
+    if ($queryRunner !== null) {
696 696
         $this->queryRunner = $queryRunner;
697 697
     }
698
-    else{
699
-      $this->queryRunner =& class_loader('DatabaseQueryRunner', 'classes/database');
698
+    else {
699
+      $this->queryRunner = & class_loader('DatabaseQueryRunner', 'classes/database');
700 700
     }
701 701
   }
702 702
 
703 703
     /**
704 704
      * Reset the database class attributs to the initail values before each query.
705 705
      */
706
-    private function reset(){
706
+    private function reset() {
707 707
 	   //query builder reset
708 708
       $this->getQueryBuilder()->reset();
709 709
       $this->numRows  = 0;
@@ -716,7 +716,7 @@  discard block
 block discarded – undo
716 716
     /**
717 717
      * The class destructor
718 718
      */
719
-    public function __destruct(){
719
+    public function __destruct() {
720 720
       $this->pdo = null;
721 721
     }
722 722
 
Please login to merge, or discard this patch.
core/classes/Url.php 1 patch
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -25,15 +25,15 @@  discard block
 block discarded – undo
25 25
 	*/
26 26
 
27 27
 
28
-	class Url{
28
+	class Url {
29 29
 
30 30
 		/**
31 31
 		 * Return the link using base_url config without front controller "index.php"
32 32
 		 * @param  string $path the link path or full URL
33 33
 		 * @return string the full link URL
34 34
 		 */
35
-		public static function base_url($path = ''){
36
-			if(is_url($path)){
35
+		public static function base_url($path = '') {
36
+			if (is_url($path)) {
37 37
 				return $path;
38 38
 			}
39 39
 			return get_config('base_url') . $path;
@@ -44,26 +44,26 @@  discard block
 block discarded – undo
44 44
 		 * @param  string $path the link path or full URL
45 45
 		 * @return string the full link URL
46 46
 		 */
47
-		public static function site_url($path = ''){
48
-			if(is_url($path)){
47
+		public static function site_url($path = '') {
48
+			if (is_url($path)) {
49 49
 				return $path;
50 50
 			}
51 51
 			$path = rtrim($path, '/');
52 52
 			$baseUrl = get_config('base_url');
53 53
 			$frontController = get_config('front_controller');
54 54
 			$url = $baseUrl;
55
-			if($frontController){
55
+			if ($frontController) {
56 56
 				$url .= $frontController . '/';
57 57
 			}
58
-			if(($suffix = get_config('url_suffix')) && $path){
59
-				if(strpos($path, '?') !== false){
58
+			if (($suffix = get_config('url_suffix')) && $path) {
59
+				if (strpos($path, '?') !== false) {
60 60
 					$query = explode('?', $path);
61 61
 					$query[0] = str_ireplace($suffix, '', $query[0]);
62 62
 					$query[0] = rtrim($query[0], '/');
63 63
 					$query[0] .= $suffix;
64 64
 					$path = implode('?', $query);
65 65
 				}
66
-				else{
66
+				else {
67 67
 					$path .= $suffix;
68 68
 				}
69 69
 			}
@@ -74,10 +74,10 @@  discard block
 block discarded – undo
74 74
 		 * Return the current site URL
75 75
 		 * @return string
76 76
 		 */
77
-		public static function current(){
77
+		public static function current() {
78 78
 			$current = '/';
79 79
 			$requestUri = get_instance()->request->requestUri();
80
-			if($requestUri){
80
+			if ($requestUri) {
81 81
 				$current = $requestUri;
82 82
 			}
83 83
 			return static::domain() . $current;
@@ -90,18 +90,18 @@  discard block
 block discarded – undo
90 90
 		 * @param  boolean $lowercase whether to set the final text to lowe case or not
91 91
 		 * @return string the friendly generated text
92 92
 		 */
93
-		public static function title($str = null, $separator = '-', $lowercase = true){
93
+		public static function title($str = null, $separator = '-', $lowercase = true) {
94 94
 			$str = trim($str);
95
-			$from = array('ç','À','Á','Â','Ã','Ä','Å','à','á','â','ã','ä','å','Ò','Ó','Ô','Õ','Ö','Ø','ò','ó','ô','õ','ö','ø','È','É','Ê','Ë','è','é','ê','ë','Ç','ç','Ì','Í','Î','Ï','ì','í','î','ï','Ù','Ú','Û','Ü','ù','ú','û','ü','ÿ','Ñ','ñ');
96
-			$to = array('c','a','a','a','a','a','a','a','a','a','a','a','a','o','o','o','o','o','o','o','o','o','o','o','o','e','e','e','e','e','e','e','e','e','e','i','i','i','i','i','i','i','i','u','u','u','u','u','u','u','u','y','n','n');
95
+			$from = array('ç', 'À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'à', 'á', 'â', 'ã', 'ä', 'å', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'È', 'É', 'Ê', 'Ë', 'è', 'é', 'ê', 'ë', 'Ç', 'ç', 'Ì', 'Í', 'Î', 'Ï', 'ì', 'í', 'î', 'ï', 'Ù', 'Ú', 'Û', 'Ü', 'ù', 'ú', 'û', 'ü', 'ÿ', 'Ñ', 'ñ');
96
+			$to = array('c', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'i', 'i', 'i', 'i', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'y', 'n', 'n');
97 97
 			$str = str_replace($from, $to, $str);
98 98
 			$str = preg_replace('#([^a-z0-9]+)#i', $separator, $str);
99 99
 			$str = str_replace('--', $separator, $str);
100 100
 			//if after process we get something like one-two-three-, need truncate the last separator "-"
101
-			if(substr($str, -1) == $separator){
101
+			if (substr($str, -1) == $separator) {
102 102
 				$str = substr($str, 0, -1);
103 103
 			}
104
-			if($lowercase){
104
+			if ($lowercase) {
105 105
 				$str = strtolower($str);
106 106
 			}
107 107
 			return $str;
@@ -111,12 +111,12 @@  discard block
 block discarded – undo
111 111
 		 * Get the current application domain with protocol
112 112
 		 * @return string the domain name
113 113
 		 */
114
-		public static function domain(){
114
+		public static function domain() {
115 115
 			$obj = & get_instance();
116 116
 			$domain = 'localhost';
117 117
 			$port = $obj->request->server('SERVER_PORT');
118 118
 			$protocol = 'http';
119
-			if(is_https()){
119
+			if (is_https()) {
120 120
 				$protocol = 'https';
121 121
 			}
122 122
 
@@ -128,27 +128,27 @@  discard block
 block discarded – undo
128 128
 
129 129
 			foreach ($domainserverVars as $var) {
130 130
 				$value = $obj->request->server($var);
131
-				if($value){
131
+				if ($value) {
132 132
 					$domain = $value;
133 133
 					break;
134 134
 				}
135 135
 			}
136 136
 			
137
-			if($port && ((is_https() && $port != 443) || (!is_https() && $port != 80))){
137
+			if ($port && ((is_https() && $port != 443) || (!is_https() && $port != 80))) {
138 138
 				//some server use SSL but the port doesn't equal 443 sometime is 80 if is the case put the port at this end
139 139
 				//of the domain like https://my.domain.com:787
140
-				if(is_https() && $port != 80){
141
-					$domain .= ':'.$port;
140
+				if (is_https() && $port != 80) {
141
+					$domain .= ':' . $port;
142 142
 				}
143 143
 			}
144
-			return $protocol.'://'.$domain;
144
+			return $protocol . '://' . $domain;
145 145
 		}
146 146
 
147 147
 		/**
148 148
 		 * Get the current request query string
149 149
 		 * @return string
150 150
 		 */
151
-		public static function queryString(){
151
+		public static function queryString() {
152 152
 			return get_instance()->request->server('QUERY_STRING');
153 153
 		}
154 154
 	}
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,12 +65,12 @@  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 72
 			self::setBaseUrlUsingServerVar();
73
-			if(ENVIRONMENT == 'production' && in_array(strtolower(self::$config['log_level']), array('debug', 'info','all'))){
73
+			if (ENVIRONMENT == 'production' && in_array(strtolower(self::$config['log_level']), array('debug', 'info', 'all'))) {
74 74
 				$logger->warning('You are in production environment, please set log level to WARNING, ERROR, FATAL to increase the application performance');
75 75
 			}
76 76
 			$logger->info('Configuration initialized successfully');
@@ -83,12 +83,12 @@  discard block
 block discarded – undo
83 83
 		 * @param  mixed $default the default value to use if can not find the config item in the list
84 84
 		 * @return mixed          the config value if exist or the default value
85 85
 		 */
86
-		public static function get($item, $default = null){
86
+		public static function get($item, $default = null) {
87 87
 			$logger = static::getLogger();
88
-			if(array_key_exists($item, self::$config)){
88
+			if (array_key_exists($item, self::$config)) {
89 89
 				return self::$config[$item];
90 90
 			}
91
-			$logger->warning('Cannot find config item ['.$item.'] using the default value ['.$default.']');
91
+			$logger->warning('Cannot find config item [' . $item . '] using the default value [' . $default . ']');
92 92
 			return $default;
93 93
 		}
94 94
 
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 		 * @param string $item  the config item name to set
98 98
 		 * @param mixed $value the config item value
99 99
 		 */
100
-		public static function set($item, $value){
100
+		public static function set($item, $value) {
101 101
 			self::$config[$item] = $value;
102 102
 		}
103 103
 
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 		 * Get all the configuration values
106 106
 		 * @return array the config values
107 107
 		 */
108
-		public static function getAll(){
108
+		public static function getAll() {
109 109
 			return self::$config;
110 110
 		}
111 111
 
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 		 * Set the configuration values bu merged with the existing configuration
114 114
 		 * @param array $config the config values to add in the configuration list
115 115
 		 */
116
-		public static function setAll(array $config = array()){
116
+		public static function setAll(array $config = array()) {
117 117
 			self::$config = array_merge(self::$config, $config);
118 118
 		}
119 119
 
@@ -122,15 +122,15 @@  discard block
 block discarded – undo
122 122
 		 * @param  string $item the config item name to be deleted
123 123
 		 * @return boolean true if the item exists and is deleted successfully otherwise will return false.
124 124
 		 */
125
-		public static function delete($item){
125
+		public static function delete($item) {
126 126
 			$logger = static::getLogger();
127
-			if(array_key_exists($item, self::$config)){
128
-				$logger->info('Delete config item ['.$item.']');
127
+			if (array_key_exists($item, self::$config)) {
128
+				$logger->info('Delete config item [' . $item . ']');
129 129
 				unset(self::$config[$item]);
130 130
 				return true;
131 131
 			}
132
-			else{
133
-				$logger->warning('Config item ['.$item.'] to be deleted does not exists');
132
+			else {
133
+				$logger->warning('Config item [' . $item . '] to be deleted does not exists');
134 134
 				return false;
135 135
 			}
136 136
 		}
@@ -139,40 +139,40 @@  discard block
 block discarded – undo
139 139
 		 * Load the configuration file. This an alias to Loader::config()
140 140
 		 * @param  string $config the config name to be loaded
141 141
 		 */
142
-		public static function load($config){
142
+		public static function load($config) {
143 143
 			Loader::config($config);
144 144
 		}
145 145
 
146 146
 		/**
147 147
 		 * Set the configuration for "base_url" if is not set in the configuration
148 148
 		 */
149
-		private static function setBaseUrlUsingServerVar(){
149
+		private static function setBaseUrlUsingServerVar() {
150 150
 			$logger = static::getLogger();
151
-			if (! isset(self::$config['base_url']) || ! is_url(self::$config['base_url'])){
152
-				if(ENVIRONMENT == 'production'){
151
+			if (!isset(self::$config['base_url']) || !is_url(self::$config['base_url'])) {
152
+				if (ENVIRONMENT == 'production') {
153 153
 					$logger->warning('Application base URL is not set or invalid, please set application base URL to increase the application loading time');
154 154
 				}
155 155
 				$baseUrl = null;
156
-				if (isset($_SERVER['SERVER_ADDR'])){
156
+				if (isset($_SERVER['SERVER_ADDR'])) {
157 157
 					$baseUrl = $_SERVER['SERVER_ADDR'];
158 158
 					//check if the server is running under IPv6
159
-					if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE){
160
-						$baseUrl = '['.$_SERVER['SERVER_ADDR'].']';
159
+					if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE) {
160
+						$baseUrl = '[' . $_SERVER['SERVER_ADDR'] . ']';
161 161
 					}
162 162
 					$serverPort = 80;
163 163
 					if (isset($_SERVER['SERVER_PORT'])) {
164 164
 						$serverPort = $_SERVER['SERVER_PORT'];
165 165
 					}
166
-					$port = ((($serverPort != '80' && ! is_https()) || ($serverPort != '443' && is_https())) ? ':' . $serverPort : '');
167
-					$baseUrl = (is_https() ? 'https' : 'http').'://' . $baseUrl . $port
166
+					$port = ((($serverPort != '80' && !is_https()) || ($serverPort != '443' && is_https())) ? ':' . $serverPort : '');
167
+					$baseUrl = (is_https() ? 'https' : 'http') . '://' . $baseUrl . $port
168 168
 						. substr($_SERVER['SCRIPT_NAME'], 0, strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME'])));
169 169
 				}
170
-				else{
170
+				else {
171 171
 					$logger->warning('Can not determine the application base URL automatically, use http://localhost as default');
172 172
 					$baseUrl = 'http://localhost/';
173 173
 				}
174 174
 				self::set('base_url', $baseUrl);
175 175
 			}
176
-			self::$config['base_url'] = rtrim(self::$config['base_url'], '/') .'/';
176
+			self::$config['base_url'] = rtrim(self::$config['base_url'], '/') . '/';
177 177
 		}
178 178
 	}
Please login to merge, or discard this patch.
core/functions/function_user_agent.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 	 */
42 42
 	
43 43
 	 
44
-	if(! function_exists('get_ip')){
44
+	if (!function_exists('get_ip')) {
45 45
 		/**
46 46
 		 *  Retrieves the user's IP address
47 47
 		 *  
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 		 *  
51 51
 		 *  @return string the IP address.
52 52
 		 */
53
-		function get_ip(){
53
+		function get_ip() {
54 54
 			$ip = '127.0.0.1';
55 55
 			$ipServerVars = array(
56 56
 								'REMOTE_ADDR',
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 								'HTTP_FORWARDED'
62 62
 							);
63 63
 			foreach ($ipServerVars as $var) {
64
-				if(isset($_SERVER[$var])){
64
+				if (isset($_SERVER[$var])) {
65 65
 					$ip = $_SERVER[$var];
66 66
 					break;
67 67
 				}
Please login to merge, or discard this patch.
core/libraries/Assets.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 	 *  @since 1.0.0
39 39
 	 *  @filesource
40 40
 	 */
41
-	class Assets{
41
+	class Assets {
42 42
 		
43 43
 		/**
44 44
 		 * The logger instance
@@ -50,10 +50,10 @@  discard block
 block discarded – undo
50 50
 		 * The signleton of the logger
51 51
 		 * @return Object the Log instance
52 52
 		 */
53
-		private static function getLogger(){
54
-			if(self::$logger == null){
53
+		private static function getLogger() {
54
+			if (self::$logger == null) {
55 55
 				//can't assign reference to static variable
56
-				self::$logger[0] =& class_loader('Log', 'classes');
56
+				self::$logger[0] = & class_loader('Log', 'classes');
57 57
 				self::$logger[0]->setLogger('Library::Assets');
58 58
 			}
59 59
 			return self::$logger[0];
@@ -72,13 +72,13 @@  discard block
 block discarded – undo
72 72
 		 *  @param string $asset the name of the assets file path with the extension.
73 73
 		 *  @return string|null the absolute path of the assets file, if it exists otherwise returns null if the file does not exist.
74 74
 		 */
75
-		public static function path($asset){
75
+		public static function path($asset) {
76 76
 			$logger = self::getLogger();	
77 77
 			$path = ASSETS_PATH . $asset;
78 78
 			
79 79
 			$logger->debug('Including the Assets file [' . $path . ']');
80 80
 			//Check if the file exists
81
-			if(file_exists($path)){
81
+			if (file_exists($path)) {
82 82
 				$logger->info('Assets file [' . $path . '] included successfully');
83 83
 				return Url::base_url($path);
84 84
 			}
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 		 *  @param string $path the name of the css file without the extension.
99 99
 		 *  @return string|null the absolute path of the css file, if it exists otherwise returns null if the file does not exist.
100 100
 		 */
101
-		public static function css($path){
101
+		public static function css($path) {
102 102
 			$logger = self::getLogger();
103 103
 			/*
104 104
 			* if the file name contains the ".css" extension, replace it with 
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 			
110 110
 			$logger->debug('Including the Assets file [' . $path . '] for CSS');
111 111
 			//Check if the file exists
112
-			if(file_exists($path)){
112
+			if (file_exists($path)) {
113 113
 				$logger->info('Assets file [' . $path . '] for CSS included successfully');
114 114
 				return Url::base_url($path);
115 115
 			}
@@ -129,12 +129,12 @@  discard block
 block discarded – undo
129 129
 		 *  @param string $path the name of the javascript file without the extension.
130 130
 		 *  @return string|null the absolute path of the javascript file, if it exists otherwise returns null if the file does not exist.
131 131
 		 */
132
-		public static function js($path){
132
+		public static function js($path) {
133 133
 			$logger = self::getLogger();
134 134
 			$path = str_ireplace('.js', '', $path);
135 135
 			$path = ASSETS_PATH . 'js/' . $path . '.js';
136 136
 			$logger->debug('Including the Assets file [' . $path . '] for javascript');
137
-			if(file_exists($path)){
137
+			if (file_exists($path)) {
138 138
 				$logger->info('Assets file [' . $path . '] for Javascript included successfully');
139 139
 				return Url::base_url($path);
140 140
 			}
@@ -154,11 +154,11 @@  discard block
 block discarded – undo
154 154
 		 *  @param string $path the name of the image file with the extension.
155 155
 		 *  @return string|null the absolute path of the image file, if it exists otherwise returns null if the file does not exist.
156 156
 		 */
157
-		public static function img($path){
157
+		public static function img($path) {
158 158
 			$logger = self::getLogger();
159 159
 			$path = ASSETS_PATH . 'images/' . $path;
160 160
 			$logger->debug('Including the Assets file [' . $path . '] for image');
161
-			if(file_exists($path)){
161
+			if (file_exists($path)) {
162 162
 				$logger->info('Assets file [' . $path . '] for image included successfully');
163 163
 				return Url::base_url($path);
164 164
 			}
Please login to merge, or discard this patch.