Skip to content

Commit

Permalink
refactor isDirectory() & pretty() in LfmPath.php
Browse files Browse the repository at this point in the history
  • Loading branch information
streamtw committed Mar 23, 2018
1 parent 8d728a4 commit c043d02
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions src/LfmPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ public function files()

public function pretty($item_path)
{
$lfm_path = clone $this;
$lfm_path = $lfm_path->setName($this->helper->getNameFromPath($item_path));

return Container::getInstance()->makeWith(LfmItem::class, ['lfm' => $lfm_path, 'helper' => $this->helper]);
return Container::getInstance()->makeWith(LfmItem::class, [
'lfm' => (clone $this)->setName($this->helper->getNameFromPath($item_path)),
'helper' => $this->helper
]);
}

public function delete()
Expand Down Expand Up @@ -153,18 +153,11 @@ public function isDirectory()
$working_dir = $this->path('working_dir');
$parent_dir = substr($working_dir, 0, strrpos($working_dir, '/'));

$parent_path = app(static::class);
$parent_path->dir($parent_dir)->setName(null);

$directories = $parent_path->directories();

$that = $this;

$directories = array_map(function ($directory_path) use ($that) {
return $this->translateToLfmPath($directory_path);
}, $directories);
$parent_directories = array_map(function ($directory_path) {
return app(static::class)->translateToLfmPath($directory_path);
}, app(static::class)->dir($parent_dir)->directories());

return in_array($this->path('url'), $directories);
return in_array($this->path('url'), $parent_directories);
}

/**
Expand Down

0 comments on commit c043d02

Please sign in to comment.