Skip to content

Commit

Permalink
Merge pull request #2748 from samsonasik/clean-up-dead-code
Browse files Browse the repository at this point in the history
clean up dead code detected by  rectorphp/rector
  • Loading branch information
lonnieezell authored Mar 28, 2020
2 parents 93f1a65 + 4d284d9 commit 1dc6216
Show file tree
Hide file tree
Showing 62 changed files with 147 additions and 273 deletions.
10 changes: 5 additions & 5 deletions app/Views/errors/html/error_exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
<?php if (empty($GLOBALS[$var]) || ! is_array($GLOBALS[$var]))
{
continue;
} ?>
} ?>

<h3>$<?= $var ?></h3>

Expand Down Expand Up @@ -235,7 +235,7 @@
<?php if (empty($GLOBALS[$var]) || ! is_array($GLOBALS[$var]))
{
continue;
} ?>
} ?>

<?php $empty = false; ?>

Expand Down Expand Up @@ -287,15 +287,15 @@
</tr>
</thead>
<tbody>
<?php foreach ($headers as $name => $value) : ?>
<?php foreach ($headers as $value) : ?>
<?php if (empty($value))
{
continue;
} ?>
} ?>
<?php if (! is_array($value))
{
$value = [$value];
} ?>
} ?>
<?php foreach ($value as $h) : ?>
<tr>
<td><?= esc($h->getName(), 'html') ?></td>
Expand Down
19 changes: 3 additions & 16 deletions system/CLI/CLI.php
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ public static function newLine(int $num = 1)
// Do it once or more, write with empty string gives us a new line
for ($i = 0; $i < $num; $i ++)
{
static::write('');
static::write();
}
}

Expand Down Expand Up @@ -504,9 +504,7 @@ public static function color(string $text, string $foreground, string $backgroun
$string .= "\033[4m";
}

$string .= $text . "\033[0m";

return $string;
return $string . ($text . "\033[0m");
}

//--------------------------------------------------------------------
Expand Down Expand Up @@ -702,24 +700,17 @@ public static function wrap(string $string = null, int $max = 0, int $pad_left =
*/
protected static function parseCommandLine()
{
$optionsFound = false;

// start picking segments off from #1, ignoring the invoking program
for ($i = 1; $i < $_SERVER['argc']; $i ++)
{
// If there's no '-' at the beginning of the argument
// then add it to our segments.
if (! $optionsFound && mb_strpos($_SERVER['argv'][$i], '-') === false)
if (mb_strpos($_SERVER['argv'][$i], '-') === false)
{
static::$segments[] = $_SERVER['argv'][$i];
continue;
}

// We set $optionsFound here so that we know to
// skip the next argument since it's likely the
// value belonging to this option.
$optionsFound = true;

$arg = str_replace('-', '', $_SERVER['argv'][$i]);
$value = null;

Expand All @@ -731,10 +722,6 @@ protected static function parseCommandLine()
}

static::$options[$arg] = $value;

// Reset $optionsFound so it can collect segments
// past any options.
$optionsFound = false;
}
}

Expand Down
2 changes: 1 addition & 1 deletion system/Cache/Handlers/FileHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public function delete(string $key)
{
$key = $this->prefix . $key;

return is_file($this->path . $key) ? unlink($this->path . $key) : false;
return is_file($this->path . $key) && unlink($this->path . $key);
}

//--------------------------------------------------------------------
Expand Down
4 changes: 1 addition & 3 deletions system/CodeIgniter.php
Original file line number Diff line number Diff line change
Expand Up @@ -749,9 +749,7 @@ public function displayPerformanceMetrics(string $output): string
{
$this->totalTime = $this->benchmark->getElapsedTime('total_execution');

$output = str_replace('{elapsed_time}', $this->totalTime, $output);

return $output;
return str_replace('{elapsed_time}', $this->totalTime, $output);
}

//--------------------------------------------------------------------
Expand Down
3 changes: 1 addition & 2 deletions system/Commands/ListCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,8 @@ protected function padTitle(string $item, int $max, int $extra = 2, int $indent
$max += $extra + $indent;

$item = str_repeat(' ', $indent) . $item;
$item = str_pad($item, $max);

return $item;
return str_pad($item, $max);
}

