Passed
Pull Request — 1.0.0-dev (#2)
by
unknown
02:37
created
core/classes/database/DatabaseQueryBuilder.php 1 patch
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -215,17 +215,17 @@  discard block
 block discarded – undo
215 215
      * @param  string $type   the type of join (INNER, LEFT, RIGHT)
216 216
      * @return object        the current DatabaseQueryBuilder instance
217 217
      */
218
-    public function join($table, $field1 = null, $op = null, $field2 = null, $type = ''){
218
+    public function join($table, $field1 = null, $op = null, $field2 = null, $type = '') {
219 219
         $on = $field1;
220 220
         $table = $this->getPrefix() . $table;
221
-        if (! is_null($op)){
222
-        $on = (! in_array($op, $this->operatorList) 
221
+        if (!is_null($op)) {
222
+        $on = (!in_array($op, $this->operatorList) 
223 223
                                                     ? ($this->getPrefix() . $field1 . ' = ' . $this->getPrefix() . $op) 
224 224
                                                     : ($this->getPrefix() . $field1 . ' ' . $op . ' ' . $this->getPrefix() . $field2));
225 225
         }
226
-        if (empty($this->join)){
226
+        if (empty($this->join)) {
227 227
         $this->join = ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on;
228
-        } else{
228
+        } else {
229 229
         $this->join = $this->join . ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on;
230 230
         }
231 231
         return $this;
@@ -329,12 +329,12 @@  discard block
 block discarded – undo
329 329
      * @param  boolean $escape whether to escape or not the $val
330 330
      * @return object        the current DatabaseQueryBuilder instance
331 331
      */
332
-    public function where($where, $op = null, $val = null, $type = '', $andOr = 'AND', $escape = true){
332
+    public function where($where, $op = null, $val = null, $type = '', $andOr = 'AND', $escape = true) {
333 333
         $whereStr = '';
334
-        if (is_array($where)){
334
+        if (is_array($where)) {
335 335
         $whereStr = $this->getWhereStrIfIsArray($where, $type, $andOr, $escape);
336
-        } else{
337
-        if (is_array($op)){
336
+        } else {
337
+        if (is_array($op)) {
338 338
             $whereStr = $this->getWhereStrIfOperatorIsArray($where, $op, $type, $escape);
339 339
         } else {
340 340
             $whereStr = $this->getWhereStrForOperator($where, $op, $val, $type, $escape);
@@ -577,13 +577,13 @@  discard block
 block discarded – undo
577 577
      * @param  int $limitEnd the limit count
578 578
      * @return object        the current DatabaseQueryBuilder instance
579 579
      */
580
-    public function limit($limit, $limitEnd = null){
581
-        if (empty($limit)){
580
+    public function limit($limit, $limitEnd = null) {
581
+        if (empty($limit)) {
582 582
         $limit = 0;
583 583
         }
584
-        if (! is_null($limitEnd)){
584
+        if (!is_null($limitEnd)) {
585 585
         $this->limit = $limit . ', ' . $limitEnd;
586
-        } else{
586
+        } else {
587 587
         $this->limit = $limit;
588 588
         }
589 589
         return $this;
@@ -595,10 +595,10 @@  discard block
 block discarded – undo
595 595
      * @param  string $orderDir the order direction (ASC or DESC)
596 596
      * @return object        the current DatabaseQueryBuilder instance
597 597
      */
598
-    public function orderBy($orderBy, $orderDir = ' ASC'){
599
-        if (stristr($orderBy, ' ') || $orderBy == 'rand()'){
598
+    public function orderBy($orderBy, $orderDir = ' ASC') {
599
+        if (stristr($orderBy, ' ') || $orderBy == 'rand()') {
600 600
         $this->orderBy = empty($this->orderBy) ? $orderBy : $this->orderBy . ', ' . $orderBy;
601
-        } else{
601
+        } else {
602 602
         $this->orderBy = empty($this->orderBy) 
603 603
                         ? ($orderBy . ' ' . strtoupper($orderDir)) 
604 604
                         : $this->orderBy . ', ' . $orderBy . ' ' . strtoupper($orderDir);
@@ -611,10 +611,10 @@  discard block
 block discarded – undo
611 611
      * @param  string|array $field the field name used or array of field list
612 612
      * @return object        the current DatabaseQueryBuilder instance
613 613
      */
614
-    public function groupBy($field){
615
-        if (is_array($field)){
614
+    public function groupBy($field) {
615
+        if (is_array($field)) {
616 616
         $this->groupBy = implode(', ', $field);
617
-        } else{
617
+        } else {
618 618
         $this->groupBy = $field;
619 619
         }
620 620
         return $this;
@@ -628,16 +628,16 @@  discard block
 block discarded – undo
628 628
      * @param  boolean $escape whether to escape or not the values
629 629
      * @return object        the current DatabaseQueryBuilder instance
630 630
      */
631
-    public function having($field, $op = null, $val = null, $escape = true){
632
-        if (is_array($op)){
631
+    public function having($field, $op = null, $val = null, $escape = true) {
632
+        if (is_array($op)) {
633 633
         $this->having = $this->getHavingStrIfOperatorIsArray($field, $op, $escape);
634
-        } else if (! in_array($op, $this->operatorList)){
635
-        if (is_null($op)){
634
+        } else if (!in_array($op, $this->operatorList)) {
635
+        if (is_null($op)) {
636 636
             $op = '';
637 637
         }
638 638
         $this->having = $field . ' > ' . ($this->escape($op, $escape));
639
-        } else{
640
-        if (is_null($val)){
639
+        } else {
640
+        if (is_null($val)) {
641 641
             $val = '';
642 642
         }
643 643
         $this->having = $field . ' ' . $op . ' ' . ($this->escape($val, $escape));
Please login to merge, or discard this patch.
core/classes/database/Database.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
             $this->updateQueryBuilderAndRunnerProperties();
150 150
 
151 151
             return is_object($this->pdo);
152
-            } catch (PDOException $e){
152
+            } catch (PDOException $e) {
153 153
             $this->logger->fatal($e->getMessage());
154 154
             show_error('Cannot connect to Database.');
155 155
             return false;
@@ -596,17 +596,17 @@  discard block
 block discarded – undo
596 596
      * @param  string $driver the driver name
597 597
      * @return string|null         the dsn name
598 598
      */
599
-    protected function getDsnValueForDriver($driver){
599
+    protected function getDsnValueForDriver($driver) {
600 600
         $dsn = '';
601 601
         $config = $this->getDatabaseConfiguration();
602
-        if (empty($config)){
602
+        if (empty($config)) {
603 603
         return null;
604 604
         }
605 605
         switch ($driver) {
606 606
             case 'mysql':
607 607
             case 'pgsql':
608 608
               $port = '';
609
-                if (! empty($config['port'])) {
609
+                if (!empty($config['port'])) {
610 610
                 $port = 'port=' . $config['port'] . ';';
611 611
                 }
612 612
                 $dsn = $driver . ':host=' . $config['hostname'] . ';' . $port . 'dbname=' . $config['database'];
Please login to merge, or discard this patch.
core/classes/database/DatabaseQueryRunner.php 1 patch
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -130,18 +130,18 @@  discard block
 block discarded – undo
130 130
                                                                 'DATABASE_QUERY_END(' . $benchmarkMarkerKey . ')'
131 131
                                                                 );
132 132
             //TODO use the configuration value for the high response time currently is 1 second
133
-        if ($responseTime >= 1 ){
133
+        if ($responseTime >= 1) {
134 134
             $this->logger->warning(
135 135
                                     'High response time while processing database query [' . $this->query . ']. 
136
-                                     The response time is [' .$responseTime. '] sec.'
136
+                                     The response time is [' .$responseTime . '] sec.'
137 137
                                     );
138 138
         }
139 139
 		
140
-        if ($this->pdoStatment !== false){
140
+        if ($this->pdoStatment !== false) {
141 141
             $isSqlSELECTQuery = stristr($this->query, 'SELECT') !== false;
142
-            if($isSqlSELECTQuery){
142
+            if ($isSqlSELECTQuery) {
143 143
                 $this->setResultForSelect();              
144
-            } else{
144
+            } else {
145 145
                 $this->setResultForNonSelect();
146 146
             }
147 147
             return $this->queryResult;
@@ -153,26 +153,26 @@  discard block
 block discarded – undo
153 153
      * Return the result for SELECT query
154 154
      * @see DatabaseQueryRunner::execute
155 155
      */
156
-    protected function setResultForSelect(){
156
+    protected function setResultForSelect() {
157 157
         //if need return all result like list of record
158 158
         $result = null;
159 159
         $numRows = 0;
160 160
         $fetchMode = PDO::FETCH_OBJ;
161
-        if($this->returnAsArray){
161
+        if ($this->returnAsArray) {
162 162
         $fetchMode = PDO::FETCH_ASSOC;
163 163
         }
164
-        if ($this->returnAsList){
164
+        if ($this->returnAsList) {
165 165
             $result = $this->pdoStatment->fetchAll($fetchMode);
166
-        } else{
166
+        } else {
167 167
             $result = $this->pdoStatment->fetch($fetchMode);
168 168
         }
169 169
         //Sqlite and pgsql always return 0 when using rowCount()
170
-        if (in_array($this->driver, array('sqlite', 'pgsql'))){
170
+        if (in_array($this->driver, array('sqlite', 'pgsql'))) {
171 171
         $numRows = count($result);  
172
-        } else{
172
+        } else {
173 173
         $numRows = $this->pdoStatment->rowCount(); 
174 174
         }
175
-        if(! is_object($this->queryResult)){
175
+        if (!is_object($this->queryResult)) {
176 176
             $this->queryResult = & class_loader('DatabaseQueryResult', 'classes/database');
177 177
         }
178 178
         $this->queryResult->setResult($result);
@@ -183,19 +183,19 @@  discard block
 block discarded – undo
183 183
      * Return the result for non SELECT query
184 184
      * @see DatabaseQueryRunner::execute
185 185
      */
186
-    protected function setResultForNonSelect(){
186
+    protected function setResultForNonSelect() {
187 187
         //Sqlite and pgsql always return 0 when using rowCount()
188 188
         $result = false;
189 189
         $numRows = 0;
190
-        if (in_array($this->driver, array('sqlite', 'pgsql'))){
190
+        if (in_array($this->driver, array('sqlite', 'pgsql'))) {
191 191
         $result = true; //to test the result for the query like UPDATE, INSERT, DELETE
192 192
         $numRows = 1; //TODO use the correct method to get the exact affected row
193
-        } else{
193
+        } else {
194 194
             //to test the result for the query like UPDATE, INSERT, DELETE
195 195
             $result  = $this->pdoStatment->rowCount() >= 0; 
196 196
             $numRows = $this->pdoStatment->rowCount(); 
197 197
         }
198
-        if(! is_object($this->queryResult)){
198
+        if (!is_object($this->queryResult)) {
199 199
             $this->queryResult = & class_loader('DatabaseQueryResult', 'classes/database');
200 200
         }
201 201
         $this->queryResult->setResult($result);
@@ -347,11 +347,11 @@  discard block
 block discarded – undo
347 347
      * Set the Log instance using argument or create new instance
348 348
      * @param object $logger the Log instance if not null
349 349
      */
350
-    protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){
351
-        if ($logger !== null){
350
+    protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null) {
351
+        if ($logger !== null) {
352 352
         $this->logger = $logger;
353
-        } else{
354
-            $this->logger =& class_loader('Log', 'classes');
353
+        } else {
354
+            $this->logger = & class_loader('Log', 'classes');
355 355
             $this->logger->setLogger('Library::DatabaseQueryRunner');
356 356
         }
357 357
     }
Please login to merge, or discard this patch.
core/classes/Request.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -90,20 +90,20 @@
 block discarded – undo
90 90
         /**
91 91
          * Construct new request instance
92 92
          */
93
-        public function __construct(){
93
+        public function __construct() {
94 94
             $this->get = $_GET;
95 95
             $this->post = $_POST;
96 96
             $this->server = $_SERVER;
97 97
             $this->query = $_REQUEST;
98 98
             $this->cookie = $_COOKIE;
99 99
             $this->file = $_FILES;
100
-            $this->session =& class_loader('Session', 'classes');
100
+            $this->session = & class_loader('Session', 'classes');
101 101
             $this->method = $this->server('REQUEST_METHOD');
102 102
             $this->requestUri = $this->server('REQUEST_URI');
103 103
             $this->header = array();
104
-            if(function_exists('apache_request_headers')){
104
+            if (function_exists('apache_request_headers')) {
105 105
                 $this->header = apache_request_headers();
106
-            } else if(function_exists('getallheaders')){
106
+            } else if (function_exists('getallheaders')) {
107 107
                 $this->header = getallheaders();
108 108
             }
109 109
         }
Please login to merge, or discard this patch.
core/classes/Security.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -38,13 +38,13 @@  discard block
 block discarded – undo
38 38
             $expire = get_config('csrf_expire', 60);
39 39
             $keyExpire = 'csrf_expire';
40 40
             $currentTime = time();
41
-            if(Session::exists($key) && Session::exists($keyExpire) && Session::get($keyExpire) > $currentTime){
41
+            if (Session::exists($key) && Session::exists($keyExpire) && Session::get($keyExpire) > $currentTime) {
42 42
                 $logger->info('The CSRF token not yet expire just return it');
43 43
                 return Session::get($key);
44
-            } else{
44
+            } else {
45 45
                 $newTime = $currentTime + $expire;
46 46
                 $token = sha1(uniqid()) . sha1(uniqid());
47
-                $logger->info('The CSRF informations are listed below: key [' .$key. '], key expire [' .$keyExpire. '], expire time [' .$expire. '], token [' .$token. ']');
47
+                $logger->info('The CSRF informations are listed below: key [' . $key . '], key expire [' . $keyExpire . '], expire time [' . $expire . '], token [' . $token . ']');
48 48
                 Session::set($keyExpire, $newTime);
49 49
                 Session::set($key, $token);
50 50
                 return Session::get($key);
@@ -87,23 +87,23 @@  discard block
 block discarded – undo
87 87
         /**
88 88
          * This method is used to check the whitelist IP address access
89 89
          */
90
-            public static function checkWhiteListIpAccess(){
90
+            public static function checkWhiteListIpAccess() {
91 91
             $logger = self::getLogger();
92 92
             $logger->debug('Validation of the IP address access ...');
93 93
             $logger->debug('Check if whitelist IP access is enabled in the configuration ...');
94 94
             $isEnable = get_config('white_list_ip_enable', false);
95
-            if($isEnable){
95
+            if ($isEnable) {
96 96
                 $logger->info('Whitelist IP access is enabled in the configuration');
97 97
                 $list = get_config('white_list_ip_addresses', array());
98
-                if(! empty($list)){
98
+                if (!empty($list)) {
99 99
                     //Can't use Loader::functions() at this time because teh "Loader" library is loader after the security prossessing
100 100
                     require_once CORE_FUNCTIONS_PATH . 'function_user_agent.php';
101 101
                     $ip = get_ip();
102
-                    if((count($list) == 1 && $list[0] == '*') || in_array($ip, $list)){
102
+                    if ((count($list) == 1 && $list[0] == '*') || in_array($ip, $list)) {
103 103
                         $logger->info('IP address ' . $ip . ' allowed using the wildcard "*" or the full IP');
104 104
                         //wildcard to access all ip address
105 105
                         return;
106
-                    } else{
106
+                    } else {
107 107
                         // go through all whitelisted ips
108 108
                         foreach ($list as $ipaddr) {
109 109
                             // find the wild card * in whitelisted ip (f.e. find position in "127.0.*" or "127*")
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
                         show_error('Access to this application is not allowed');
129 129
                     }
130 130
                 }
131
-            } else{
131
+            } else {
132 132
                 $logger->info('Whitelist IP access is not enabled in the configuration, ignore checking');
133 133
             }
134 134
             }
Please login to merge, or discard this patch.
core/bootstrap.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -86,9 +86,9 @@  discard block
 block discarded – undo
86 86
     /**
87 87
      * Verification of the PHP environment: minimum and maximum version
88 88
      */
89
-    if (version_compare(phpversion(), TNH_REQUIRED_PHP_MIN_VERSION, '<')){
89
+    if (version_compare(phpversion(), TNH_REQUIRED_PHP_MIN_VERSION, '<')) {
90 90
         show_error('Your PHP Version [' . phpversion() . '] is less than [' . TNH_REQUIRED_PHP_MIN_VERSION . '], please install a new version or update your PHP to the latest.', 'PHP Error environment');	
91
-    } else if(version_compare(phpversion(), TNH_REQUIRED_PHP_MAX_VERSION, '>')){
91
+    } else if (version_compare(phpversion(), TNH_REQUIRED_PHP_MAX_VERSION, '>')) {
92 92
         show_error('Your PHP Version [' . phpversion() . '] is greather than [' . TNH_REQUIRED_PHP_MAX_VERSION . '] please install a PHP version that is compatible.', 'PHP Error environment');	
93 93
     }
94 94
     $LOGGER->info('PHP version [' . phpversion() . '] is OK [REQUIRED MINIMUM: ' . TNH_REQUIRED_PHP_MIN_VERSION . ', REQUIRED MAXIMUM: ' . TNH_REQUIRED_PHP_MAX_VERSION . '], application can work without any issue');
@@ -110,10 +110,10 @@  discard block
 block discarded – undo
110 110
 	
111 111
     //if user have some composer packages
112 112
     $LOGGER->debug('Check for composer autoload');
113
-    if(file_exists(VENDOR_PATH . 'autoload.php')){
113
+    if (file_exists(VENDOR_PATH . 'autoload.php')) {
114 114
         $LOGGER->info('The composer autoload file exists include it');
115 115
         require_once VENDOR_PATH . 'autoload.php';
116
-    } else{
116
+    } else {
117 117
         $LOGGER->info('The composer autoload file does not exist skipping');
118 118
     }
119 119
 	
@@ -158,35 +158,35 @@  discard block
 block discarded – undo
158 158
     /**
159 159
      * Loading Security class
160 160
      */
161
-    $SECURITY =& class_loader('Security', 'classes');
161
+    $SECURITY = & class_loader('Security', 'classes');
162 162
     $SECURITY->checkWhiteListIpAccess();
163 163
 	
164 164
     /**
165 165
      * Loading Url class
166 166
      */
167
-    $URL =& class_loader('Url', 'classes');
167
+    $URL = & class_loader('Url', 'classes');
168 168
 	
169
-    if(get_config('cache_enable', false)){
169
+    if (get_config('cache_enable', false)) {
170 170
         /**
171 171
          * Load Cache interface file
172 172
          */
173 173
         require_once CORE_CLASSES_CACHE_PATH . 'CacheInterface.php';
174 174
         $cacheHandler = get_config('cache_handler');
175
-        if(! $cacheHandler){
175
+        if (!$cacheHandler) {
176 176
             show_error('The cache feature is enabled in the configuration but the cache handler class is not set.');
177 177
         }
178 178
         $CACHE = null;
179 179
         //first check if the cache handler is the system driver
180
-        if(file_exists(CORE_CLASSES_CACHE_PATH . $cacheHandler . '.php')){
181
-            $CACHE =& class_loader($cacheHandler, 'classes/cache');
182
-        } else{
180
+        if (file_exists(CORE_CLASSES_CACHE_PATH . $cacheHandler . '.php')) {
181
+            $CACHE = & class_loader($cacheHandler, 'classes/cache');
182
+        } else {
183 183
             //it's not a system driver use user library
184
-            $CACHE =& class_loader($cacheHandler);
184
+            $CACHE = & class_loader($cacheHandler);
185 185
         }
186 186
         //check if the page already cached
187
-        if(! empty($_SERVER['REQUEST_METHOD']) && strtolower($_SERVER['REQUEST_METHOD']) == 'get'){
187
+        if (!empty($_SERVER['REQUEST_METHOD']) && strtolower($_SERVER['REQUEST_METHOD']) == 'get') {
188 188
             $RESPONSE = & class_loader('Response', 'classes');
189
-            if ($RESPONSE->renderFinalPageFromCache($CACHE)){
189
+            if ($RESPONSE->renderFinalPageFromCache($CACHE)) {
190 190
                 return;
191 191
             }
192 192
         }
Please login to merge, or discard this patch.