From a1cb213131c063531e632626820a04cff3660d88 Mon Sep 17 00:00:00 2001 From: Chris Kankiewicz Date: Sun, 26 Jan 2020 01:26:56 -0700 Subject: [PATCH] Simplified path handling in DirectoryController --- app/Controllers/DirectoryController.php | 19 +------------------ tests/Support/HelpersTest.php | 22 ---------------------- 2 files changed, 1 insertion(+), 40 deletions(-) diff --git a/app/Controllers/DirectoryController.php b/app/Controllers/DirectoryController.php index 83c4705..264e498 100644 --- a/app/Controllers/DirectoryController.php +++ b/app/Controllers/DirectoryController.php @@ -10,7 +10,6 @@ use Slim\Views\Twig; use Symfony\Component\Finder\Exception\DirectoryNotFoundException; use Symfony\Component\Finder\Finder; use Symfony\Component\Finder\SplFileInfo; -use Tightenco\Collect\Support\Collection; class DirectoryController { @@ -64,29 +63,13 @@ class DirectoryController 'files' => $search ? $files->name( sprintf('/(?:.*)%s(?:.*)/i', preg_quote($search, '/')) ) : $files->depth(0), - 'path' => $this->relativePath($path), + 'path' => $path, 'is_root' => $this->isRoot($path), 'readme' => $this->readme($path), 'search' => $search, ]); } - /** - * Return the relative path given a full path. - * - * @param string $path - * - * @return string - */ - protected function relativePath(string $path): string - { - $realPath = realpath($this->container->get('base_path') . '/' . $path); - - return Collection::make(explode('/', $realPath))->diff( - explode('/', $this->container->get('base_path')) - )->filter()->implode('/'); - } - /** * Determine if a provided path is the root path. * diff --git a/tests/Support/HelpersTest.php b/tests/Support/HelpersTest.php index f5f9d7c..8901dee 100644 --- a/tests/Support/HelpersTest.php +++ b/tests/Support/HelpersTest.php @@ -4,7 +4,6 @@ namespace Tests\Support; use App\Support\Helpers; use PHPUnit\Framework\TestCase; -use RuntimeException; class HelpersTest extends TestCase { @@ -48,25 +47,4 @@ class HelpersTest extends TestCase $this->assertEquals('Test charlie; please ignore', $env); } - - public function test_it_can_get_a_relative_path_from_one_path_to_another(): void - { - $relativePath = Helpers::realativePath('foo/bar', 'foo/bar/baz/qux'); - - $this->assertEquals('baz/qux', $relativePath); - } - - public function test_it_cat_get_a_relative_path_to_itself(): void - { - $relativePath = Helpers::realativePath('foo/bar/baz', 'foo/bar/baz'); - - $this->assertEquals('', $relativePath); - } - - public function test_it_can_get_a_relative_path_between_two_unrelated_paths(): void - { - $path = $this->expectException(RuntimeException::class); - - Helpers::realativePath('foo/bar', 'baz/qux'); - } }