Merge pull request #666 from samsonasik/count-improve

count() usage improvement: replace with empty() when possible, assign to variable on loop
This commit is contained in:
Lonnie Ezell 2017-08-07 22:58:39 -05:00 committed by GitHub
commit 6765c6e27c
18 changed files with 49 additions and 50 deletions

View File

@ -258,7 +258,7 @@ class FileLocator
$tempFiles = get_filenames($fullPath, true);
//CLI::newLine($tempFiles);
if (count($tempFiles))
if (! empty($tempFiles))
$files = array_merge($files, $tempFiles);
}

View File

@ -744,7 +744,7 @@ class CLI
*/
public static function getOptionString(): string
{
if ( ! count(static::$options))
if (empty(static::$options))
{
return '';
}

View File

@ -134,8 +134,8 @@ class ListCommands extends BaseCommand
// Pad each item to the same length
$names = $this->padArray($names, 2, 2);
for ($i = 0; $i < count($names); $i ++ )
$countNames = count($names);
for ($i = 0; $i < $countNames; $i ++ )
{
$lastGroup = $this->describeGroup($groups[$i], $lastGroup);

View File

@ -777,7 +777,7 @@ if ( ! function_exists('redirect_with_input'))
// so they can be displayed when the validation is
// handled within a method different than displaying the form.
$validator = Services::validation();
if (count($validator->getErrors()) > 0)
if (! empty($validator->getErrors()))
{
$session->setFlashdata('_ci_validation_errors', serialize($validator->getErrors()));
}

View File

@ -216,7 +216,7 @@ class BaseBuilder
$this->from($tableName);
if (count($options))
if (! empty($options))
{
foreach ($options as $key => $value)
{
@ -628,7 +628,7 @@ class BaseBuilder
foreach ($key as $k => $v)
{
$prefix = (count($this->$qb_key) === 0) ? $this->groupGetType('') : $this->groupGetType($type);
$prefix = empty($this->$qb_key) ? $this->groupGetType('') : $this->groupGetType($type);
if ($v !== null)
{
@ -784,7 +784,7 @@ class BaseBuilder
$where_in = array_values($values);
$this->binds[$ok] = $where_in;
$prefix = (count($this->QBWhere) === 0) ? $this->groupGetType('') : $this->groupGetType($type);
$prefix = empty($this->QBWhere) ? $this->groupGetType('') : $this->groupGetType($type);
$where_in = [
'condition' => $prefix . $key . $not . ' IN :' . $ok,
@ -914,7 +914,7 @@ class BaseBuilder
foreach ($field as $k => $v)
{
$prefix = (count($this->QBWhere) === 0) ? $this->groupGetType('') : $this->groupGetType($type);
$prefix = empty($this->QBWhere) ? $this->groupGetType('') : $this->groupGetType($type);
if ($insensitiveSearch === true)
{
@ -992,7 +992,7 @@ class BaseBuilder
$type = $this->groupGetType($type);
$this->QBWhereGroupStarted = true;
$prefix = count($this->QBWhere) === 0 ? '' : $type;
$prefix = empty($this->QBWhere) ? '' : $type;
$where = [
'condition' => $prefix . $not . str_repeat(' ', ++ $this->QBWhereGroupCount) . ' (',
'escape' => false,
@ -1385,7 +1385,7 @@ class BaseBuilder
}
$query = $this->db->query($sql);
if (count($query->getResult()) === 0)
if (empty($query->getResult()))
{
return 0;
}
@ -1715,7 +1715,7 @@ class BaseBuilder
*/
protected function validateInsert()
{
if (count($this->QBSet) === 0)
if (empty($this->QBSet))
{
if (CI_DEBUG)
{
@ -1766,7 +1766,7 @@ class BaseBuilder
$this->set($set);
}
if (count($this->QBSet) === 0)
if (empty($this->QBSet))
{
if (CI_DEBUG)
{
@ -1936,7 +1936,7 @@ class BaseBuilder
*/
protected function validateUpdate()
{
if (count($this->QBSet) === 0)
if (empty($this->QBSet))
{
if (CI_DEBUG)
{
@ -2241,7 +2241,7 @@ class BaseBuilder
$this->where($where);
}
if (count($this->QBWhere) === 0)
if (empty($this->QBWhere))
{
if (CI_DEBUG)
{
@ -2396,7 +2396,7 @@ class BaseBuilder
{
$sql = ( ! $this->QBDistinct) ? 'SELECT ' : 'SELECT DISTINCT ';
if (count($this->QBSelect) === 0)
if (empty($this->QBSelect))
{
$sql .= '*';
}
@ -2416,13 +2416,13 @@ class BaseBuilder
}
// Write the "FROM" portion of the query
if (count($this->QBFrom) > 0)
if (! empty($this->QBFrom))
{
$sql .= "\nFROM " . $this->_fromTables();
}
// Write the "JOIN" portion of the query
if (count($this->QBJoin) > 0)
if (! empty($this->QBJoin))
{
$sql .= "\n" . implode("\n", $this->QBJoin);
}
@ -2457,7 +2457,7 @@ class BaseBuilder
*/
protected function compileWhereHaving($qb_key)
{
if (count($this->$qb_key) > 0)
if (! empty($this->$qb_key))
{
for ($i = 0, $c = count($this->$qb_key); $i < $c; $i ++ )
{
@ -2530,7 +2530,7 @@ class BaseBuilder
*/
protected function compileGroupBy()
{
if (count($this->QBGroupBy) > 0)
if (! empty($this->QBGroupBy))
{
for ($i = 0, $c = count($this->QBGroupBy); $i < $c; $i ++ )
{
@ -2565,7 +2565,7 @@ class BaseBuilder
*/
protected function compileOrderBy()
{
if (is_array($this->QBOrderBy) && count($this->QBOrderBy) > 0)
if (is_array($this->QBOrderBy) && ! empty($this->QBOrderBy))
{
for ($i = 0, $c = count($this->QBOrderBy); $i < $c; $i ++ )
{

View File

@ -205,7 +205,7 @@ abstract class BaseResult implements ResultInterface
*/
public function getResultArray(): array
{
if (count($this->resultArray) > 0)
if (! empty($this->resultArray))
{
return $this->resultArray;
}
@ -248,7 +248,7 @@ abstract class BaseResult implements ResultInterface
*/
public function getResultObject(): array
{
if (count($this->resultObject) > 0)
if (! empty($this->resultObject))
{
return $this->resultObject;
}
@ -339,7 +339,7 @@ abstract class BaseResult implements ResultInterface
{
isset($this->customResultObject[$className]) OR $this->customResultObject($className);
if (count($this->customResultObject[$className]) === 0)
if (empty($this->customResultObject[$className]))
{
return null;
}
@ -366,7 +366,7 @@ abstract class BaseResult implements ResultInterface
public function getRowArray($n = 0)
{
$result = $this->getResultArray();
if (count($result) === 0)
if (empty($result))
{
return null;
}
@ -393,7 +393,7 @@ abstract class BaseResult implements ResultInterface
public function getRowObject($n = 0)
{
$result = $this->getResultObject();
if (count($result) === 0)
if (empty($result))
{
return null;
}
@ -453,7 +453,7 @@ abstract class BaseResult implements ResultInterface
{
$result = $this->getResult($type);
return (count($result) === 0) ? null : $result[0];
return (empty($result)) ? null : $result[0];
}
//--------------------------------------------------------------------
@ -469,7 +469,7 @@ abstract class BaseResult implements ResultInterface
{
$result = $this->getResult($type);
return (count($result) === 0) ? null : $result[count($result) - 1];
return (empty($result)) ? null : $result[count($result) - 1];
}
//--------------------------------------------------------------------
@ -484,7 +484,7 @@ abstract class BaseResult implements ResultInterface
public function getNextRow($type = 'object')
{
$result = $this->getResult($type);
if (count($result) === 0)
if (empty($result))
{
return null;
}
@ -504,7 +504,7 @@ abstract class BaseResult implements ResultInterface
public function getPreviousRow($type = 'object')
{
$result = $this->getResult($type);
if (count($result) === 0)
if (empty($result))
{
return null;
}

View File

@ -349,7 +349,7 @@ abstract class BaseUtils
];
// Did the user submit any preferences? If so set them....
if (count($params) > 0)
if (! empty($params))
{
foreach ($prefs as $key => $val)
{
@ -362,7 +362,7 @@ abstract class BaseUtils
// Are we backing up a complete database or individual tables?
// If no table names were submitted we'll fetch the entire table list
if (count($prefs['tables']) === 0)
if (empty($prefs['tables']))
{
$prefs['tables'] = $this->db->listTables();
}

View File

@ -116,7 +116,7 @@
</a>
<?php if (isset($_SESSION)) : ?>
<?php if (count($_SESSION)) : ?>
<?php if (! empty($_SESSION)) : ?>
<table id="session_table">
<tbody>
<?php foreach ($_SESSION as $key => $value) : ?>

View File

@ -507,7 +507,7 @@ class ContentSecurityPolicy
*/
public function setSandbox(bool $value = true, array $flags = null)
{
if (empty($this->sandbox) && ! count($flags))
if (empty($this->sandbox) && empty($flags))
{
$this->sandbox = $value;
}
@ -704,7 +704,7 @@ class ContentSecurityPolicy
// Compile our own header strings here since if we just
// append it to the response, it will be joined with
// commas, not semi-colons as we need.
if (count($this->tempHeaders))
if (! empty($this->tempHeaders))
{
$header = '';
foreach ($this->tempHeaders as $name => $value)
@ -714,7 +714,7 @@ class ContentSecurityPolicy
$response->appendHeader('Content-Security-Policy', $header);
}
if (count($this->reportOnlyHeaders))
if (! empty($this->reportOnlyHeaders))
{
$header = '';
foreach ($this->reportOnlyHeaders as $name => $value)
@ -782,12 +782,12 @@ class ContentSecurityPolicy
}
}
if (count($sources))
if (! empty($sources))
{
$this->tempHeaders[$name] = implode(' ', $sources);
}
if (count($reportSources))
if (! empty($reportSources))
{
$this->reportOnlyHeaders[$name] = implode(' ', $reportSources);
}

View File

@ -284,7 +284,7 @@ class FileCollection
*/
protected function getValueDotNotationSyntax($index, $value)
{
if (is_array($index) && count($index)
if (is_array($index) && ! empty($index)
)
{
$current_index = array_shift($index);

View File

@ -962,7 +962,7 @@ if ( ! function_exists('parse_form_attributes'))
unset($attributes[$key]);
}
}
if (count($attributes) > 0)
if (! empty($attributes))
{
$default = array_merge($default, $attributes);
}
@ -988,4 +988,3 @@ if ( ! function_exists('parse_form_attributes'))
//--------------------------------------------------------------------
}

View File

@ -165,7 +165,7 @@ if ( ! function_exists('ascii_to_entities'))
}
else
{
if (count($temp) === 0)
if (empty($temp))
{
$count = ($ordinal < 224) ? 2 : 3;
}
@ -510,7 +510,7 @@ if ( ! function_exists('word_wrap'))
}
// Put our markers back
if (count($unwrap) > 0)
if (! empty($unwrap))
{
foreach ($unwrap as $key => $val)
{

View File

@ -438,7 +438,7 @@ if ( ! function_exists('safe_mailto'))
}
else
{
if (count($temp) === 0)
if (empty($temp))
{
$count = ($ordinal < 224) ? 2 : 3;
}

View File

@ -102,7 +102,7 @@ class Language
$output = isset($this->language[$file][$line]) ? $this->language[$file][$line] : $line;
if (count($args))
if (! empty($args))
{
$output = $this->formatMessage($output, $args);
}

View File

@ -274,7 +274,7 @@ class Rules
return true;
}
return is_array($str) ? (bool) count($str) : (trim($str) !== '');
return is_array($str) ? ! empty($str) : (trim($str) !== '');
}
//--------------------------------------------------------------------
@ -326,7 +326,7 @@ class Rules
return ! empty($data[$item]);
});
return ! (bool) count($requiredFields);
return empty($requiredFields);
}
//--------------------------------------------------------------------

View File

@ -144,7 +144,7 @@ class Validation implements ValidationInterface
$this->processRules($rField, $data[$rField] ?? null, $rules, $data);
}
return count($this->errors) > 0 ? false : true;
return ! empty($this->errors) ? false : true;
}
//--------------------------------------------------------------------

View File

@ -1,4 +1,4 @@
<?php if (count($errors) > 0) : ?>
<?php if (! empty($errors)) : ?>
<div class="alert alert-danger" role="alert">
<ul>
<?php foreach ($errors as $error) : ?>

View File

@ -213,7 +213,7 @@ class Cell
unset($new_params);
}
if (is_array($params) && ! count($params))
if (is_array($params) && empty($params))
{
return [];
}