Skip to content

Commit

Permalink
Deprecate both Exceptions::cleanPath() and `BaseCollector::cleanPat…
Browse files Browse the repository at this point in the history
…h()`
  • Loading branch information
paulbalandan committed Feb 12, 2022
1 parent d76e2a2 commit 9c3f6e9
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 43 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 @@ -30,7 +30,7 @@

<!-- Source -->
<div class="container">
<p><b><?= esc(static::cleanPath($file, $line)) ?></b> at line <b><?= esc($line) ?></b></p>
<p><b><?= esc(clean_path($file)) ?></b> at line <b><?= esc($line) ?></b></p>

<?php if (is_file($file)) : ?>
<div class="source">
Expand Down Expand Up @@ -64,12 +64,12 @@
<?php if (isset($row['file']) && is_file($row['file'])) :?>
<?php
if (isset($row['function']) && in_array($row['function'], ['include', 'include_once', 'require', 'require_once'], true)) {
echo esc($row['function'] . ' ' . static::cleanPath($row['file']));
echo esc($row['function'] . ' ' . clean_path($row['file']));
} else {
echo esc(static::cleanPath($row['file']) . ' : ' . $row['line']);
echo esc(clean_path($row['file']) . ' : ' . $row['line']);
}
?>
<?php else : ?>
<?php else: ?>
{PHP internal code}
<?php endif; ?>

Expand Down Expand Up @@ -350,7 +350,7 @@

<ol>
<?php foreach ($files as $file) :?>
<li><?= esc(static::cleanPath($file)) ?></li>
<li><?= esc(clean_path($file)) ?></li>
<?php endforeach ?>
</ol>
</div>
Expand Down
2 changes: 2 additions & 0 deletions system/Debug/Exceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,8 @@ protected function determineCodes(Throwable $exception): array

/**
* This makes nicer looking paths for the error output.
*
* @deprecated Use dedicated `clean_path()` function.
*/
public static function cleanPath(string $file): string
{
Expand Down
8 changes: 3 additions & 5 deletions system/Debug/Toolbar/Collectors/BaseCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

namespace CodeIgniter\Debug\Toolbar\Collectors;

use CodeIgniter\Debug\Exceptions;

/**
* Base Toolbar collector
*/
Expand Down Expand Up @@ -174,13 +172,13 @@ public function display()
}

/**
* Clean Path
*
* This makes nicer looking paths for the error output.
*
* @deprecated Use the dedicated `clean_path()` function.
*/
public function cleanPath(string $file): string
{
return Exceptions::cleanPath($file);
return clean_path($file);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion system/Debug/Toolbar/Collectors/Files.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function display(): array
$userFiles = [];

foreach ($rawFiles as $file) {
$path = $this->cleanPath($file);
$path = clean_path($file);

if (strpos($path, 'SYSTEMPATH') !== false) {
$coreFiles[] = [
Expand Down
32 changes: 0 additions & 32 deletions tests/system/Debug/ExceptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,36 +61,4 @@ public function testDetermineCodes(): void
$this->assertSame([500, 1], $determineCodes(new RuntimeException('That.', 600)));
$this->assertSame([404, 1], $determineCodes(new RuntimeException('There.', 404)));
}

/**
* @dataProvider dirtyPathsProvider
*/
public function testCleanPaths(string $file, string $expected): void
{
$this->assertSame($expected, Exceptions::cleanPath($file));
}

public function dirtyPathsProvider()
{
$ds = DIRECTORY_SEPARATOR;

yield from [
[
APPPATH . 'Config' . $ds . 'App.php',
'APPPATH' . $ds . 'Config' . $ds . 'App.php',
],
[
SYSTEMPATH . 'CodeIgniter.php',
'SYSTEMPATH' . $ds . 'CodeIgniter.php',
],
[
VENDORPATH . 'autoload.php',
'VENDORPATH' . $ds . 'autoload.php',
],
[
FCPATH . 'index.php',
'FCPATH' . $ds . 'index.php',
],
];
}
}
1 change: 1 addition & 0 deletions user_guide_src/source/changelogs/v4.2.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Deprecations
************

- ``CodeIgniter\Database\SQLSRV\Connection::getError()`` is deprecated. Use ``CodeIgniter\Database\SQLSRV\Connection::error()`` instead.
- ``CodeIgniter\Debug\Exceptions::cleanPath()`` and ``CodeIgniter\Debug\Toolbar\Collectors\BaseCollector::cleanPath()`` are deprecated. Use the ``clean_path()`` function instead.

Bugs Fixed
**********
Expand Down

0 comments on commit 9c3f6e9

Please sign in to comment.