Skip to content

Commit

Permalink
reorganize File, a little cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ahuggins committed Aug 29, 2020
1 parent 0ffe655 commit ce6a618
Showing 1 changed file with 7 additions and 29 deletions.
36 changes: 7 additions & 29 deletions src/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@
use OpenOnMake\Paths;
use OpenOnMake\Options;
use OpenOnMake\CommandInfo;
use Symfony\Component\Finder\Finder;
use OpenOnMake\Openers\MigrationFile;

class File
{
private $options;
private $open;
private $finder;

public function __construct(OpenFile $open, Options $options)
public function __construct(OpenFile $open, Options $options, Finder $finder)
{
$this->open = $open;
$this->options = $options;
$this->finder = $finder;
}

public function openOptionalFiles($option, $name)
Expand All @@ -33,36 +36,19 @@ public function open($path)
$this->open->open($path);
}

public function getViewFileName($name)
{
$pathSeparator = str_replace('.', '/', $name) . '.blade.php';
$parts = explode('/', $pathSeparator);
return array_pop($parts);
}

public function getFileName($name)
{
return str_replace('\\', '/', $name . '.php');
}

public function filename($commandString, $name)
{
if (Check::isViewCommand($commandString)) {
return $this->getViewFileName($name);
}

return $this->getFileName($name);
}

public function find(CommandInfo $commandInfo)
{
$finder = new \Symfony\Component\Finder\Finder();
$finder->files()->depth('>= 0')->depth('< 10')->name($commandInfo->getSplFile()->getFileName())->in(base_path());
$this->finder->files()->depth('>= 0')->depth('< 10')->name($commandInfo->getSplFile()->getFileName())->in(base_path());

$path = '';

if ($finder->hasResults()) {
foreach ($finder as $file) {
if ($this->finder->hasResults()) {
foreach ($this->finder as $file) {
$path = $file->getRealPath();
break;
}
Expand Down Expand Up @@ -96,12 +82,4 @@ public function openFilesGeneratedInAdditionToModel($option, $name)
$this->openAdditionalFile(Paths::getPath($this->options->getOption($option)), $name, $option);
}
}

public function getFileNameFromSplFileInfo($filename)
{
if ($filename instanceof \SplFileInfo) {
return $filename->getFileName();
}
return $filename;
}
}

0 comments on commit ce6a618

Please sign in to comment.