Commit 9bb85d7d authored by Marco Schmiedel's avatar Marco Schmiedel

fix

parent 9d037667
......@@ -10,7 +10,7 @@
| sidekick package.
|
| Author: Marco Schmiedel <marco.schmiedel@itmax.email>
| Date: 2021-12-23 20:30:33
| Date: 2022-04-13 07:39:40
|
*/
namespace Ceetrox\Commands\CodebeautifierCommand;
......@@ -23,6 +23,7 @@
*/
use Ceetrox\Managers\TerminalManager\TerminalManager;
use Ceetrox\Managers\BeautifyManager\BeautifyManager;
use Ceetrox\Managers\DirectoryManager\DirectoryManager;
use Illuminate\Console\Command;
......@@ -31,7 +32,7 @@
| Class "CodebeautifierCommand"
|------------------------------------------------------------------------------------------------
*/
class CodebeautifierCommand extends Command
class CodebeautifierCommand extends Command
{
/*
......@@ -59,32 +60,52 @@
|----------------------------------------------------------------------------------------
| Try to get the filepath from the command line argument.
*/
$file = $this->argument('path');
$path = $this->argument('path');
/*
|----------------------------------------------------------------------------------------
| Check if the given file exists.
*/
if(!file_exists($file))
if(file_exists($path) and !is_dir($path))
{
/*
|------------------------------------------------------------------------------------
| Drop error for a wrong file path.
*/
$file = $this->error('Please enter a valid path to a php class!');
/*
|------------------------------------------------------------------------------------
| Stop the command...
*/
return false;
$this->singleCleaning($path);
return;
}
elseif(!is_dir($path))
{
$this->error('Please enter a valid path!');
return;
}
/*
|----------------------------------------------------------------------------------------
| Drop info for a wrong file path.
*/
$this->error($path);
if ($this->confirm('This is not a valid php file. Do you want to clean the whole path?'))
{
dd( DirectoryManager::getFilesWithFiletypeForDirectory($path, 'php') );
}
}
/*
|--------------------------------------------------------------------------------------------
| Method "singleCleaning"
|--------------------------------------------------------------------------------------------
*/
private function singleCleaning($file)
{
/*
|----------------------------------------------------------------------------------------
| Copy a backup to the vendor folder.
*/
copy( $file, __DIR__.'/BACKUP_'.time() );
copy( $file, __DIR__.'/BACKUP_'.time().md5(microtime()) );
/*
|----------------------------------------------------------------------------------------
......
......@@ -354,6 +354,12 @@
*/
$classes = $this->matchBetweenTwoPatterns($this->content, $openPattern, $closePattern);
// Exit when now class was found
if($classes == false)
{
exit();
}
/*
|----------------------------------------------------------------------------------------
| loop detected clases.
......
<?php
namespace Ceetrox\Managers\DirectoryManager;
class DirectoryManager
{
static function getFilesWithFiletypeForDirectory($directory, $type)
{
$files = glob($directory . '/*');
$data = array();
foreach ($files as $file) {
if (is_dir($file)) {
$data = array_merge($data, self::getFilesWithFiletypeForDirectory($file, $type));
} elseif (substr($file,-4) == '.'.$type) {
$data[] = $file;
}
}
return $data;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment