Mercurial > packages > magicforger
diff src/Generator/BaseGenerator.php @ 7:769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
| author | luka |
|---|---|
| date | Wed, 18 Oct 2023 21:04:11 -0400 |
| parents | b0b2e79ad8e6 |
| children | d4730c14806d |
line wrap: on
line diff
--- a/src/Generator/BaseGenerator.php Thu Oct 12 19:44:22 2023 -0400 +++ b/src/Generator/BaseGenerator.php Wed Oct 18 21:04:11 2023 -0400 @@ -3,19 +3,17 @@ namespace Wizzard\MagicForger\Generator; use DB; - use Illuminate\Console\GeneratorCommand; -use Illuminate\Support\Str; -use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; - use Wizzard\MagicForger\Replacer\Replacer; +use Wizzard\MagicForger\Replacer\TableReplacer; abstract class BaseGenerator extends GeneratorCommand { use Replacer; + use TableReplacer; /** * The schema of the database. @@ -27,7 +25,7 @@ /** * The tables available in the schema. * - * @var array + * @var array */ protected $tables; @@ -43,10 +41,8 @@ */ public function handle() { - - // First we need to ensure that the table exists, then we can - if (! $this->tableExists($this->getTableInput())) { + if (!$this->tableExists($this->getTableInput())) { $this->components->error('The table: "'.$this->getTableInput().'" does not exist in the database.'); return false; @@ -58,10 +54,14 @@ $file = $this->apply_replacements($file); + $file = $this->apply_inserts($file); + $this->makeDirectory($path); $this->files->put($path, $this->sortImports($file)); + $this->format_file($path); + $info = $this->type; $this->components->info(sprintf('%s [%s] created successfully.', $info, $path)); @@ -69,15 +69,14 @@ /** * Override the original so that we can prompt for a table with autocomplete. - * */ protected function promptForMissingArguments(InputInterface $input, OutputInterface $output) { $prompted = false; - if(is_null($input->getArgument('table'))) { + if (is_null($input->getArgument('table'))) { $prompted = true; $table = null; - while ($table === null) { + while (null === $table) { $table = $this->components->askWithCompletion( 'What Table should we use?', $this->possibleTables() @@ -90,7 +89,7 @@ parent::promptForMissingArguments($input, $output); // This will get missed if we prompt here but not in the parent - if($prompted) { + if ($prompted) { $this->afterPromptingForMissingArguments($input, $output); } } @@ -140,7 +139,7 @@ } /** - * Determines if the file exists + * Determines if the file exists. */ protected function fileExists(string $path): bool { @@ -151,22 +150,20 @@ * Gets the file that will be worked on. If there is already an existing file * then we can open that. However if we are forcing the operation, then we * will start with an empty stub. - * */ protected function getFile($name) { - if ((! $this->hasOption('fresh') || - ! $this->option('fresh')) && - $this->fileExists($name)) { - //Working with an existing file + if (!($this->hasOption('fresh') + && $this->option('fresh')) + && $this->fileExists($name)) { + // Working with an existing file return $this->files->get($name); } - //Working with a stub + // Working with a stub return $this->files->get($this->getStub()); } - /** * Get the desired class table from the input. * @@ -177,9 +174,8 @@ return trim($this->argument('table')); } - /** - * Determines if the table exists in the current database + * Determines if the table exists in the current database. */ protected function tableExists(string $table_name): bool { @@ -195,7 +191,7 @@ } /** - * Get the tables in the schema + * Get the tables in the schema. */ protected function getTables() { @@ -207,12 +203,12 @@ } /** - * Get the database schema for DB interactions + * Get the database schema for DB interactions. */ protected function getSchema() { if (is_null($this->schema)) { - $this->schema = DB::connection()->getDoctrineSchemaManager(); + $this->schema = \DB::connection()->getDoctrineSchemaManager(); } return $this->schema; @@ -231,9 +227,14 @@ protected function setCurrentTable(string $table_name) { $table = null; - if(!is_null($table_name) && trim($table_name) !== '') { + if (!is_null($table_name) && '' !== trim($table_name)) { $table = $this->getTable($table_name); } $this->currentTable = $table; } + + protected function format_file(string $path) + { + exec('php-cs-fixer fix '.$path); + } }