//--------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion system/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ function esc($data, string $context = 'html', string $encoding = null)
{
if (is_array($data))
{
foreach ($data as $key => &$value)
foreach ($data as &$value)
{
$value = esc($value, $context);
}
Expand Down
4 changes: 0 additions & 4 deletions system/Config/BaseConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,12 @@ protected function getEnvValue(string $property, string $prefix, string $shortPr
{
case array_key_exists("{$shortPrefix}.{$property}", $_ENV):
return $_ENV["{$shortPrefix}.{$property}"];
break;
case array_key_exists("{$shortPrefix}.{$property}", $_SERVER):
return $_SERVER["{$shortPrefix}.{$property}"];
break;
case array_key_exists("{$prefix}.{$property}", $_ENV):
return $_ENV["{$prefix}.{$property}"];
break;
case array_key_exists("{$prefix}.{$property}", $_SERVER):
return $_SERVER["{$prefix}.{$property}"];
break;
default:
$value = getenv($property);
return $value === false ? null : $value;
Expand Down
4 changes: 1 addition & 3 deletions system/Config/DotEnv.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public function parse(): ?array
if (strpos($line, '=') !== false)
{
list($name, $value) = $this->normaliseVariable($line);
$vars[$name] = $value;
$vars[$name] = $value;
}
}

Expand Down Expand Up @@ -314,10 +314,8 @@ protected function getVariable(string $name)
{
case array_key_exists($name, $_ENV):
return $_ENV[$name];
break;
case array_key_exists($name, $_SERVER):
return $_SERVER[$name];
break;
default:
$value = getenv($name);

Expand Down
14 changes: 6 additions & 8 deletions system/Config/Services.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,7 @@ public static function email($config = null, bool $getShared = true)
{
$config = new \Config\Email();
}
$email = new \CodeIgniter\Email\Email($config);
return $email;
return new \CodeIgniter\Email\Email($config);
}

/**
Expand All @@ -232,8 +231,7 @@ public static function encrypter($config = null, $getShared = false)
}

$encryption = new Encryption($config);
$encrypter = $encryption->initialize($config);
return $encrypter;
return $encryption->initialize($config);
}

//--------------------------------------------------------------------
Expand Down Expand Up @@ -542,7 +540,7 @@ public static function parser(string $viewPath = null, $config = null, bool $get
$viewPath = $paths->viewDirectory;
}

return new Parser($config, $viewPath, static::locator(true), CI_DEBUG, static::logger(true));
return new Parser($config, $viewPath, static::locator(), CI_DEBUG, static::logger());
}

//--------------------------------------------------------------------
Expand Down Expand Up @@ -577,7 +575,7 @@ public static function renderer(string $viewPath = null, $config = null, bool $g
$viewPath = $paths->viewDirectory;
}

return new \CodeIgniter\View\View($config, $viewPath, static::locator(true), CI_DEBUG, static::logger(true));
return new \CodeIgniter\View\View($config, $viewPath, static::locator(), CI_DEBUG, static::logger());
}

//--------------------------------------------------------------------
Expand Down Expand Up @@ -705,7 +703,7 @@ public static function router(RouteCollectionInterface $routes = null, Request $

if (empty($routes))
{
$routes = static::routes(true);
$routes = static::routes();
}

return new Router($routes, $request);
Expand Down Expand Up @@ -759,7 +757,7 @@ public static function session(App $config = null, bool $getShared = true)
$config = config(App::class);
}

$logger = static::logger(true);
$logger = static::logger();

$driverName = $config->sessionDriver;
$driver = new $driverName($config, static::request()->getIpAddress());
Expand Down
4 changes: 1 addition & 3 deletions system/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,10 @@ protected function validate($rules, array $messages = []): bool
$rules = $validation->$rules;
}

$success = $this->validator
return $this->validator
->withRequest($this->request)
->setRules($rules, $messages)
->run();

return $success;
}

//--------------------------------------------------------------------
Expand Down
36 changes: 18 additions & 18 deletions system/Database/BaseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ public function select($select = '*', bool $escape = null)
*/
public function selectMax(string $select = '', string $alias = '')
{
return $this->maxMinAvgSum($select, $alias, 'MAX');
return $this->maxMinAvgSum($select, $alias);
}

//--------------------------------------------------------------------
Expand Down Expand Up @@ -981,12 +981,12 @@ public function orHavingNotIn(string $key = null, $values = null, bool $escape =
* @used-by whereNotIn()
* @used-by orWhereNotIn()
*
* @param string $key The field to search
* @param array|Closure $values The values searched on, or anonymous function with subquery
* @param boolean $not If the statement would be IN or NOT IN
* @param string $type
* @param boolean $escape
* @param string $clause (Internal use only)
* @param string $key The field to search
* @param array|Closure $values The values searched on, or anonymous function with subquery
* @param boolean $not If the statement would be IN or NOT IN
* @param string $type
* @param boolean $escape
* @param string $clause (Internal use only)
* @throws InvalidArgumentException
*
* @return BaseBuilder
Expand All @@ -998,8 +998,8 @@ protected function _whereIn(string $key = null, $values = null, bool $not = fals
if (CI_DEBUG)
{
throw new InvalidArgumentException(sprintf('%s() expects $key to be a non-empty string', debug_backtrace(0, 2)[1]['function']));
}
}

return $this;
}

Expand All @@ -1009,7 +1009,7 @@ protected function _whereIn(string $key = null, $values = null, bool $not = fals
{
throw new InvalidArgumentException(sprintf('%s() expects $values to be of type array or closure', debug_backtrace(0, 2)[1]['function']));
}

return $this;
}

Expand Down Expand Up @@ -1325,7 +1325,7 @@ protected function _like_statement(string $prefix = null, string $column, string
*/
public function groupStart()
{
return $this->groupStartPrepare('', 'AND ', 'QBWhere');
return $this->groupStartPrepare();
}

//--------------------------------------------------------------------
Expand All @@ -1337,7 +1337,7 @@ public function groupStart()
*/
public function orGroupStart()
{
return $this->groupStartPrepare('', 'OR ', 'QBWhere');
return $this->groupStartPrepare('', 'OR ');
}

//--------------------------------------------------------------------
Expand All @@ -1349,7 +1349,7 @@ public function orGroupStart()
*/
public function notGroupStart()
{
return $this->groupStartPrepare('NOT ', 'AND ', 'QBWhere');
return $this->groupStartPrepare('NOT ');
}

//--------------------------------------------------------------------
Expand All @@ -1361,7 +1361,7 @@ public function notGroupStart()
*/
public function orNotGroupStart()
{
return $this->groupStartPrepare('NOT ', 'OR ', 'QBWhere');
return $this->groupStartPrepare('NOT ', 'OR ');
}

//--------------------------------------------------------------------
Expand All @@ -1373,7 +1373,7 @@ public function orNotGroupStart()
*/
public function groupEnd()
{
return $this->groupEndPrepare('QBWhere');
return $this->groupEndPrepare();
}

// --------------------------------------------------------------------
Expand Down Expand Up @@ -2597,7 +2597,7 @@ protected function _updateBatch(string $table, array $values, string $index): st
$ids = [];
$final = [];

foreach ($values as $key => $val)
foreach ($values as $val)
{
$ids[] = $val[$index];

Expand Down Expand Up @@ -2646,7 +2646,7 @@ public function setUpdateBatch($key, string $index = '', bool $escape = null)

is_bool($escape) || $escape = $this->db->protectIdentifiers;

foreach ($key as $k => $v)
foreach ($key as $v)
{
$index_set = false;
$clean = [];
Expand Down Expand Up @@ -3426,7 +3426,7 @@ protected function setBind(string $key, $value = null, bool $escape = true): str
return $key;
}

if (!array_key_exists($key, $this->bindsKeyCount))
if (! array_key_exists($key, $this->bindsKeyCount))
{
$this->bindsKeyCount[$key] = 0;
}
Expand Down
6 changes: 2 additions & 4 deletions system/Database/BaseConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,7 @@ public function prepare(\Closure $func, array $options = [])
$this->initialize();
}

$this->pretend(true);
$this->pretend();

$sql = $func($this);

Expand Down Expand Up @@ -1381,9 +1381,7 @@ public function escape($str)
{
if (is_array($str))
{
$str = array_map([&$this, 'escape'], $str);

return $str;
return array_map([&$this, 'escape'], $str);
}
else if (is_string($str) || ( is_object($str) && method_exists($str, '__toString')))
{
Expand Down
Loading

0 comments on commit 1dc6216

Please sign in to comment.