Skip to content

Commit 0ddb710

Browse files
committed
Optimize Code
1 parent 58f63f6 commit 0ddb710

File tree

4 files changed

+21
-23
lines changed

4 files changed

+21
-23
lines changed

hungng/HungNG_CI_Base_Controllers.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ protected function errorExceptionResponse($exception)
104104
(ENVIRONMENT === 'development' || ENVIRONMENT === 'staging' || ENVIRONMENT === 'testing')
105105
)
106106
||
107-
in_array(getIPAddress(), config_item('whitelist_ip'))
107+
in_array(getIPAddress(), config_item('whitelist_ip'), true)
108108
) {
109109
$response['error'] = array(
110110
'Code' => $exception->getCode(),
@@ -188,7 +188,7 @@ protected function errorSignatureResponse($validSignature = array())
188188
$response = array();
189189
$response['code'] = StatusCodes::HTTP_FORBIDDEN;
190190
$response['message'] = StatusCodes::$statusTexts[StatusCodes::HTTP_FORBIDDEN];
191-
if ((defined('_PROCESS_TEST_') && _PROCESS_TEST_ === true) || in_array(getIPAddress(), config_item('whitelist_ip'))) {
191+
if ((defined('_PROCESS_TEST_') && _PROCESS_TEST_ === true) || in_array(getIPAddress(), config_item('whitelist_ip'), true)) {
192192
$response['validSignature'] = $validSignature;
193193
}
194194

hungng/HungNG_CI_Base_Module.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ protected function errorExceptionResponse($exception)
104104
(ENVIRONMENT === 'development' || ENVIRONMENT === 'staging' || ENVIRONMENT === 'testing')
105105
)
106106
||
107-
in_array(getIPAddress(), config_item('whitelist_ip'))
107+
in_array(getIPAddress(), config_item('whitelist_ip'), true)
108108
) {
109109
$response['error'] = array(
110110
'Code' => $exception->getCode(),
@@ -188,7 +188,7 @@ protected function errorSignatureResponse($validSignature = array())
188188
$response = array();
189189
$response['code'] = StatusCodes::HTTP_FORBIDDEN;
190190
$response['message'] = StatusCodes::$statusTexts[StatusCodes::HTTP_FORBIDDEN];
191-
if ((defined('_PROCESS_TEST_') && _PROCESS_TEST_ === true) || in_array(getIPAddress(), config_item('whitelist_ip'))) {
191+
if ((defined('_PROCESS_TEST_') && _PROCESS_TEST_ === true) || in_array(getIPAddress(), config_item('whitelist_ip'), true)) {
192192
$response['validSignature'] = $validSignature;
193193
}
194194

hungng/HungNG_Custom_Based_model.php

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ public function close()
145145
*/
146146
public function page_limit($size = 500, $page = 0)
147147
{
148-
if ($size != 'no_limit') {
149-
if ($page != 0) {
148+
if ($size !== 'no_limit') {
149+
if ($page !== 0) {
150150
if (!$page || $page <= 0 || empty($page)) {
151151
$page = 1;
152152
}
@@ -338,7 +338,7 @@ public function get_data_simple_result($selectField = '*', $wheres = [], $size =
338338
}
339339
}
340340
// Limit Result
341-
self::_page_limit($size, $page);
341+
$this->_page_limit($size, $page);
342342
// Order Result
343343
foreach ($orderBy as $key => $val) {
344344
$this->db->order_by($this->tableName . '.' . $key, $val);
@@ -369,9 +369,9 @@ public function get_info($value = '', $field = null, $array = false)
369369
}
370370
if ($array === true) {
371371
return $this->db->get()->row_array();
372-
} else {
373-
return $this->db->get()->row();
374372
}
373+
374+
return $this->db->get()->row();
375375
}
376376

377377
/**
@@ -402,12 +402,12 @@ public function get_value($value_input = '', $field_input = null, $field_output
402402
if (null !== $field_output) {
403403
if (null === $query->row()) {
404404
return null;
405-
} else {
406-
return $query->row()->$field_output;
407405
}
408-
} else {
409-
return $query->row();
406+
407+
return $query->row()->$field_output;
410408
}
409+
410+
return $query->row();
411411
}
412412

413413
/**
@@ -497,16 +497,14 @@ public function request_builder($search)
497497
{
498498
if (!empty($search)) {
499499
foreach ($search as $field => $value) {
500-
if ($this->db->field_exists($field, $this->tableName)) {
501-
if (!empty($value)) {
502-
if (is_array($value)) {
503-
$this->db->where_in($this->tableName . '.' . $field, $value);
504-
} else {
505-
$this->db->like($this->tableName . '.' . $field, $value);
506-
}
500+
if (!empty($value) && $this->db->field_exists($field, $this->tableName)) {
501+
if (is_array($value)) {
502+
$this->db->where_in($this->tableName . '.' . $field, $value);
503+
} else {
504+
$this->db->like($this->tableName . '.' . $field, $value);
507505
}
508506
}
509-
if ($field == 'sort') {
507+
if ($field === 'sort') {
510508
$sort = (strpos($value, '-') === false) ? 'DESC' : 'ASC';
511509
$column = (strpos($value, '-') === false) ? $value : substr($value, 1);
512510
if ($this->db->field_exists($column, $this->tableName)) {
@@ -522,7 +520,7 @@ public function request_builder($search)
522520
*/
523521
public function __destruct()
524522
{
525-
if ($this->db != '') {
523+
if ($this->db) {
526524
$this->close();
527525
}
528526
}

hungng/HungNG_Lang.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public function load($langfile, $idiom = '', $return = false, $add_suffix = true
104104
$langfile = preg_replace('/_lang$/', '', $langfile) . '_lang';
105105
}
106106
$langfile .= '.php';
107-
if (empty($idiom) or !preg_match('/^[a-z_-]+$/i', $idiom)) {
107+
if (empty($idiom) || !preg_match('/^[a-z_-]+$/i', $idiom)) {
108108
$config =& get_config();
109109
$idiom = empty($config['language']) ? $this->base_language : $config['language'];
110110
}

0 commit comments

Comments
 (0)