Skip to content

Commit 1dc6216

Browse files
authored
Merge pull request #2748 from samsonasik/clean-up-dead-code
clean up dead code detected by rectorphp/rector
2 parents 93f1a65 + 4d284d9 commit 1dc6216

62 files changed

Lines changed: 147 additions & 273 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/Views/errors/html/error_exception.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@
132132
<?php if (empty($GLOBALS[$var]) || ! is_array($GLOBALS[$var]))
133133
{
134134
continue;
135-
} ?>
135+
} ?>
136136

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

@@ -235,7 +235,7 @@
235235
<?php if (empty($GLOBALS[$var]) || ! is_array($GLOBALS[$var]))
236236
{
237237
continue;
238-
} ?>
238+
} ?>
239239

240240
<?php $empty = false; ?>
241241

@@ -287,15 +287,15 @@
287287
</tr>
288288
</thead>
289289
<tbody>
290-
<?php foreach ($headers as $name => $value) : ?>
290+
<?php foreach ($headers as $value) : ?>
291291
<?php if (empty($value))
292292
{
293293
continue;
294-
} ?>
294+
} ?>
295295
<?php if (! is_array($value))
296296
{
297297
$value = [$value];
298-
} ?>
298+
} ?>
299299
<?php foreach ($value as $h) : ?>
300300
<tr>
301301
<td><?= esc($h->getName(), 'html') ?></td>

system/CLI/CLI.php

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ public static function newLine(int $num = 1)
437437
// Do it once or more, write with empty string gives us a new line
438438
for ($i = 0; $i < $num; $i ++)
439439
{
440-
static::write('');
440+
static::write();
441441
}
442442
}
443443

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

507-
$string .= $text . "\033[0m";
508-
509-
return $string;
507+
return $string . ($text . "\033[0m");
510508
}
511509

512510
//--------------------------------------------------------------------
@@ -702,24 +700,17 @@ public static function wrap(string $string = null, int $max = 0, int $pad_left =
702700
*/
703701
protected static function parseCommandLine()
704702
{
705-
$optionsFound = false;
706-
707703
// start picking segments off from #1, ignoring the invoking program
708704
for ($i = 1; $i < $_SERVER['argc']; $i ++)
709705
{
710706
// If there's no '-' at the beginning of the argument
711707
// then add it to our segments.
712-
if (! $optionsFound && mb_strpos($_SERVER['argv'][$i], '-') === false)
708+
if (mb_strpos($_SERVER['argv'][$i], '-') === false)
713709
{
714710
static::$segments[] = $_SERVER['argv'][$i];
715711
continue;
716712
}
717713

718-
// We set $optionsFound here so that we know to
719-
// skip the next argument since it's likely the
720-
// value belonging to this option.
721-
$optionsFound = true;
722-
723714
$arg = str_replace('-', '', $_SERVER['argv'][$i]);
724715
$value = null;
725716

@@ -731,10 +722,6 @@ protected static function parseCommandLine()
731722
}
732723

733724
static::$options[$arg] = $value;
734-
735-
// Reset $optionsFound so it can collect segments
736-
// past any options.
737-
$optionsFound = false;
738725
}
739726
}
740727

