From 0b5f91bb655f3c5d1d4971b97060f22b7e0fc273 Mon Sep 17 00:00:00 2001 From: Craig Harman Date: Fri, 12 Jul 2019 02:22:17 +0000 Subject: [PATCH] Apply fixes from StyleCI --- src/Commands/MakeInertiaTable.php | 38 +++++++++++++++++-------------- src/InertiaTable.php | 8 ++++--- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/src/Commands/MakeInertiaTable.php b/src/Commands/MakeInertiaTable.php index 61f6031..f82118e 100644 --- a/src/Commands/MakeInertiaTable.php +++ b/src/Commands/MakeInertiaTable.php @@ -9,7 +9,8 @@ use Symfony\Component\Process\Process; use Symfony\Component\Process\Exception\ProcessFailedException; -class MakeInertiaTable extends Command { +class MakeInertiaTable extends Command +{ use \Illuminate\Console\DetectsApplicationNamespace; /** @@ -31,16 +32,18 @@ class MakeInertiaTable extends Command { * * @return void */ - public function __construct() { + public function __construct() + { parent::__construct(); } - private function inertiaTableJSExists() { + private function inertiaTableJSExists() + { $process = new Process('npm list --depth=0 | grep inertia-table'); $process->run(); // executes after the command finishes - if (!$process->isSuccessful()) { + if (! $process->isSuccessful()) { if ($process->getOutput() == '') { return false; } @@ -61,46 +64,47 @@ private function inertiaTableJSExists() { * * @return mixed */ - public function handle() { + public function handle() + { $model = ucfirst($this->argument('model')); - if (!file_exists(app_path($model) . '.php') && !file_exists(app_path('Models\\' . $model) . '.php')) { + if (! file_exists(app_path($model).'.php') && ! file_exists(app_path('Models\\'.$model).'.php')) { // Create Model - $str = file_get_contents(__DIR__ . '/../Stubs/Model.php'); + $str = file_get_contents(__DIR__.'/../Stubs/Model.php'); $str = str_replace('@namespace', substr($this->getAppNamespace(), 0, -1), $str); $str = str_replace('@modelName', $model, $str); - file_put_contents(app_path($model . '.php'), $str); + file_put_contents(app_path($model.'.php'), $str); } // Create Controller $pluralName = Str::plural($model); - $controllerName = $pluralName . 'Controller'; - $str = file_get_contents(__DIR__ . '/../Stubs/Controller.php'); + $controllerName = $pluralName.'Controller'; + $str = file_get_contents(__DIR__.'/../Stubs/Controller.php'); $str = str_replace('@namespace', substr($this->getAppNamespace(), 0, -1), $str); $str = str_replace('@controllerName', $controllerName, $str); $str = str_replace('@modelName', $model, $str); - file_put_contents(app_path('Http/Controllers/' . $controllerName . '.php'), $str); + file_put_contents(app_path('Http/Controllers/'.$controllerName.'.php'), $str); // Add routes - $this->warn('You need to manually add route: Route::inertia(\'' . Str::plural(strtolower($model)) . '\');'); + $this->warn('You need to manually add route: Route::inertia(\''.Str::plural(strtolower($model)).'\');'); if ($this->inertiaTableJSExists()) { $pluralNameLowercase = \strtolower($pluralName); $modelLowercase = \strtolower($model); // Get column names from table - $class = 'App\\' . $model; + $class = 'App\\'.$model; $columns = Schema::getColumnListing(with(new $class)->getTable()); // Create an InertiaTable.vue component and then create Index.vue using it - $tableElementPath = resource_path('js/Pages/' . $pluralName); + $tableElementPath = resource_path('js/Pages/'.$pluralName); File::makeDirectory($tableElementPath, 0755, true); - $str = file_get_contents(__DIR__ . '/../Stubs/Index.vue'); + $str = file_get_contents(__DIR__.'/../Stubs/Index.vue'); $str = str_replace('@pluralNameLowercase', $pluralNameLowercase, $str); $str = str_replace('@plural', $pluralName, $str); - $str = str_replace('@columns', '"' . implode('","', $columns) . '"', $str); + $str = str_replace('@columns', '"'.implode('","', $columns).'"', $str); $str = str_replace('@modelLowercase', $modelLowercase, $str); - file_put_contents($tableElementPath . '/Index.vue', $str); + file_put_contents($tableElementPath.'/Index.vue', $str); } $this->info('Model, Controller and Vue Components successfully created.'); diff --git a/src/InertiaTable.php b/src/InertiaTable.php index 5af4b3d..571bf75 100644 --- a/src/InertiaTable.php +++ b/src/InertiaTable.php @@ -7,7 +7,8 @@ use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Request; -class InertiaTable { +class InertiaTable +{ /** * Generates inertia view data for model. * @@ -15,7 +16,8 @@ class InertiaTable { * @param array $columns An array of column names to send to front end (null for all columns) * @return void */ - public function index(InertiaModel $model, array $columns = null) { + public function index(InertiaModel $model, array $columns = null) + { $modelName = class_basename($model); if ($columns == null) { // default to all columns @@ -25,7 +27,7 @@ public function index(InertiaModel $model, array $columns = null) { $modelPlural = Str::plural($modelName); - return Inertia::render($modelPlural . '/Index', [ + return Inertia::render($modelPlural.'/Index', [ 'filters' => Request::all('search', 'trashed'), 'order' => Request::all('orderColumn', 'orderDirection'), strtolower($modelPlural) => $model