system/Cache/Handlers/FileHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public function delete(string $key)
154154
{
155155
$key = $this->prefix . $key;
156156

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

160160
//--------------------------------------------------------------------

system/CodeIgniter.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -749,9 +749,7 @@ public function displayPerformanceMetrics(string $output): string
749749
{
750750
$this->totalTime = $this->benchmark->getElapsedTime('total_execution');
751751

752-
$output = str_replace('{elapsed_time}', $this->totalTime, $output);
753-
754-
return $output;
752+
return str_replace('{elapsed_time}', $this->totalTime, $output);
755753
}
756754

757755
//--------------------------------------------------------------------

system/Commands/ListCommands.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,8 @@ protected function padTitle(string $item, int $max, int $extra = 2, int $indent
188188
$max += $extra + $indent;
189189

190190
$item = str_repeat(' ', $indent) . $item;
191-
$item = str_pad($item, $max);
192191

193-
return $item;
192+
return str_pad($item, $max);
194193
}
195194

196195
//--------------------------------------------------------------------

system/Common.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ function esc($data, string $context = 'html', string $encoding = null)
319319
{
320320
if (is_array($data))
321321
{
322-
foreach ($data as $key => &$value)
322+
foreach ($data as &$value)
323323
{
324324
$value = esc($value, $context);
325325
}

system/Config/BaseConfig.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,16 +164,12 @@ protected function getEnvValue(string $property, string $prefix, string $shortPr
164164
{
165165
case array_key_exists("{$shortPrefix}.{$property}", $_ENV):
166166
return $_ENV["{$shortPrefix}.{$property}"];
167-
break;
168167
case array_key_exists("{$shortPrefix}.{$property}", $_SERVER):
169168
return $_SERVER["{$shortPrefix}.{$property}"];
170-
break;
171169
case array_key_exists("{$prefix}.{$property}", $_ENV):
172170
return $_ENV["{$prefix}.{$property}"];
173-
break;
174171
case array_key_exists("{$prefix}.{$property}", $_SERVER):
175172
return $_SERVER["{$prefix}.{$property}"];
176-
break;
177173
default:
178174
$value = getenv($property);
179175
return $value === false ? null : $value;

system/Config/DotEnv.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public function parse(): ?array
128128
if (strpos($line, '=') !== false)
129129
{
130130
list($name, $value) = $this->normaliseVariable($line);
131-
$vars[$name] = $value;
131+
$vars[$name] = $value;
132132
}
133133
}
134134

@@ -314,10 +314,8 @@ protected function getVariable(string $name)
314314
{
315315
case array_key_exists($name, $_ENV):
316316
return $_ENV[$name];
317-
break;
318317
case array_key_exists($name, $_SERVER):
319318
return $_SERVER[$name];
320-
break;
321319
default:
322320
$value = getenv($name);
323321

system/Config/Services.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,7 @@ public static function email($config = null, bool $getShared = true)
207207
{
208208
$config = new \Config\Email();
209209
}
210-
$email = new \CodeIgniter\Email\Email($config);
211-
return $email;
210+
return new \CodeIgniter\Email\Email($config);
212211
}
213212

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

234233
$encryption = new Encryption($config);
235-
$encrypter = $encryption->initialize($config);
236-
return $encrypter;
234+
return $encryption->initialize($config);
237235
}
238236

239237
//--------------------------------------------------------------------
@@ -542,7 +540,7 @@ public static function parser(string $viewPath = null, $config = null, bool $get
542540
$viewPath = $paths->viewDirectory;
543541
}
544542

545-
return new Parser($config, $viewPath, static::locator(true), CI_DEBUG, static::logger(true));
543+
return new Parser($config, $viewPath, static::locator(), CI_DEBUG, static::logger());
546544
}
547545

548546
//--------------------------------------------------------------------
@@ -577,7 +575,7 @@ public static function renderer(string $viewPath = null, $config = null, bool $g
577575
$viewPath = $paths->viewDirectory;
578576
}
579577

580-
return new \CodeIgniter\View\View($config, $viewPath, static::locator(true), CI_DEBUG, static::logger(true));
578+
return new \CodeIgniter\View\View($config, $viewPath, static::locator(), CI_DEBUG, static::logger());
581579
}
582580

583581
//--------------------------------------------------------------------
@@ -705,7 +703,7 @@ public static function router(RouteCollectionInterface $routes = null, Request $
705703

706704
if (empty($routes))
707705
{
708-
$routes = static::routes(true);
706+
$routes = static::routes();
709707
}
710708

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

762-
$logger = static::logger(true);
760+
$logger = static::logger();
763761

764762
$driverName = $config->sessionDriver;
765763
$driver = new $driverName($config, static::request()->getIpAddress());

system/Controller.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,10 @@ protected function validate($rules, array $messages = []): bool
213213
$rules = $validation->$rules;
214214
}
215215

216-
$success = $this->validator
216+
return $this->validator
217217
->withRequest($this->request)
218218
->setRules($rules, $messages)
219219
->run();
220-
221-
return $success;
222220
}
223221

224222
//--------------------------------------------------------------------

0 commit comments

Comments
 (0)