diff --git a/helpers.php b/helpers.php index 3fb8c62..a619ac8 100644 --- a/helpers.php +++ b/helpers.php @@ -1,6 +1,6 @@ getGithubToken(); $path = $this->argument('path'); - if (!File::isDirectory($path)) { + if (! File::isDirectory($path)) { $path = base_path($path); } @@ -38,18 +40,19 @@ public function handle(): void $this->runCmd($path, 'git pull'); if (empty($lastTag)) { - $body = $this->runCmd($path, "git log --no-merges --pretty=format:\"* %s\" | uniq"); + $body = $this->runCmd($path, 'git log --no-merges --pretty=format:"* %s" | uniq'); } else { $body = $this->runCmd($path, "git log --no-merges --pretty=format:\"* %s\" {$lastTag}..HEAD | uniq"); } if (empty($body)) { $this->info('Nothing to release'); + return; } $body = collect(explode("\n", $body)) - ->filter(fn ($item) => !empty($item) && !str_contains($item, ':construction:')) + ->filter(fn ($item) => ! empty($item) && ! str_contains($item, ':construction:')) ->implode("\n"); $newTag = $this->getReleaseVersion($lastTag); @@ -88,7 +91,7 @@ public function handle(): void ) ->throw(); - $this->info('Released url: '. $release->json()['html_url']); + $this->info('Released url: '.$release->json()['html_url']); } protected function getLastTag(string $path): string @@ -127,7 +130,7 @@ protected function getReleaseVersion(string $lastTag): string $split = explode('.', $lastTag); if (count($split) > 2) { - ++$split[count($split) - 1]; + $split[count($split) - 1]++; $newTag = implode('.', $split); } else { $newTag = $lastTag.'.1'; diff --git a/src/Commands/Modules/CommandMakeCommand.php b/src/Commands/Modules/CommandMakeCommand.php index 5223d8e..1753e57 100644 --- a/src/Commands/Modules/CommandMakeCommand.php +++ b/src/Commands/Modules/CommandMakeCommand.php @@ -15,8 +15,6 @@ class CommandMakeCommand extends GeneratorCommand /** * The name of argument name. - * - * @var string */ protected string $argumentName = 'name'; @@ -73,8 +71,8 @@ protected function getTemplateContents() return (new Stub('/command.stub', [ 'COMMAND_NAME' => $this->getCommandName(), - 'NAMESPACE' => $this->getClassNamespace($module), - 'CLASS' => $this->getClass(), + 'NAMESPACE' => $this->getClassNamespace($module), + 'CLASS' => $this->getClass(), ]))->render(); } @@ -95,7 +93,7 @@ protected function getDestinationFilePath() $commandPath = GenerateConfigReader::read('command'); - return $path . $commandPath->getPath() . '/' . $this->getFileName() . '.php'; + return $path.$commandPath->getPath().'/'.$this->getFileName().'.php'; } /** diff --git a/src/Commands/Modules/ComponentClassMakeCommand.php b/src/Commands/Modules/ComponentClassMakeCommand.php index d5bcf5d..1b81297 100644 --- a/src/Commands/Modules/ComponentClassMakeCommand.php +++ b/src/Commands/Modules/ComponentClassMakeCommand.php @@ -14,8 +14,6 @@ class ComponentClassMakeCommand extends GeneratorCommand /** * The name of argument name. - * - * @var string */ protected string $argumentName = 'name'; @@ -42,6 +40,7 @@ public function handle(): int return 0; } + /** * Write the view template for the component. * @@ -49,7 +48,7 @@ public function handle(): int */ protected function writeComponentViewTemplate() { - $this->call('module:make-component-view', ['name' => $this->argument('name') , 'module' => $this->argument('module')]); + $this->call('module:make-component-view', ['name' => $this->argument('name'), 'module' => $this->argument('module')]); } public function getDefaultNamespace(): string @@ -71,6 +70,7 @@ protected function getArguments() ['module', InputArgument::OPTIONAL, 'The name of module will be used.'], ]; } + /** * @return mixed */ @@ -79,10 +79,10 @@ protected function getTemplateContents() $module = $this->laravel['modules']->findOrFail($this->getModuleName()); return (new Stub('/component-class.stub', [ - 'NAMESPACE' => $this->getClassNamespace($module), - 'CLASS' => $this->getClass(), - 'LOWER_NAME' => $module->getLowerName(), - 'COMPONENT_NAME' => 'components.' . Str::lower($this->argument('name')), + 'NAMESPACE' => $this->getClassNamespace($module), + 'CLASS' => $this->getClass(), + 'LOWER_NAME' => $module->getLowerName(), + 'COMPONENT_NAME' => 'components.'.Str::lower($this->argument('name')), ]))->render(); } @@ -94,7 +94,7 @@ protected function getDestinationFilePath() $path = $this->laravel['modules']->getModulePath($this->getModuleName()); $factoryPath = GenerateConfigReader::read('component-class'); - return $path . $factoryPath->getPath() . '/' . $this->getFileName(); + return $path.$factoryPath->getPath().'/'.$this->getFileName(); } /** @@ -102,6 +102,6 @@ protected function getDestinationFilePath() */ private function getFileName() { - return Str::studly($this->argument('name')) . '.php'; + return Str::studly($this->argument('name')).'.php'; } } diff --git a/src/Commands/Modules/ComponentViewMakeCommand.php b/src/Commands/Modules/ComponentViewMakeCommand.php index 278bc6f..4ce3a50 100644 --- a/src/Commands/Modules/ComponentViewMakeCommand.php +++ b/src/Commands/Modules/ComponentViewMakeCommand.php @@ -15,8 +15,6 @@ class ComponentViewMakeCommand extends GeneratorCommand /** * The name of argument name. - * - * @var string */ protected string $argumentName = 'name'; @@ -52,7 +50,7 @@ protected function getArguments() */ protected function getTemplateContents() { - return (new Stub('/component-view.stub', ['QUOTE'=> Inspiring::quote()]))->render(); + return (new Stub('/component-view.stub', ['QUOTE' => Inspiring::quote()]))->render(); } /** @@ -63,7 +61,7 @@ protected function getDestinationFilePath() $path = $this->laravel['modules']->getModulePath($this->getModuleName()); $factoryPath = GenerateConfigReader::read('component-view'); - return $path . $factoryPath->getPath() . '/' . $this->getFileName(); + return $path.$factoryPath->getPath().'/'.$this->getFileName(); } /** @@ -71,6 +69,6 @@ protected function getDestinationFilePath() */ private function getFileName() { - return Str::lower($this->argument('name')) . '.blade.php'; + return Str::lower($this->argument('name')).'.blade.php'; } } diff --git a/src/Commands/Modules/ControllerMakeCommand.php b/src/Commands/Modules/ControllerMakeCommand.php index d48b897..eddbaac 100644 --- a/src/Commands/Modules/ControllerMakeCommand.php +++ b/src/Commands/Modules/ControllerMakeCommand.php @@ -3,6 +3,7 @@ namespace Juzaweb\DevTool\Commands\Modules; use Illuminate\Support\Str; +use Juzaweb\Modules\Core\Facades\Module; use Juzaweb\Modules\Core\Modules\FileRepository; use Juzaweb\Modules\Core\Modules\Support\Config\GenerateConfigReader; use Juzaweb\Modules\Core\Modules\Support\Stub; @@ -16,8 +17,6 @@ class ControllerMakeCommand extends GeneratorCommand /** * The name of argument being used. - * - * @var string */ protected string $argumentName = 'controller'; @@ -37,43 +36,36 @@ class ControllerMakeCommand extends GeneratorCommand /** * Get controller name. - * - * @return string */ public function getDestinationFilePath(): string { - $path = \Juzaweb\Modules\Core\Facades\Module::getModulePath($this->getModuleName()); + $path = Module::getModulePath($this->getModuleName()); $controllerPath = GenerateConfigReader::read('controller'); - return $path . $controllerPath->getPath() . '/' . $this->getControllerName() . '.php'; + return $path.$controllerPath->getPath().'/'.$this->getControllerName().'.php'; } - /** - * @return string - */ protected function getTemplateContents(): string { - $module = \Juzaweb\Modules\Core\Facades\Module::findOrFail($this->getModuleName()); + $module = Module::findOrFail($this->getModuleName()); return (new Stub($this->getStubName(), [ - 'MODULENAME' => $module->getStudlyName(), - 'CONTROLLERNAME' => $this->getControllerName(), - 'NAMESPACE' => $module->getStudlyName(), - 'CLASS_NAMESPACE' => $this->getClassNamespace($module), - 'CLASS' => $this->getControllerNameWithoutNamespace(), - 'LOWER_NAME' => $module->getLowerName(), - 'MODULE' => $this->getModuleName(), - 'NAME' => $this->getModuleName(), - 'STUDLY_NAME' => $module->getStudlyName(), - 'MODULE_NAMESPACE' => \Juzaweb\Modules\Core\Facades\Module::config('namespace'), + 'MODULENAME' => $module->getStudlyName(), + 'CONTROLLERNAME' => $this->getControllerName(), + 'NAMESPACE' => $module->getStudlyName(), + 'CLASS_NAMESPACE' => $this->getClassNamespace($module), + 'CLASS' => $this->getControllerNameWithoutNamespace(), + 'LOWER_NAME' => $module->getLowerName(), + 'MODULE' => $this->getModuleName(), + 'NAME' => $this->getModuleName(), + 'STUDLY_NAME' => $module->getStudlyName(), + 'MODULE_NAMESPACE' => Module::config('namespace'), ]))->render(); } /** * Get the console command arguments. - * - * @return array */ protected function getArguments(): array { @@ -83,9 +75,6 @@ protected function getArguments(): array ]; } - /** - * @return array - */ protected function getOptions(): array { return [ @@ -115,7 +104,6 @@ public function getDefaultNamespace(): string /** * Get the stub file name based on the options - * @return string */ protected function getStubName(): string { @@ -130,9 +118,6 @@ protected function getStubName(): string return $stub; } - /** - * @return array|string - */ private function getControllerNameWithoutNamespace(): array|string { return class_basename($this->getControllerName()); diff --git a/src/Commands/Modules/Cruds/APICrudMakeCommand.php b/src/Commands/Modules/Cruds/APICrudMakeCommand.php index 25fa7d2..d2608c2 100644 --- a/src/Commands/Modules/Cruds/APICrudMakeCommand.php +++ b/src/Commands/Modules/Cruds/APICrudMakeCommand.php @@ -1,9 +1,10 @@ getPath().'/APIs/'.$this->getControllerName().'.php'; - if (!$this->laravel['files']->isDirectory($dir = dirname($path))) { + if (! $this->laravel['files']->isDirectory($dir = dirname($path))) { $this->laravel['files']->makeDirectory($dir, 0777, true); } @@ -93,33 +94,33 @@ protected function generateController(): int $this->tableName = $this->makeModel($module)->getTable(); $contents = (new Stub('cruds/api/controller.stub', [ - 'MODULENAME' => $module->getStudlyName(), - 'CONTROLLERNAME' => $this->getControllerName(), - 'NAMESPACE' => $module->getStudlyName(), - 'CLASS_NAMESPACE' => $this->getClassNamespace($module, 'Http\\Controllers\\APIs\\'), - 'CLASS' => $this->getControllerNameWithoutNamespace(), - 'LOWER_NAME' => $module->getLowerName(), - 'MODULE' => $this->getModuleName(), - 'NAME' => $this->getModuleName(), - 'STUDLY_NAME' => $module->getStudlyName(), - 'MODULE_NAMESPACE' => app(RepositoryInterface::class)->config('namespace'), - 'MODEL_NAMESPACE' => $this->getModelClass($module), - 'URL_PREFIX' => $this->getUrlPrefix(), - 'MODEL_NAME' => $this->getModelName(), + 'MODULENAME' => $module->getStudlyName(), + 'CONTROLLERNAME' => $this->getControllerName(), + 'NAMESPACE' => $module->getStudlyName(), + 'CLASS_NAMESPACE' => $this->getClassNamespace($module, 'Http\\Controllers\\APIs\\'), + 'CLASS' => $this->getControllerNameWithoutNamespace(), + 'LOWER_NAME' => $module->getLowerName(), + 'MODULE' => $this->getModuleName(), + 'NAME' => $this->getModuleName(), + 'STUDLY_NAME' => $module->getStudlyName(), + 'MODULE_NAMESPACE' => app(RepositoryInterface::class)->config('namespace'), + 'MODEL_NAMESPACE' => $this->getModelClass($module), + 'URL_PREFIX' => $this->getUrlPrefix(), + 'MODEL_NAME' => $this->getModelName(), 'REPOSITORY_NAMESPACE' => $this->getRepositoryClass($module), - 'REPOSITORY_CLASS' => $this->getRepositoryName(), - 'REPOSITORY_NAME' => Str::camel($this->getRepositoryName()), - 'TITLE' => $this->getTitle(), - 'SINGULAR_TITLE' => Str::singular($this->getTitle()), - 'TABLE' => $this->tableName, + 'REPOSITORY_CLASS' => $this->getRepositoryName(), + 'REPOSITORY_NAME' => Str::camel($this->getRepositoryName()), + 'TITLE' => $this->getTitle(), + 'SINGULAR_TITLE' => Str::singular($this->getTitle()), + 'TABLE' => $this->tableName, 'REQUEST_NAMESPACE' => $this->getRequestNamespace($module), 'BULK_REQUEST_NAMESPACE' => $this->getBulkRequestNamespace($module), - 'REQUEST_NAME' => "{$this->modelName}Request", + 'REQUEST_NAME' => "{$this->modelName}Request", 'BULK_REQUEST_NAME' => "{$this->modelName}ActionsRequest", ]))->render(); try { - $this->components->task("Generating file {$path}",function () use ($path, $contents) { + $this->components->task("Generating file {$path}", function () use ($path, $contents) { $overwriteFile = $this->hasOption('force') ? $this->option('force') : false; (new FileGenerator($path, $contents))->withFileOverwrite($overwriteFile)->generate(); }); @@ -153,9 +154,6 @@ protected function getUrlPrefix(): string return Str::plural(Str::slug($this->argument('model'))); } - /** - * @return string - */ protected function getControllerNameWithoutNamespace(): string { return class_basename($this->getControllerName()); @@ -179,8 +177,6 @@ protected function getModulePath() /** * Get class name. - * - * @return string */ protected function getClass(): string { @@ -189,8 +185,6 @@ protected function getClass(): string /** * Get the console command arguments. - * - * @return array */ protected function getArguments(): array { diff --git a/src/Commands/Modules/Cruds/AdminCrudMakeCommand.php b/src/Commands/Modules/Cruds/AdminCrudMakeCommand.php index 39d60e7..d36c4b8 100644 --- a/src/Commands/Modules/Cruds/AdminCrudMakeCommand.php +++ b/src/Commands/Modules/Cruds/AdminCrudMakeCommand.php @@ -53,9 +53,9 @@ public function handle(): int $module = \Juzaweb\Modules\Core\Facades\Module::findOrFail($this->getModuleName()); $routePath = GenerateConfigReader::read('routes'); - $adminRouteFile = $this->getModulePath() . $routePath->getPath() . '/admin.php'; + $adminRouteFile = $this->getModulePath().$routePath->getPath().'/admin.php'; $controllerClass = $this->getClassNamespace($module, 'Http\\Controllers\\') - . "\\" . $this->getControllerNameWithoutNamespace(); + .'\\'.$this->getControllerNameWithoutNamespace(); $content = file_get_contents($adminRouteFile); @@ -68,12 +68,12 @@ public function handle(): int $content = substr_replace($content, "\nuse {$controllerClass};", $pos, 0); } else { // Nếu không có use nào, thêm ở đầu file - $content = "use {$controllerClass};\n\n" . $content; + $content = "use {$controllerClass};\n\n".$content; } // Thêm Route::admin(...) xuống cuối file - $routeLine = "\nRoute::admin('{$this->getUrlPrefix()}', " . $this->getControllerNameWithoutNamespace() . "::class);\n"; - $content = rtrim($content) . $routeLine; + $routeLine = "\nRoute::admin('{$this->getUrlPrefix()}', ".$this->getControllerNameWithoutNamespace()."::class);\n"; + $content = rtrim($content).$routeLine; file_put_contents($adminRouteFile, $content); @@ -100,7 +100,7 @@ protected function generateController(): int $path .= $controllerPath->getPath().'/'.$this->getControllerName().'.php'; - if (!$this->laravel['files']->isDirectory($dir = dirname($path))) { + if (! $this->laravel['files']->isDirectory($dir = dirname($path))) { $this->laravel['files']->makeDirectory($dir, 0777, true); } @@ -111,7 +111,7 @@ protected function generateController(): int ]))->render(); try { - $this->components->task("Generating file {$path}",function () use ($path, $contents) { + $this->components->task("Generating file {$path}", function () use ($path, $contents) { $overwriteFile = $this->hasOption('force') ? $this->option('force') : false; (new FileGenerator($path, $contents))->withFileOverwrite($overwriteFile)->generate(); }); @@ -153,7 +153,7 @@ protected function generateViews(): int $path .= $viewPath->getPath()."/{$lowerSingularTitle}/index.blade.php"; - if (!File::isDirectory($dir = dirname($path))) { + if (! File::isDirectory($dir = dirname($path))) { File::makeDirectory($dir, 0777, true); } @@ -164,7 +164,7 @@ protected function generateViews(): int ]))->render(); try { - $this->components->task("Generating file {$path}",function () use ($path, $contents) { + $this->components->task("Generating file {$path}", function () use ($path, $contents) { $overwriteFile = $this->hasOption('force') ? $this->option('force') : false; (new FileGenerator($path, $contents))->withFileOverwrite($overwriteFile)->generate(); }); @@ -183,7 +183,7 @@ protected function generateViews(): int ]))->render(); try { - $this->components->task("Generating file {$path}",function () use ($path, $contents) { + $this->components->task("Generating file {$path}", function () use ($path, $contents) { $overwriteFile = $this->hasOption('force') ? $this->option('force') : false; (new FileGenerator($path, $contents))->withFileOverwrite($overwriteFile)->generate(); }); @@ -235,16 +235,18 @@ protected function mapFieldsFromModel(Model $model): array $label = title_from_key($item); if ($item === 'active') { - $fields[] = "{{ Field::checkbox(__('". $label ."'), '{$item}', ['value' => \$model->{$item}]) }}"; + $fields[] = "{{ Field::checkbox(__('".$label."'), '{$item}', ['value' => \$model->{$item}]) }}"; + continue; } if ($item === 'status') { - $fields[] = "{{ Field::select(__('". $label ."'), '{$item}')->dropDownList([]) }}"; + $fields[] = "{{ Field::select(__('".$label."'), '{$item}')->dropDownList([]) }}"; + continue; } - $fields[] = "{{ Field::text(__('". $label ."'), '{$item}', ['value' => \$model->{$item}]) }}"; + $fields[] = "{{ Field::text(__('".$label."'), '{$item}', ['value' => \$model->{$item}]) }}"; } return $fields; @@ -262,7 +264,7 @@ protected function getUrlPrefix(): string protected function getDatatableNamespace(Module $module): string { - return $this->getClassNamespace($module, 'Http\\DataTables', Str::plural($this->getModelName()) . "DataTable"); + return $this->getClassNamespace($module, 'Http\\DataTables', Str::plural($this->getModelName()).'DataTable'); } protected function getFormNamespace(Module $module): string @@ -270,9 +272,6 @@ protected function getFormNamespace(Module $module): string return $this->getClassNamespace($module, 'Http\\Forms', "{$this->getModelName()}Form"); } - /** - * @return string - */ protected function getControllerNameWithoutNamespace(): string { return class_basename($this->getControllerName()); @@ -306,8 +305,6 @@ protected function getModulePath(): string /** * Get class name. - * - * @return string */ protected function getClass(): string { @@ -321,8 +318,6 @@ protected function getModelName(): string /** * Get the console command arguments. - * - * @return array */ protected function getArguments(): array { diff --git a/src/Commands/Modules/Cruds/CrudMakeCommand.php b/src/Commands/Modules/Cruds/CrudMakeCommand.php index 1a0e20a..88c084a 100644 --- a/src/Commands/Modules/Cruds/CrudMakeCommand.php +++ b/src/Commands/Modules/Cruds/CrudMakeCommand.php @@ -1,9 +1,10 @@ getPath() . '/' . $this->getFileName(); + return $path.$factoryPath->getPath().'/'.$this->getFileName(); } /** @@ -78,7 +76,7 @@ protected function getDestinationFilePath() */ private function getFileName() { - return Str::studly($this->argument('name')) . 'Factory.php'; + return Str::studly($this->argument('name')).'Factory.php'; } /** @@ -91,8 +89,6 @@ private function getModelName() /** * Get default namespace. - * - * @return string */ public function getDefaultNamespace(): string { @@ -103,8 +99,6 @@ public function getDefaultNamespace(): string /** * Get model namespace. - * - * @return string */ public function getModelNamespace(): string { @@ -112,6 +106,6 @@ public function getModelNamespace(): string $path = str_replace('/', '\\', $path); - return $this->laravel['modules']->config('namespace') . '\\' . $this->laravel['modules']->findOrFail($this->getModuleName()) . '\\' . $path; + return $this->laravel['modules']->config('namespace').'\\'.$this->laravel['modules']->findOrFail($this->getModuleName()).'\\'.$path; } } diff --git a/src/Commands/Modules/Databases/MigrateCommand.php b/src/Commands/Modules/Databases/MigrateCommand.php index c8f1dd5..d110279 100644 --- a/src/Commands/Modules/Databases/MigrateCommand.php +++ b/src/Commands/Modules/Databases/MigrateCommand.php @@ -3,6 +3,7 @@ namespace Juzaweb\DevTool\Commands\Modules\Databases; use Illuminate\Console\Command; +use Juzaweb\Modules\Core\Modules\Contracts\RepositoryInterface; use Juzaweb\Modules\Core\Modules\Migrations\Migrator; use Juzaweb\Modules\Core\Modules\Module; use Symfony\Component\Console\Input\InputArgument; @@ -25,7 +26,7 @@ class MigrateCommand extends Command protected $description = 'Migrate the migrations from the specified module or from all modules.'; /** - * @var \Juzaweb\Modules\Core\Modules\Contracts\RepositoryInterface + * @var RepositoryInterface */ protected $module; @@ -49,7 +50,7 @@ public function handle(): int } foreach ($this->module->getOrdered($this->option('direction')) as $module) { - $this->line('Running for module: ' . $module->getName() . ''); + $this->line('Running for module: '.$module->getName().''); $this->migrate($module); } @@ -59,15 +60,13 @@ public function handle(): int /** * Run the migration from the specified module. - * - * @param Module $module */ protected function migrate(Module $module) { $path = str_replace(base_path(), '', (new Migrator($module, $this->getLaravel()))->getPath()); if ($this->option('subpath')) { - $path = $path . "/" . $this->option("subpath"); + $path = $path.'/'.$this->option('subpath'); } $this->call('migrate', [ diff --git a/src/Commands/Modules/Databases/MigrateFreshCommand.php b/src/Commands/Modules/Databases/MigrateFreshCommand.php index 0d5712e..d881157 100644 --- a/src/Commands/Modules/Databases/MigrateFreshCommand.php +++ b/src/Commands/Modules/Databases/MigrateFreshCommand.php @@ -32,7 +32,7 @@ public function handle(): int { $module = $this->argument('module'); - if ($module && !$this->getModuleName()) { + if ($module && ! $this->getModuleName()) { $this->error("Module [$module] does not exists."); return E_ERROR; @@ -80,7 +80,7 @@ public function getModuleName() { $module = $this->argument('module'); - if (!$module) { + if (! $module) { return null; } diff --git a/src/Commands/Modules/Databases/MigrateRefreshCommand.php b/src/Commands/Modules/Databases/MigrateRefreshCommand.php index de782a5..8f0a9f0 100644 --- a/src/Commands/Modules/Databases/MigrateRefreshCommand.php +++ b/src/Commands/Modules/Databases/MigrateRefreshCommand.php @@ -32,7 +32,7 @@ public function handle(): int { $module = $this->argument('module'); - if ($module && !$this->getModuleName()) { + if ($module && ! $this->getModuleName()) { $this->error("Module [$module] does not exists."); return E_ERROR; @@ -89,7 +89,7 @@ public function getModuleName() { $module = $this->argument('module'); - if (!$module) { + if (! $module) { return null; } diff --git a/src/Commands/Modules/Databases/MigrateResetCommand.php b/src/Commands/Modules/Databases/MigrateResetCommand.php index 12a8307..c3e5011 100644 --- a/src/Commands/Modules/Databases/MigrateResetCommand.php +++ b/src/Commands/Modules/Databases/MigrateResetCommand.php @@ -3,6 +3,7 @@ namespace Juzaweb\DevTool\Commands\Modules\Databases; use Illuminate\Console\Command; +use Juzaweb\Modules\Core\Modules\Contracts\RepositoryInterface; use Juzaweb\Modules\Core\Modules\Migrations\Migrator; use Juzaweb\Modules\Core\Modules\Traits\MigrationLoaderTrait; use Symfony\Component\Console\Input\InputArgument; @@ -27,7 +28,7 @@ class MigrateResetCommand extends Command protected $description = 'Reset the modules migrations.'; /** - * @var \Juzaweb\Modules\Core\Modules\Contracts\RepositoryInterface + * @var RepositoryInterface */ protected $module; @@ -40,14 +41,14 @@ public function handle(): int $name = $this->argument('module'); - if (!empty($name)) { + if (! empty($name)) { $this->reset($name); return 0; } foreach ($this->module->getOrdered($this->option('direction')) as $module) { - $this->line('Running for module: ' . $module->getName() . ''); + $this->line('Running for module: '.$module->getName().''); $this->reset($module); } @@ -57,8 +58,6 @@ public function handle(): int /** * Rollback migration from the specified module. - * - * @param $module */ public function reset($module) { @@ -70,7 +69,7 @@ public function reset($module) $database = $this->option('database'); - if (!empty($database)) { + if (! empty($database)) { $migrator->setDatabase($database); } diff --git a/src/Commands/Modules/Databases/MigrateRollbackCommand.php b/src/Commands/Modules/Databases/MigrateRollbackCommand.php index 4558e99..40a576c 100644 --- a/src/Commands/Modules/Databases/MigrateRollbackCommand.php +++ b/src/Commands/Modules/Databases/MigrateRollbackCommand.php @@ -3,6 +3,7 @@ namespace Juzaweb\DevTool\Commands\Modules\Databases; use Illuminate\Console\Command; +use Juzaweb\Modules\Core\Modules\Contracts\RepositoryInterface; use Juzaweb\Modules\Core\Modules\Migrations\Migrator; use Juzaweb\Modules\Core\Modules\Traits\MigrationLoaderTrait; use Symfony\Component\Console\Input\InputArgument; @@ -27,7 +28,7 @@ class MigrateRollbackCommand extends Command protected $description = 'Rollback the modules migrations.'; /** - * @var \Juzaweb\Modules\Core\Modules\Contracts\RepositoryInterface + * @var RepositoryInterface */ protected $module; @@ -40,14 +41,14 @@ public function handle(): int $name = $this->argument('module'); - if (!empty($name)) { + if (! empty($name)) { $this->rollback($name); return 0; } foreach ($this->module->getOrdered($this->option('direction')) as $module) { - $this->line('Running for module: ' . $module->getName() . ''); + $this->line('Running for module: '.$module->getName().''); $this->rollback($module); } @@ -57,8 +58,6 @@ public function handle(): int /** * Rollback migration from the specified module. - * - * @param $module */ public function rollback($module) { @@ -70,7 +69,7 @@ public function rollback($module) $database = $this->option('database'); - if (!empty($database)) { + if (! empty($database)) { $migrator->setDatabase($database); } diff --git a/src/Commands/Modules/Databases/MigrateStatusCommand.php b/src/Commands/Modules/Databases/MigrateStatusCommand.php index 263fca1..b39358f 100644 --- a/src/Commands/Modules/Databases/MigrateStatusCommand.php +++ b/src/Commands/Modules/Databases/MigrateStatusCommand.php @@ -3,6 +3,7 @@ namespace Juzaweb\DevTool\Commands\Modules\Databases; use Illuminate\Console\Command; +use Juzaweb\Modules\Core\Modules\Contracts\RepositoryInterface; use Juzaweb\Modules\Core\Modules\Migrations\Migrator; use Juzaweb\Modules\Core\Modules\Module; use Symfony\Component\Console\Input\InputArgument; @@ -25,7 +26,7 @@ class MigrateStatusCommand extends Command protected $description = 'Status for all module migrations'; /** - * @var \Juzaweb\Modules\Core\Modules\Contracts\RepositoryInterface + * @var RepositoryInterface */ protected $module; @@ -49,7 +50,7 @@ public function handle(): int } foreach ($this->module->getOrdered($this->option('direction')) as $module) { - $this->line('Running for module: ' . $module->getName() . ''); + $this->line('Running for module: '.$module->getName().''); $this->migrateStatus($module); } @@ -58,8 +59,6 @@ public function handle(): int /** * Run the migration from the specified module. - * - * @param Module $module */ protected function migrateStatus(Module $module) { diff --git a/src/Commands/Modules/Databases/MigrationMakeCommand.php b/src/Commands/Modules/Databases/MigrationMakeCommand.php index 34dc315..7dd77c9 100644 --- a/src/Commands/Modules/Databases/MigrationMakeCommand.php +++ b/src/Commands/Modules/Databases/MigrationMakeCommand.php @@ -67,9 +67,9 @@ public function getSchemaParser() } /** - * @throws \InvalidArgumentException - * * @return mixed + * + * @throws \InvalidArgumentException */ protected function getTemplateContents() { @@ -117,7 +117,7 @@ protected function getDestinationFilePath() $generatorPath = GenerateConfigReader::read('migration'); - return $path . $generatorPath->getPath() . '/' . $this->getFileName() . '.php'; + return $path.$generatorPath->getPath().'/'.$this->getFileName().'.php'; } /** @@ -125,7 +125,7 @@ protected function getDestinationFilePath() */ private function getFileName() { - return date('Y_m_d_His_') . $this->getSchemaName(); + return date('Y_m_d_His_').$this->getSchemaName(); } /** diff --git a/src/Commands/Modules/Databases/SeedCommand.php b/src/Commands/Modules/Databases/SeedCommand.php index 5eb1869..a2144c3 100644 --- a/src/Commands/Modules/Databases/SeedCommand.php +++ b/src/Commands/Modules/Databases/SeedCommand.php @@ -13,6 +13,7 @@ use RuntimeException; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; class SeedCommand extends Command { @@ -64,12 +65,11 @@ public function handle(): int /** * @throws RuntimeException - * @return RepositoryInterface */ public function getModuleRepository(): RepositoryInterface { $modules = $this->laravel['modules']; - if (!$modules instanceof RepositoryInterface) { + if (! $modules instanceof RepositoryInterface) { throw new RuntimeException('Module repository not found!'); } @@ -77,11 +77,9 @@ public function getModuleRepository(): RepositoryInterface } /** - * @param $name + * @return Module * * @throws RuntimeException - * - * @return Module */ public function getModuleByName($name) { @@ -94,8 +92,6 @@ public function getModuleByName($name) } /** - * @param Module $module - * * @return void */ public function moduleSeed(Module $module) @@ -104,17 +100,17 @@ public function moduleSeed(Module $module) $name = $module->getName(); $config = $module->get('migration'); if (is_array($config) && array_key_exists('seeds', $config)) { - foreach ((array)$config['seeds'] as $class) { + foreach ((array) $config['seeds'] as $class) { if (class_exists($class)) { $seeders[] = $class; } } } else { - $class = $this->getSeederName($name); //legacy support + $class = $this->getSeederName($name); // legacy support if (class_exists($class)) { $seeders[] = $class; } else { - //look at other namespaces + // look at other namespaces $classes = $this->getSeederNames($name); foreach ($classes as $class) { if (class_exists($class)) { @@ -133,12 +129,12 @@ public function moduleSeed(Module $module) /** * Seed the specified module. * - * @param string $className + * @param string $className */ protected function dbSeed($className) { if ($option = $this->option('class')) { - $params['--class'] = Str::finish(substr($className, 0, strrpos($className, '\\')), '\\') . $option; + $params['--class'] = Str::finish(substr($className, 0, strrpos($className, '\\')), '\\').$option; } else { $params = ['--class' => $className]; } @@ -157,8 +153,7 @@ protected function dbSeed($className) /** * Get master database seeder name for the specified module. * - * @param string $name - * + * @param string $name * @return string */ public function getSeederName($name) @@ -169,14 +164,13 @@ public function getSeederName($name) $config = GenerateConfigReader::read('seeder'); $seederPath = str_replace('/', '\\', $config->getPath()); - return $namespace . '\\' . $name . '\\' . $seederPath . '\\' . $name . 'DatabaseSeeder'; + return $namespace.'\\'.$name.'\\'.$seederPath.'\\'.$name.'DatabaseSeeder'; } /** * Get master database seeder name for the specified module under a different namespace than Modules. * - * @param string $name - * + * @param string $name * @return array $foundModules array containing namespace paths */ public function getSeederNames($name) @@ -189,7 +183,7 @@ public function getSeederNames($name) $foundModules = []; foreach ($this->laravel['modules']->config('scan.paths') as $path) { $namespace = array_slice(explode('/', $path), -1)[0]; - $foundModules[] = $namespace . '\\' . $name . '\\' . $seederPath . '\\' . $name . 'DatabaseSeeder'; + $foundModules[] = $namespace.'\\'.$name.'\\'.$seederPath.'\\'.$name.'DatabaseSeeder'; } return $foundModules; @@ -198,7 +192,7 @@ public function getSeederNames($name) /** * Report the exception to the exception handler. * - * @param \Symfony\Component\Console\Output\OutputInterface $output + * @param OutputInterface $output * @param \Throwable $e * @return void */ diff --git a/src/Commands/Modules/Databases/SeedMakeCommand.php b/src/Commands/Modules/Databases/SeedMakeCommand.php index f49f820..10ff7bf 100644 --- a/src/Commands/Modules/Databases/SeedMakeCommand.php +++ b/src/Commands/Modules/Databases/SeedMakeCommand.php @@ -13,8 +13,8 @@ class SeedMakeCommand extends GeneratorCommand { - use ModuleCommandTrait; use CanClearModulesCache; + use ModuleCommandTrait; protected string $argumentName = 'name'; @@ -88,7 +88,7 @@ protected function getDestinationFilePath() $seederPath = GenerateConfigReader::read('seeder'); - return $path . $seederPath->getPath() . '/' . $this->getSeederName() . '.php'; + return $path.$seederPath->getPath().'/'.$this->getSeederName().'.php'; } /** @@ -100,13 +100,11 @@ private function getSeederName() { $end = $this->option('master') ? 'DatabaseSeeder' : 'TableSeeder'; - return Str::studly($this->argument('name')) . $end; + return Str::studly($this->argument('name')).$end; } /** * Get default namespace. - * - * @return string */ public function getDefaultNamespace(): string { diff --git a/src/Commands/Modules/DatatableMakeCommand.php b/src/Commands/Modules/DatatableMakeCommand.php index 78b200b..4bceca8 100644 --- a/src/Commands/Modules/DatatableMakeCommand.php +++ b/src/Commands/Modules/DatatableMakeCommand.php @@ -34,8 +34,6 @@ class DatatableMakeCommand extends GeneratorCommand /** * The name of argument being used. - * - * @var string */ protected string $argumentName = 'datatable'; @@ -78,7 +76,7 @@ protected function mapActionsFromRepository(Module $module, GeneratorPath $confi return; } - if (!method_exists($repository, 'bulkActions')) { + if (! method_exists($repository, 'bulkActions')) { return; } @@ -95,9 +93,9 @@ protected function mapColumnsFromModel(Model $model, GeneratorPath $config): voi $makeColumns = array_diff($makeColumns, $config->get('excludeColumns', [])); - $this->columns[] = "Column::checkbox()"; - $this->columns[] = "Column::id()"; - $this->columns[] = "Column::actions()"; + $this->columns[] = 'Column::checkbox()'; + $this->columns[] = 'Column::id()'; + $this->columns[] = 'Column::actions()'; $hasTitle = false; foreach ($makeColumns as $item) { @@ -106,6 +104,7 @@ protected function mapColumnsFromModel(Model $model, GeneratorPath $config): voi $prefix = $this->getUrlPrefix(); $this->columns[] = "Column::editLink('{$item}', admin_url('{$prefix}/{id}/edit'), __('core::translation.label'))"; $hasTitle = true; + continue; } @@ -113,7 +112,7 @@ protected function mapColumnsFromModel(Model $model, GeneratorPath $config): voi } if ($model->usesTimestamps()) { - $this->columns[] = "Column::createdAt()"; + $this->columns[] = 'Column::createdAt()'; } } @@ -163,7 +162,7 @@ protected function getDestinationFilePath(): string $datatablePath = GenerateConfigReader::read('datatable'); - return $path . $datatablePath->getPath() . '/' . $this->getDatatableName() . '.php'; + return $path.$datatablePath->getPath().'/'.$this->getDatatableName().'.php'; } protected function getDatatableName(): string @@ -182,9 +181,6 @@ public function getDefaultNamespace(): string return \Juzaweb\Modules\Core\Facades\Module::config('paths.generator.datatable.namespace', 'Http/DataTables'); } - /** - * @return string - */ protected function getDatatableNameWithoutNamespace(): string { return class_basename($this->getDatatableName()); @@ -192,7 +188,6 @@ protected function getDatatableNameWithoutNamespace(): string /** * Get the stub file name based on the options - * @return string */ protected function getStubName(): string { @@ -201,8 +196,6 @@ protected function getStubName(): string /** * Get the console command arguments. - * - * @return array */ protected function getArguments(): array { @@ -214,8 +207,6 @@ protected function getArguments(): array /** * Get the console command options. - * - * @return array */ protected function getOptions(): ?array { diff --git a/src/Commands/Modules/DumpCommand.php b/src/Commands/Modules/DumpCommand.php index d27c63e..610e5f6 100644 --- a/src/Commands/Modules/DumpCommand.php +++ b/src/Commands/Modules/DumpCommand.php @@ -30,7 +30,7 @@ public function handle(): int { $this->components->info('Generating optimized autoload modules.'); - if ($name = $this->argument('module') ) { + if ($name = $this->argument('module')) { $this->dump($name); return 0; diff --git a/src/Commands/Modules/EventMakeCommand.php b/src/Commands/Modules/EventMakeCommand.php index fc7cc2e..d51ab69 100644 --- a/src/Commands/Modules/EventMakeCommand.php +++ b/src/Commands/Modules/EventMakeCommand.php @@ -40,11 +40,11 @@ public function getTemplateContents() public function getDestinationFilePath() { - $path = $this->laravel['modules']->getModulePath($this->getModuleName()); + $path = $this->laravel['modules']->getModulePath($this->getModuleName()); $eventPath = GenerateConfigReader::read('event'); - return $path . $eventPath->getPath() . '/' . $this->getFileName() . '.php'; + return $path.$eventPath->getPath().'/'.$this->getFileName().'.php'; } /** diff --git a/src/Commands/Modules/GeneratorCommand.php b/src/Commands/Modules/GeneratorCommand.php index aa5ef07..bb9ad68 100644 --- a/src/Commands/Modules/GeneratorCommand.php +++ b/src/Commands/Modules/GeneratorCommand.php @@ -11,8 +11,6 @@ abstract class GeneratorCommand extends Command { /** * The name of 'name' argument. - * - * @var string */ protected string $argumentName = ''; @@ -45,14 +43,14 @@ public function handle(): int $path = str_replace('\\', '/', $this->getDestinationFilePath()); - if (!$this->laravel['files']->isDirectory($dir = dirname($path))) { + if (! $this->laravel['files']->isDirectory($dir = dirname($path))) { $this->laravel['files']->makeDirectory($dir, 0777, true); } $contents = $this->getTemplateContents(); try { - $this->components->task("Generating file {$path}",function () use ($path,$contents) { + $this->components->task("Generating file {$path}", function () use ($path, $contents) { $overwriteFile = $this->hasOption('force') ? $this->option('force') : false; (new FileGenerator($path, $contents))->withFileOverwrite($overwriteFile)->generate(); }); @@ -82,8 +80,6 @@ public function getClass() /** * Get default namespace. - * - * @return string */ public function getDefaultNamespace(): string { @@ -92,19 +88,14 @@ public function getDefaultNamespace(): string /** * Get class namespace. - * - * @param Module $module - * @param string|null $defaultNamespace - * @param string|null $extra - * @return string */ public function getClassNamespace(Module $module, ?string $defaultNamespace = null, ?string $extra = null): string { $namespace = $this->laravel['modules']->config('namespace'); - $namespace .= '\\' . $module->getStudlyName(); + $namespace .= '\\'.$module->getStudlyName(); - $namespace .= '\\' . ($defaultNamespace ?? $this->getDefaultNamespace()); + $namespace .= '\\'.($defaultNamespace ?? $this->getDefaultNamespace()); if (! $extra) { $extra = str_replace($this->getClass(), '', $this->argument($this->argumentName)); @@ -112,7 +103,7 @@ public function getClassNamespace(Module $module, ?string $defaultNamespace = nu $extra = str_replace('/', '\\', $extra); } - $namespace .= '\\' . $extra; + $namespace .= '\\'.$extra; $namespace = str_replace('/', '\\', $namespace); diff --git a/src/Commands/Modules/JobMakeCommand.php b/src/Commands/Modules/JobMakeCommand.php index 28439ac..f95fba6 100644 --- a/src/Commands/Modules/JobMakeCommand.php +++ b/src/Commands/Modules/JobMakeCommand.php @@ -72,7 +72,7 @@ protected function getTemplateContents() return (new Stub($this->getStubName(), [ 'NAMESPACE' => $this->getClassNamespace($module), - 'CLASS' => $this->getClass(), + 'CLASS' => $this->getClass(), ]))->render(); } @@ -87,7 +87,7 @@ protected function getDestinationFilePath() $jobPath = GenerateConfigReader::read('jobs'); - return $path . $jobPath->getPath() . '/' . $this->getFileName() . '.php'; + return $path.$jobPath->getPath().'/'.$this->getFileName().'.php'; } /** @@ -98,9 +98,6 @@ private function getFileName() return Str::studly($this->argument('name')); } - /** - * @return string - */ protected function getStubName(): string { if ($this->option('sync')) { diff --git a/src/Commands/Modules/ListenerMakeCommand.php b/src/Commands/Modules/ListenerMakeCommand.php index f3e927e..0cec805 100644 --- a/src/Commands/Modules/ListenerMakeCommand.php +++ b/src/Commands/Modules/ListenerMakeCommand.php @@ -77,10 +77,10 @@ public function getDefaultNamespace(): string protected function getEventName(Module $module) { - $namespace = $this->laravel['modules']->config('namespace') . "\\" . $module->getStudlyName(); + $namespace = $this->laravel['modules']->config('namespace').'\\'.$module->getStudlyName(); $eventPath = GenerateConfigReader::read('event'); - $eventName = $namespace . "\\" . $eventPath->getNamespace() . "\\" . $this->option('event'); + $eventName = $namespace.'\\'.$eventPath->getNamespace().'\\'.$this->option('event'); return str_replace('/', '\\', $eventName); } @@ -96,7 +96,7 @@ protected function getDestinationFilePath() $listenerPath = GenerateConfigReader::read('listener'); - return $path . $listenerPath->getPath() . '/' . $this->getFileName() . '.php'; + return $path.$listenerPath->getPath().'/'.$this->getFileName().'.php'; } /** @@ -107,9 +107,6 @@ protected function getFileName() return Str::studly($this->argument('name')); } - /** - * @return string - */ protected function getStubName(): string { if ($this->option('queued')) { diff --git a/src/Commands/Modules/MailMakeCommand.php b/src/Commands/Modules/MailMakeCommand.php index 13564db..5233ef6 100644 --- a/src/Commands/Modules/MailMakeCommand.php +++ b/src/Commands/Modules/MailMakeCommand.php @@ -59,7 +59,7 @@ protected function getTemplateContents() return (new Stub('/mail.stub', [ 'NAMESPACE' => $this->getClassNamespace($module), - 'CLASS' => $this->getClass(), + 'CLASS' => $this->getClass(), ]))->render(); } @@ -74,7 +74,7 @@ protected function getDestinationFilePath() $mailPath = GenerateConfigReader::read('emails'); - return $path . $mailPath->getPath() . '/' . $this->getFileName() . '.php'; + return $path.$mailPath->getPath().'/'.$this->getFileName().'.php'; } /** diff --git a/src/Commands/Modules/MiddlewareMakeCommand.php b/src/Commands/Modules/MiddlewareMakeCommand.php index af4f4c8..1540ee4 100644 --- a/src/Commands/Modules/MiddlewareMakeCommand.php +++ b/src/Commands/Modules/MiddlewareMakeCommand.php @@ -14,8 +14,6 @@ class MiddlewareMakeCommand extends GeneratorCommand /** * The name of argument name. - * - * @var string */ protected string $argumentName = 'name'; @@ -62,7 +60,7 @@ protected function getTemplateContents() return (new Stub('/middleware.stub', [ 'NAMESPACE' => $this->getClassNamespace($module), - 'CLASS' => $this->getClass(), + 'CLASS' => $this->getClass(), ]))->render(); } @@ -75,7 +73,7 @@ protected function getDestinationFilePath() $middlewarePath = GenerateConfigReader::read('filter'); - return $path . $middlewarePath->getPath() . '/' . $this->getFileName() . '.php'; + return $path.$middlewarePath->getPath().'/'.$this->getFileName().'.php'; } /** diff --git a/src/Commands/Modules/ModelMakeCommand.php b/src/Commands/Modules/ModelMakeCommand.php index 018ea71..dea3fee 100644 --- a/src/Commands/Modules/ModelMakeCommand.php +++ b/src/Commands/Modules/ModelMakeCommand.php @@ -15,8 +15,6 @@ class ModelMakeCommand extends GeneratorCommand /** * The name of argument name. - * - * @var string */ protected string $argumentName = 'model'; @@ -52,7 +50,6 @@ public function handle(): int * Create a proper migration name: * ProductDetail: product_details * Product: products - * @return string */ private function createMigrationName(): string { @@ -72,8 +69,6 @@ private function createMigrationName(): string /** * Get the console command arguments. - * - * @return array */ protected function getArguments(): array { @@ -85,8 +80,6 @@ protected function getArguments(): array /** * Get the console command options. - * - * @return array */ protected function getOptions(): array { @@ -95,7 +88,7 @@ protected function getOptions(): array ['migration', 'm', InputOption::VALUE_NONE, 'Flag to create associated migrations', null], ['controller', 'c', InputOption::VALUE_NONE, 'Flag to create associated controllers', null], ['seed', 's', InputOption::VALUE_NONE, 'Create a new seeder for the model', null], - ['request', 'r', InputOption::VALUE_NONE, 'Create a new request for the model', null] + ['request', 'r', InputOption::VALUE_NONE, 'Create a new request for the model', null], ]; } @@ -137,7 +130,7 @@ protected function handleOptionalSeedOption() $this->call('module:make-seed', array_filter([ 'name' => $seedName, - 'module' => $this->argument('module') + 'module' => $this->argument('module'), ])); } } @@ -154,7 +147,7 @@ protected function handleOptionalRequestOption() $this->call('module:make-request', array_filter([ 'name' => $requestName, - 'module' => $this->argument('module') + 'module' => $this->argument('module'), ])); } } @@ -199,14 +192,11 @@ private function getModelName(): mixed return Str::studly($this->argument('model')); } - /** - * @return string - */ private function getFillable(): string { $fillable = $this->option('fillable'); - if (!is_null($fillable)) { + if (! is_null($fillable)) { $arrays = explode(',', $fillable); return json_encode($arrays, JSON_THROW_ON_ERROR); @@ -217,8 +207,6 @@ private function getFillable(): string /** * Get default namespace. - * - * @return string */ public function getDefaultNamespace(): string { diff --git a/src/Commands/Modules/ModelShowCommand.php b/src/Commands/Modules/ModelShowCommand.php index 34f0d95..387231e 100644 --- a/src/Commands/Modules/ModelShowCommand.php +++ b/src/Commands/Modules/ModelShowCommand.php @@ -2,6 +2,7 @@ namespace Juzaweb\DevTool\Commands\Modules; +use Illuminate\Console\GeneratorCommand; use Illuminate\Database\Console\ShowModelCommand; class ModelShowCommand extends ShowModelCommand @@ -40,14 +41,11 @@ class ModelShowCommand extends ShowModelCommand {--database= : The database connection to use} {--json : Output the model as JSON}'; - /** * Qualify the given model class base name. * - * @param string $model - * @return string * - * @see \Illuminate\Console\GeneratorCommand + * @see GeneratorCommand */ protected function qualifyModel(string $model): string { @@ -57,16 +55,15 @@ protected function qualifyModel(string $model): string $rootNamespace = config('modules.namespace'); - $modelPath = glob($rootNamespace . DIRECTORY_SEPARATOR . - '*' . DIRECTORY_SEPARATOR . - config('dev-tool.modules.paths.generator.model.path') . DIRECTORY_SEPARATOR . + $modelPath = glob($rootNamespace.DIRECTORY_SEPARATOR. + '*'.DIRECTORY_SEPARATOR. + config('dev-tool.modules.paths.generator.model.path').DIRECTORY_SEPARATOR. "$model.php"); - if (!count($modelPath)) { + if (! count($modelPath)) { return $model; } return str_replace(['/', '.php'], ['\\', ''], $modelPath[0]); } - } diff --git a/src/Commands/Modules/ModuleDeleteCommand.php b/src/Commands/Modules/ModuleDeleteCommand.php index 4a3d493..503723e 100644 --- a/src/Commands/Modules/ModuleDeleteCommand.php +++ b/src/Commands/Modules/ModuleDeleteCommand.php @@ -8,6 +8,7 @@ class ModuleDeleteCommand extends Command { protected $name = 'module:delete'; + protected $description = 'Delete a module from the application'; public function handle(): int diff --git a/src/Commands/Modules/ModuleMakeCommand.php b/src/Commands/Modules/ModuleMakeCommand.php index 06804ec..9e87ec0 100644 --- a/src/Commands/Modules/ModuleMakeCommand.php +++ b/src/Commands/Modules/ModuleMakeCommand.php @@ -42,7 +42,7 @@ public function handle(): int ->setComponent($this->components) ->setForce($this->option('force')) ->setType($this->getModuleType()) - ->setActive(!$this->option('disabled')) + ->setActive(! $this->option('disabled')) ->generate(); if ($code === E_ERROR) { @@ -77,10 +77,10 @@ protected function getOptions() } /** - * Get module type . - * - * @return string - */ + * Get module type . + * + * @return string + */ private function getModuleType() { $isPlain = $this->option('plain'); diff --git a/src/Commands/Modules/NotificationMakeCommand.php b/src/Commands/Modules/NotificationMakeCommand.php index 3df8d66..33bb389 100644 --- a/src/Commands/Modules/NotificationMakeCommand.php +++ b/src/Commands/Modules/NotificationMakeCommand.php @@ -46,7 +46,7 @@ protected function getTemplateContents() return (new Stub('/notification.stub', [ 'NAMESPACE' => $this->getClassNamespace($module), - 'CLASS' => $this->getClass(), + 'CLASS' => $this->getClass(), ]))->render(); } @@ -61,7 +61,7 @@ protected function getDestinationFilePath() $notificationPath = GenerateConfigReader::read('notifications'); - return $path . $notificationPath->getPath() . '/' . $this->getFileName() . '.php'; + return $path.$notificationPath->getPath().'/'.$this->getFileName().'.php'; } /** diff --git a/src/Commands/Modules/PolicyMakeCommand.php b/src/Commands/Modules/PolicyMakeCommand.php index 9a0c4ed..0c2651b 100644 --- a/src/Commands/Modules/PolicyMakeCommand.php +++ b/src/Commands/Modules/PolicyMakeCommand.php @@ -14,8 +14,6 @@ class PolicyMakeCommand extends GeneratorCommand /** * The name of argument name. - * - * @var string */ protected string $argumentName = 'name'; @@ -62,7 +60,7 @@ protected function getTemplateContents() return (new Stub('/policy.plain.stub', [ 'NAMESPACE' => $this->getClassNamespace($module), - 'CLASS' => $this->getClass(), + 'CLASS' => $this->getClass(), ]))->render(); } @@ -75,7 +73,7 @@ protected function getDestinationFilePath() $policyPath = GenerateConfigReader::read('policies'); - return $path . $policyPath->getPath() . '/' . $this->getFileName() . '.php'; + return $path.$policyPath->getPath().'/'.$this->getFileName().'.php'; } /** diff --git a/src/Commands/Modules/ProviderMakeCommand.php b/src/Commands/Modules/ProviderMakeCommand.php index 2331c35..d8cf7a0 100644 --- a/src/Commands/Modules/ProviderMakeCommand.php +++ b/src/Commands/Modules/ProviderMakeCommand.php @@ -16,8 +16,6 @@ class ProviderMakeCommand extends GeneratorCommand /** * The name of argument name. - * - * @var string */ protected string $argumentName = 'name'; diff --git a/src/Commands/Modules/PublishCommand.php b/src/Commands/Modules/PublishCommand.php index 8fad2be..d2cc770 100644 --- a/src/Commands/Modules/PublishCommand.php +++ b/src/Commands/Modules/PublishCommand.php @@ -53,8 +53,6 @@ public function publishAll() /** * Publish assets from the specified module. - * - * @param string|Module $name */ public function publish(string|Module $name) { @@ -69,7 +67,7 @@ public function publish(string|Module $name) ->setConsole($this) ->publish(); - $this->components->task($module->getStudlyName(), fn()=>true); + $this->components->task($module->getStudlyName(), fn () => true); } /** diff --git a/src/Commands/Modules/PublishConfigurationCommand.php b/src/Commands/Modules/PublishConfigurationCommand.php index 3684e63..c2ff2c3 100644 --- a/src/Commands/Modules/PublishConfigurationCommand.php +++ b/src/Commands/Modules/PublishConfigurationCommand.php @@ -44,7 +44,7 @@ public function handle(): int } /** - * @param string $module + * @param string $module * @return string */ private function getServiceProviderForModule($module) @@ -56,7 +56,7 @@ private function getServiceProviderForModule($module) } /** - * @param string $module + * @param string $module */ private function publishConfiguration($module) { diff --git a/src/Commands/Modules/PublishMigrationCommand.php b/src/Commands/Modules/PublishMigrationCommand.php index 34dee23..12ec7da 100644 --- a/src/Commands/Modules/PublishMigrationCommand.php +++ b/src/Commands/Modules/PublishMigrationCommand.php @@ -4,6 +4,7 @@ use Illuminate\Console\Command; use Juzaweb\Modules\Core\Modules\Migrations\Migrator; +use Juzaweb\Modules\Core\Modules\Module; use Juzaweb\Modules\Core\Modules\Publishing\MigrationPublisher; use Symfony\Component\Console\Input\InputArgument; @@ -48,7 +49,7 @@ public function handle(): int /** * Publish migration for the specified module. * - * @param \Juzaweb\Modules\Core\Modules\Module $module + * @param Module $module */ public function publish($module) { diff --git a/src/Commands/Modules/PublishTranslationCommand.php b/src/Commands/Modules/PublishTranslationCommand.php index 15f24fe..829ba57 100644 --- a/src/Commands/Modules/PublishTranslationCommand.php +++ b/src/Commands/Modules/PublishTranslationCommand.php @@ -54,7 +54,7 @@ public function publishAll() /** * Publish assets from the specified module. * - * @param string $name + * @param string $name */ public function publish($name) { diff --git a/src/Commands/Modules/RequestMakeCommand.php b/src/Commands/Modules/RequestMakeCommand.php index e80c53e..1ed3361 100644 --- a/src/Commands/Modules/RequestMakeCommand.php +++ b/src/Commands/Modules/RequestMakeCommand.php @@ -19,8 +19,6 @@ class RequestMakeCommand extends GeneratorCommand /** * The name of argument name. - * - * @var string */ protected string $argumentName = 'name'; @@ -81,9 +79,6 @@ public function getDefaultNamespace(): string return app(RepositoryInterface::class)->config('paths.generator.request.namespace', 'Http/Requests'); } - /** - * @return string - */ protected function getTemplateContents(): string { $module = app(RepositoryInterface::class)->findOrFail($this->getModuleName()); @@ -102,9 +97,6 @@ protected function getRules(): string return "[\n\t\t\t".implode(",\n\t\t\t", $this->rules)."\n\t\t]"; } - /** - * @return string - */ protected function getDestinationFilePath(): string { $path = app(RepositoryInterface::class)->getModulePath($this->getModuleName()); @@ -123,9 +115,6 @@ protected function getStubName(): string return '/requests/request.stub'; } - /** - * @return string - */ protected function getFileName(): string { return Str::studly($this->argument('name')); @@ -133,8 +122,6 @@ protected function getFileName(): string /** * Get the console command arguments. - * - * @return array */ protected function getArguments(): array { diff --git a/src/Commands/Modules/ResourceMakeCommand.php b/src/Commands/Modules/ResourceMakeCommand.php index 797aa5a..847194a 100644 --- a/src/Commands/Modules/ResourceMakeCommand.php +++ b/src/Commands/Modules/ResourceMakeCommand.php @@ -77,6 +77,7 @@ protected function mapFieldsFromModel(Model $model): void foreach ($columns as $column) { if ($this->collection()) { $this->fields[] = "'{$column}' => \$item->{$column}"; + continue; } @@ -99,9 +100,6 @@ protected function getFields(): string return "[\n\t\t\t\t\t".implode(",\n\t\t\t\t\t", $this->fields)."\n\t\t\t\t]"; } - /** - * @return string - */ protected function getTemplateContents(): string { $module = app(RepositoryInterface::class)->findOrFail($this->getModuleName()); @@ -115,9 +113,6 @@ protected function getTemplateContents(): string ]))->render(); } - /** - * @return string - */ protected function getDestinationFilePath(): string { $path = app(RepositoryInterface::class)->getModulePath($this->getModuleName()); @@ -127,9 +122,6 @@ protected function getDestinationFilePath(): string return $path.$resourcePath->getPath().'/'.$this->getFileName().'.php'; } - /** - * @return string - */ protected function getFileName(): string { return Str::studly($this->argument('name')); @@ -137,8 +129,6 @@ protected function getFileName(): string /** * Determine if the command is generating a resource collection. - * - * @return bool */ protected function collection(): bool { @@ -146,9 +136,6 @@ protected function collection(): bool Str::endsWith($this->argument('name'), 'Collection'); } - /** - * @return string - */ protected function getStubName(): string { if ($this->collection()) { @@ -168,8 +155,6 @@ protected function getStubName(): string /** * Get the console command arguments. - * - * @return array */ protected function getArguments(): array { diff --git a/src/Commands/Modules/RouteProviderMakeCommand.php b/src/Commands/Modules/RouteProviderMakeCommand.php index fc0a8f4..4bde5ff 100644 --- a/src/Commands/Modules/RouteProviderMakeCommand.php +++ b/src/Commands/Modules/RouteProviderMakeCommand.php @@ -57,14 +57,14 @@ protected function getTemplateContents() $module = $this->laravel['modules']->findOrFail($this->getModuleName()); return (new Stub('/route-provider.stub', [ - 'NAMESPACE' => $this->getClassNamespace($module), - 'CLASS' => $this->getFileName(), - 'MODULE_NAMESPACE' => $this->laravel['modules']->config('namespace'), - 'MODULE' => $this->getModuleName(), + 'NAMESPACE' => $this->getClassNamespace($module), + 'CLASS' => $this->getFileName(), + 'MODULE_NAMESPACE' => $this->laravel['modules']->config('namespace'), + 'MODULE' => $this->getModuleName(), 'CONTROLLER_NAMESPACE' => $this->getControllerNameSpace(), - 'WEB_ROUTES_PATH' => $this->getWebRoutesPath(), - 'API_ROUTES_PATH' => $this->getApiRoutesPath(), - 'LOWER_NAME' => $module->getLowerName(), + 'WEB_ROUTES_PATH' => $this->getWebRoutesPath(), + 'API_ROUTES_PATH' => $this->getApiRoutesPath(), + 'LOWER_NAME' => $module->getLowerName(), ]))->render(); } @@ -87,7 +87,7 @@ protected function getDestinationFilePath() $generatorPath = GenerateConfigReader::read('provider'); - return $path . $generatorPath->getPath() . '/' . $this->getFileName() . '.php'; + return $path.$generatorPath->getPath().'/'.$this->getFileName().'.php'; } /** @@ -95,7 +95,7 @@ protected function getDestinationFilePath() */ protected function getWebRoutesPath() { - return '/' . $this->laravel['modules']->config('stubs.files.routes/web', 'Routes/web.php'); + return '/'.$this->laravel['modules']->config('stubs.files.routes/web', 'Routes/web.php'); } /** @@ -103,7 +103,7 @@ protected function getWebRoutesPath() */ protected function getApiRoutesPath() { - return '/' . $this->laravel['modules']->config('stubs.files.routes/api', 'Routes/api.php'); + return '/'.$this->laravel['modules']->config('stubs.files.routes/api', 'Routes/api.php'); } public function getDefaultNamespace(): string @@ -113,9 +113,6 @@ public function getDefaultNamespace(): string return config('dev-tool.modules.paths.generator.provider.namespace') ?: config('dev-tool.modules.paths.generator.provider.path', 'Providers'); } - /** - * @return string - */ private function getControllerNameSpace(): string { $module = $this->laravel['modules']; diff --git a/src/Commands/Modules/RuleMakeCommand.php b/src/Commands/Modules/RuleMakeCommand.php index 4f3cbc4..221d9c6 100644 --- a/src/Commands/Modules/RuleMakeCommand.php +++ b/src/Commands/Modules/RuleMakeCommand.php @@ -14,8 +14,6 @@ class RuleMakeCommand extends GeneratorCommand /** * The name of argument name. - * - * @var string */ protected string $argumentName = 'name'; @@ -62,7 +60,7 @@ protected function getTemplateContents() return (new Stub('/rule.stub', [ 'NAMESPACE' => $this->getClassNamespace($module), - 'CLASS' => $this->getFileName(), + 'CLASS' => $this->getFileName(), ]))->render(); } @@ -75,7 +73,7 @@ protected function getDestinationFilePath() $rulePath = GenerateConfigReader::read('rules'); - return $path . $rulePath->getPath() . '/' . $this->getFileName() . '.php'; + return $path.$rulePath->getPath().'/'.$this->getFileName().'.php'; } /** diff --git a/src/Commands/Modules/SetupCommand.php b/src/Commands/Modules/SetupCommand.php index 7e0e923..63561ba 100644 --- a/src/Commands/Modules/SetupCommand.php +++ b/src/Commands/Modules/SetupCommand.php @@ -56,15 +56,10 @@ public function generateAssetsFolder() /** * Generate the specified directory by given $dir. - * - * @param $dir - * @param $success - * @param $error - * @return int */ protected function generateDirectory($dir, $success, $error): int { - if (!$this->laravel['files']->isDirectory($dir)) { + if (! $this->laravel['files']->isDirectory($dir)) { $this->laravel['files']->makeDirectory($dir, 0755, true, true); $this->components->info($success); diff --git a/src/Commands/Modules/TestMakeCommand.php b/src/Commands/Modules/TestMakeCommand.php index 1db781c..3b4e43e 100644 --- a/src/Commands/Modules/TestMakeCommand.php +++ b/src/Commands/Modules/TestMakeCommand.php @@ -14,7 +14,9 @@ class TestMakeCommand extends GeneratorCommand use ModuleCommandTrait; protected string $argumentName = 'name'; + protected $name = 'module:make-test'; + protected $description = 'Create a new test class for the specified module.'; public function getDefaultNamespace(): string @@ -67,7 +69,7 @@ protected function getTemplateContents() return (new Stub($stub, [ 'NAMESPACE' => $this->getClassNamespace($module), - 'CLASS' => $this->getClass(), + 'CLASS' => $this->getClass(), ]))->render(); } @@ -84,7 +86,7 @@ protected function getDestinationFilePath() $testPath = GenerateConfigReader::read('test'); } - return $path . $testPath->getPath() . '/' . $this->getFileName() . '.php'; + return $path.$testPath->getPath().'/'.$this->getFileName().'.php'; } /** diff --git a/src/Commands/Modules/UseCommand.php b/src/Commands/Modules/UseCommand.php index 98ae5e7..b5fd002 100644 --- a/src/Commands/Modules/UseCommand.php +++ b/src/Commands/Modules/UseCommand.php @@ -29,7 +29,7 @@ public function handle(): int { $module = Str::studly($this->argument('module')); - if (!$this->laravel['modules']->has($module)) { + if (! $this->laravel['modules']->has($module)) { $this->error("Module [{$module}] does not exists."); return E_ERROR; diff --git a/src/Commands/PublishAgentsCommand.php b/src/Commands/PublishAgentsCommand.php index 86cc15d..41fcfe4 100644 --- a/src/Commands/PublishAgentsCommand.php +++ b/src/Commands/PublishAgentsCommand.php @@ -27,23 +27,24 @@ class PublishAgentsCommand extends Command */ public function handle(Filesystem $files): int { - $baseSourcePath = dirname(__DIR__, 2) . '/agents'; + $baseSourcePath = dirname(__DIR__, 2).'/agents'; $destinationPath = base_path('.agent'); // Determine which folder to publish $folder = $this->getPublishFolder(); - $sourcePath = $folder ? $baseSourcePath . DIRECTORY_SEPARATOR . $folder : $baseSourcePath; + $sourcePath = $folder ? $baseSourcePath.DIRECTORY_SEPARATOR.$folder : $baseSourcePath; - if (!$files->isDirectory($sourcePath)) { + if (! $files->isDirectory($sourcePath)) { $this->components->error("Source directory does not exist: {$sourcePath}"); + return 1; } $this->components->info($folder ? "Publishing {$folder}..." : 'Publishing dev-tool agents...'); // Create destination directory if it doesn't exist - $targetDestination = $folder ? $destinationPath . DIRECTORY_SEPARATOR . $folder : $destinationPath; - if (!$files->isDirectory($targetDestination)) { + $targetDestination = $folder ? $destinationPath.DIRECTORY_SEPARATOR.$folder : $destinationPath; + if (! $files->isDirectory($targetDestination)) { $files->makeDirectory($targetDestination, 0755, true); } @@ -53,27 +54,27 @@ public function handle(Filesystem $files): int // Create directories first foreach ($directories as $directory) { - $relativePath = str_replace($sourcePath . DIRECTORY_SEPARATOR, '', $directory); - $targetDir = $targetDestination . DIRECTORY_SEPARATOR . $relativePath; + $relativePath = str_replace($sourcePath.DIRECTORY_SEPARATOR, '', $directory); + $targetDir = $targetDestination.DIRECTORY_SEPARATOR.$relativePath; - if (!$files->isDirectory($targetDir)) { + if (! $files->isDirectory($targetDir)) { $files->makeDirectory($targetDir, 0755, true); } } // Copy files foreach ($items as $file) { - $relativePath = str_replace($sourcePath . DIRECTORY_SEPARATOR, '', $file->getPathname()); - $targetPath = $targetDestination . DIRECTORY_SEPARATOR . $relativePath; + $relativePath = str_replace($sourcePath.DIRECTORY_SEPARATOR, '', $file->getPathname()); + $targetPath = $targetDestination.DIRECTORY_SEPARATOR.$relativePath; - if ($files->exists($targetPath) && !$this->option('force')) { - if (!$this->components->confirm("File already exists: {$relativePath}. Overwrite?")) { + if ($files->exists($targetPath) && ! $this->option('force')) { + if (! $this->components->confirm("File already exists: {$relativePath}. Overwrite?")) { continue; } } $files->copy($file->getPathname(), $targetPath); - $this->components->task($relativePath, fn() => true); + $this->components->task($relativePath, fn () => true); } $this->components->info('Agents published successfully!'); diff --git a/src/Commands/Themes/DownloadCommand.php b/src/Commands/Themes/DownloadCommand.php index c574812..449c620 100644 --- a/src/Commands/Themes/DownloadCommand.php +++ b/src/Commands/Themes/DownloadCommand.php @@ -1,10 +1,12 @@ getMessage(), 0, $e); + throw new \RuntimeException("HTTP request failed for {$url}: ".$e->getMessage(), 0, $e); } catch (\Throwable $e) { if (File::exists($path)) { File::delete($path); @@ -104,7 +106,7 @@ protected function getFileContent(string $url): string 'GET', $url, [ - 'verify' => false + 'verify' => false, ] )->getBody()->getContents(); } @@ -115,7 +117,7 @@ protected function curlGet(string $url): string $url, [ 'timeout' => 10, - 'verify' => false + 'verify' => false, ] ); diff --git a/src/Commands/Themes/DownloadStyleCommand.php b/src/Commands/Themes/DownloadStyleCommand.php index f26b84f..4568d5f 100644 --- a/src/Commands/Themes/DownloadStyleCommand.php +++ b/src/Commands/Themes/DownloadStyleCommand.php @@ -3,8 +3,8 @@ /** * JUZAWEB CMS - Laravel CMS for Your Project * - * @package juzaweb/cms * @author The Anh Dang + * * @link https://cms.juzaweb.com */ @@ -29,6 +29,7 @@ public function handle(): void $this->theme = \Juzaweb\Modules\Core\Facades\Theme::find($this->argument('theme')); if ($this->theme === null) { $this->error("Theme {$this->argument('theme')} not found!"); + return; } @@ -47,15 +48,15 @@ public function handle(): void protected function generateMixFile(array $css, array $js): void { - $mixOutput = 'themes/' . $this->theme->name() . '/assets'; + $mixOutput = 'themes/'.$this->theme->name().'/assets'; $cssList = array_map( - fn($item) => "basePath + '/css/" . basename(trim($item, "'")) . "'", + fn ($item) => "basePath + '/css/".basename(trim($item, "'"))."'", $css ); $jsList = array_map( - fn($item) => "basePath + '/js/" . basename(trim($item, "'")) . "'", + fn ($item) => "basePath + '/js/".basename(trim($item, "'"))."'", $js ); @@ -79,11 +80,11 @@ protected function generateMixFile(array $css, array $js): void mix.setPublicPath(publishPath); mix.styles([ - " . implode(",\n ", $cssList) . " + ".implode(",\n ", $cssList)." ], publishPath + '/css/main.min.css'); mix.combine([ - " . implode(",\n ", $jsList) . " + ".implode(",\n ", $jsList)." ], publishPath + '/js/main.min.js');"; File::put(base_path("{$mixOutput}/webpack.mix.js"), $mix); @@ -181,6 +182,7 @@ protected function downloadAssetsFromCssWithContent(string $content, string $css $assetUrl = trim($assetUrl, "\"'"); if (is_url($assetUrl) && $this->isExcludeDomain($assetUrl)) { $this->warn("Skip {$assetUrl}"); + continue; } @@ -198,7 +200,7 @@ protected function downloadAssetsFromCssWithContent(string $content, string $css continue; } - $savePath = $output . abs_path($urlPath); + $savePath = $output.abs_path($urlPath); try { $this->downloadFile($parsedUrl, base_path($savePath)); @@ -214,8 +216,9 @@ protected function downloadAssetsFromCss(array $cssFiles, string $cssUrl): void foreach ($cssFiles as $cssPath) { $fullPath = base_path(trim($cssPath, "'")); - if (!File::exists($fullPath)) { + if (! File::exists($fullPath)) { $this->warn("File {$fullPath} don't exists."); + continue; } @@ -227,18 +230,18 @@ protected function downloadAssetsFromCss(array $cssFiles, string $cssUrl): void protected function parseHref(string $href): string { if (str_starts_with($href, '//')) { - $href = 'https:' . $href; + $href = 'https:'.$href; } - if (!is_url($href)) { + if (! is_url($href)) { $baseUrl = explode('/', $this->data['url'])[0]; - $baseUrl .= '://' . get_domain_by_url($this->data['url']); + $baseUrl .= '://'.get_domain_by_url($this->data['url']); if (str_starts_with($href, '/')) { - $href = $baseUrl . trim($href); + $href = $baseUrl.trim($href); } else { $dir = dirname($this->data['url']); - $href = "{$dir}/" . trim($href); + $href = "{$dir}/".trim($href); } } diff --git a/src/Commands/Themes/DownloadTemplateCommand.php b/src/Commands/Themes/DownloadTemplateCommand.php index 764511c..367c75e 100644 --- a/src/Commands/Themes/DownloadTemplateCommand.php +++ b/src/Commands/Themes/DownloadTemplateCommand.php @@ -19,6 +19,7 @@ public function handle(): void $this->theme = \Juzaweb\Modules\Core\Facades\Theme::find($this->argument('theme')); if ($this->theme === null) { $this->error('Theme not found!'); + return; } @@ -62,7 +63,7 @@ protected function downloadFileAsks(): void $output = $this->theme->path('src/resources/views'); $path = "{$output}/{$this->data['file']}"; - if (!File::isDirectory(dirname($path))) { + if (! File::isDirectory(dirname($path))) { File::makeDirectory(dirname($path), 0755, true); } diff --git a/src/Commands/Themes/GenerateCommand.php b/src/Commands/Themes/GenerateCommand.php index 2df708d..7dd1b19 100644 --- a/src/Commands/Themes/GenerateCommand.php +++ b/src/Commands/Themes/GenerateCommand.php @@ -3,9 +3,10 @@ /** * JUZAWEB CMS - Laravel CMS for Your Project * - * @package juzaweb/cms * @author The Anh Dang + * * @link https://cms.juzaweb.com + * * @license GNU V2 */ @@ -21,11 +22,11 @@ abstract class GenerateCommand extends Command protected function getStyleProviderContents(Theme $theme): false|string { $providerFile = $theme->path('src/Providers/StyleServiceProvider.php'); - if (!file_exists($providerFile)) { + if (! file_exists($providerFile)) { $content = $this->generateContents( 'provider.stub', [ - 'NAMESPACE' => 'Juzaweb\\Themes\\' . Str::studly($theme->name()) . '\\Providers', + 'NAMESPACE' => 'Juzaweb\\Themes\\'.Str::studly($theme->name()).'\\Providers', 'CLASS' => 'StyleServiceProvider', ] ); @@ -40,7 +41,7 @@ protected function addToProviderBoot(string $code, string $content): string { $pattern = '/(public function boot\s*\(\)(?:\s*:\s*void)?\s*\{)([\s\S]*?)(^\s*\})/m'; - $replacement = '$1$2' . $code . '$3'; + $replacement = '$1$2'.$code.'$3'; return preg_replace($pattern, $replacement, $content); } @@ -49,7 +50,7 @@ protected function addUseClass(string $content, string $className): string { $useStatement = "use {$className};"; - if (!str_contains($content, $useStatement)) { + if (! str_contains($content, $useStatement)) { // Tìm vị trí cuối cùng của nhóm use hiện tại if (preg_match_all('/^use\s+[^;]+;/m', $content, $allMatches, PREG_OFFSET_CAPTURE)) { // $allMatches[0] is an array of matches; pick the last one diff --git a/src/Commands/Themes/MakeControllerCommand.php b/src/Commands/Themes/MakeControllerCommand.php index 7dfe63e..3ea0e48 100644 --- a/src/Commands/Themes/MakeControllerCommand.php +++ b/src/Commands/Themes/MakeControllerCommand.php @@ -3,9 +3,10 @@ /** * JUZAWEB CMS - Laravel CMS for Your Project * - * @package juzaweb/cms * @author The Anh Dang + * * @link https://cms.juzaweb.com + * * @license GNU V2 */ @@ -32,6 +33,7 @@ public function handle(): int if ($theme === null) { $this->error("Theme {$themeName} does not exist."); + return self::FAILURE; } @@ -41,15 +43,16 @@ public function handle(): int $controllerName .= 'Controller'; } - Stub::setBasePath(config('dev-tool.themes.stubs.path') . '/'); + Stub::setBasePath(config('dev-tool.themes.stubs.path').'/'); $controllerPath = $theme->path("src/Http/Controllers/{$controllerName}.php"); - if (file_exists($controllerPath) && !$this->option('force')) { + if (file_exists($controllerPath) && ! $this->option('force')) { $this->error("Controller {$controllerName} already exists!"); + return self::FAILURE; } - if (!File::isDirectory(dirname($controllerPath))) { + if (! File::isDirectory(dirname($controllerPath))) { File::makeDirectory(dirname($controllerPath), 0755, true); } @@ -62,6 +65,7 @@ public function handle(): int ); $this->info("Controller {$controllerPath} created successfully."); + return self::SUCCESS; } diff --git a/src/Commands/Themes/MakePageBlockCommand.php b/src/Commands/Themes/MakePageBlockCommand.php index 1f9baeb..437dbbd 100644 --- a/src/Commands/Themes/MakePageBlockCommand.php +++ b/src/Commands/Themes/MakePageBlockCommand.php @@ -26,10 +26,11 @@ public function handle(): int if ($theme === null) { $this->error("Theme {$themeName} does not exists."); + return self::FAILURE; } - Stub::setBasePath(config('dev-tool.themes.stubs.path') . '/'); + Stub::setBasePath(config('dev-tool.themes.stubs.path').'/'); if ($this->makeViews($theme, $name) === self::FAILURE) { return self::FAILURE; @@ -38,6 +39,7 @@ public function handle(): int $this->modifyProvider($theme, $name, $themeName); $this->info("Block {$name} created successfully."); + return self::SUCCESS; } @@ -47,13 +49,14 @@ protected function makeViews($theme, string $name): int $viewPath = $theme->path("src/resources/views/components/blocks/{$name}/view.blade.php"); if (file_exists($formPath) || file_exists($viewPath)) { - if (!$this->option('force')) { + if (! $this->option('force')) { $this->error("Block {$name} already exists!"); + return self::FAILURE; } } - if (!File::isDirectory(dirname($viewPath))) { + if (! File::isDirectory(dirname($viewPath))) { File::makeDirectory(dirname($viewPath), 0755, true); } @@ -77,11 +80,11 @@ protected function makeViews($theme, string $name): int protected function modifyProvider($theme, string $name, string $themeName): void { $providerFile = $theme->path('src/Providers/StyleServiceProvider.php'); - if (!file_exists($providerFile)) { + if (! file_exists($providerFile)) { $content = $this->generateContents( 'provider.stub', [ - 'NAMESPACE' => 'Juzaweb\\Themes\\' . Str::studly($theme->name()) . '\\Providers', + 'NAMESPACE' => 'Juzaweb\\Themes\\'.Str::studly($theme->name()).'\\Providers', 'CLASS' => 'StyleServiceProvider', ] ); @@ -98,25 +101,25 @@ protected function modifyProvider($theme, string $name, string $themeName): void protected function appendBlockToProvider(string $content, string $name, string $themeName): string { $pattern = '/(public function boot\s*\(\)(?:\s*:\s*void)?\s*\{)([\s\S]*?)(^\s*\})/m'; - $replacement = '$1$2' . " PageBlock::make( + $replacement = '$1$2'." PageBlock::make( '{$name}', function () { return [ - 'label' => __('" . title_from_key($name) . "'), + 'label' => __('".title_from_key($name)."'), 'form' => '{$themeName}::components.blocks.{$name}.form', 'view' => '{$themeName}::components.blocks.{$name}.view', ]; } - );\n" . '$3'; + );\n".'$3'; return preg_replace($pattern, $replacement, $content); } protected function addUseStatementToProvider(string $content): string { - $useStatement = "use Juzaweb\\Modules\\Admin\\Facades\\PageBlock;"; + $useStatement = 'use Juzaweb\\Modules\\Admin\\Facades\\PageBlock;'; - if (!str_contains($content, $useStatement)) { + if (! str_contains($content, $useStatement)) { // Tìm vị trí cuối cùng của nhóm use hiện tại if (preg_match_all('/^use\s+[^;]+;/m', $content, $allMatches, PREG_OFFSET_CAPTURE)) { // $allMatches[0] is an array of matches; pick the last one diff --git a/src/Commands/Themes/MakeTemplateCommand.php b/src/Commands/Themes/MakeTemplateCommand.php index a19ea92..ea56d5f 100644 --- a/src/Commands/Themes/MakeTemplateCommand.php +++ b/src/Commands/Themes/MakeTemplateCommand.php @@ -24,23 +24,26 @@ public function handle(): int if ($theme === null) { $this->error("Theme {$themeName} does not exists."); + return self::FAILURE; } - Stub::setBasePath(config('dev-tool.themes.stubs.path') . '/'); + Stub::setBasePath(config('dev-tool.themes.stubs.path').'/'); $templatePath = $theme->path("src/resources/views/templates/$name.blade.php"); - if (file_exists($templatePath) && !$this->option('force')) { + if (file_exists($templatePath) && ! $this->option('force')) { $this->error("Block {$name} already exists!"); + return self::FAILURE; } if ($name === 'home') { $this->error("Template name 'home' is index page reserved!"); + return self::FAILURE; } - if (!File::isDirectory(dirname($templatePath))) { + if (! File::isDirectory(dirname($templatePath))) { File::makeDirectory(dirname($templatePath), 0755, true); } @@ -57,7 +60,7 @@ public function handle(): int '{$name}', function () { return [ - 'label' => __('" . title_from_key($name) . "'), + 'label' => __('".title_from_key($name)."'), 'view' => '{$theme->name()}::templates.{$name}', 'blocks' => [ 'content' => __('core::translation.content'), @@ -67,12 +70,13 @@ function () { );\n"; $content = $this->addToProviderBoot($addContent, $content); - $useStatement = "Juzaweb\\Modules\\Admin\\Facades\\PageTemplate;"; + $useStatement = 'Juzaweb\\Modules\\Admin\\Facades\\PageTemplate;'; $newContent = $this->addUseClass($content, $useStatement); $this->writeStyleProvider($theme, $newContent); $this->info("Template {$templatePath} created successfully."); + return self::SUCCESS; } diff --git a/src/Commands/Themes/MakeViewCommand.php b/src/Commands/Themes/MakeViewCommand.php index a6dc256..1492829 100644 --- a/src/Commands/Themes/MakeViewCommand.php +++ b/src/Commands/Themes/MakeViewCommand.php @@ -23,18 +23,20 @@ public function handle(): int if ($theme === null) { $this->error("Theme {$themeName} does not exist."); + return self::FAILURE; } - Stub::setBasePath(config('dev-tool.themes.stubs.path') . '/'); + Stub::setBasePath(config('dev-tool.themes.stubs.path').'/'); $viewPath = $theme->path("src/resources/views/$name.blade.php"); - if (file_exists($viewPath) && !$this->option('force')) { + if (file_exists($viewPath) && ! $this->option('force')) { $this->error("View {$name} already exists!"); + return self::FAILURE; } - if (!File::isDirectory(dirname($viewPath))) { + if (! File::isDirectory(dirname($viewPath))) { File::makeDirectory(dirname($viewPath), 0755, true); } @@ -46,6 +48,7 @@ public function handle(): int ); $this->info("View {$viewPath} created successfully."); + return self::SUCCESS; } diff --git a/src/Commands/Themes/MakeWidgetCommand.php b/src/Commands/Themes/MakeWidgetCommand.php index 313eb56..33917d9 100644 --- a/src/Commands/Themes/MakeWidgetCommand.php +++ b/src/Commands/Themes/MakeWidgetCommand.php @@ -25,6 +25,7 @@ public function handle(): int if ($theme === null) { $this->error("Theme {$themeName} does not exist."); + return self::FAILURE; } @@ -32,13 +33,14 @@ public function handle(): int $formPath = $theme->path("src/resources/views/components/widgets/{$name}/form.blade.php"); if (file_exists($viewPath) || file_exists($formPath)) { - if (!$this->option('force')) { + if (! $this->option('force')) { $this->error("Widget {$name} already exists!"); + return self::FAILURE; } } - if (!File::isDirectory(dirname($viewPath))) { + if (! File::isDirectory(dirname($viewPath))) { File::makeDirectory(dirname($viewPath), 0755, true); } @@ -62,8 +64,9 @@ protected function injectIntoProvider($theme, $name) { $providerFile = $theme->path('src/Providers/ThemeServiceProvider.php'); - if (!file_exists($providerFile)) { + if (! file_exists($providerFile)) { $this->warn("ThemeServiceProvider.php not found at {$providerFile}"); + return; } @@ -75,8 +78,8 @@ protected function injectIntoProvider($theme, $name) '{$name}', function () { return [ - 'label' => __('" . $title . "'), - 'description' => __('" . $title . " Widget'), + 'label' => __('".$title."'), + 'description' => __('".$title." Widget'), 'view' => '{$themeName}::components.widgets.{$name}.show', 'form' => '{$themeName}::components.widgets.{$name}.form', ]; @@ -85,12 +88,12 @@ function () { $pattern = '/(public function boot\s*\(\)(?:\s*:\s*void)?\s*\{)([\s\S]*?)(^\s*\})/m'; if (preg_match($pattern, $content)) { - $replacement = '$1$2' . "\n" . $stub . '$3'; + $replacement = '$1$2'."\n".$stub.'$3'; $newContent = preg_replace($pattern, $replacement, $content); // Add Use statement - $useStatement = "use Juzaweb\\Modules\\Core\\Facades\\Widget;"; - if (!str_contains($newContent, $useStatement)) { + $useStatement = 'use Juzaweb\\Modules\\Core\\Facades\\Widget;'; + if (! str_contains($newContent, $useStatement)) { if (preg_match_all('/^use\s+[^;]+;/m', $newContent, $allMatches, PREG_OFFSET_CAPTURE)) { $lastMatch = end($allMatches[0]); $insertPos = $lastMatch[1] + strlen($lastMatch[0]); @@ -104,9 +107,9 @@ function () { } } file_put_contents($providerFile, $newContent); - $this->info("Registered widget in ThemeServiceProvider."); + $this->info('Registered widget in ThemeServiceProvider.'); } else { - $this->warn("Could not find boot method in ThemeServiceProvider to register widget."); + $this->warn('Could not find boot method in ThemeServiceProvider to register widget.'); } } diff --git a/src/Commands/Themes/ThemeGeneratorCommand.php b/src/Commands/Themes/ThemeGeneratorCommand.php index 50b4a69..51af5e7 100644 --- a/src/Commands/Themes/ThemeGeneratorCommand.php +++ b/src/Commands/Themes/ThemeGeneratorCommand.php @@ -27,29 +27,21 @@ class ThemeGeneratorCommand extends Command /** * Theme Folder Path. - * - * @var string */ protected string $themePath; /** * Create Theme Info. - * - * @var array */ protected array $theme; /** * Created Theme Structure. - * - * @var array */ protected array $themeFolders; /** * Theme Stubs. - * - * @var string */ protected string $themeStubPath; @@ -65,16 +57,16 @@ public function handle(): void /** * Theme Initialize. * - * @return void * @throws FileNotFoundException */ protected function init(): void { - $createdThemePath = $this->themePath . '/' . Str::kebab($this->theme['name']); + $createdThemePath = $this->themePath.'/'.Str::kebab($this->theme['name']); $force = $this->option('force'); - if (!$force && File::isDirectory($createdThemePath)) { - $this->error('Sorry, ' . Str::kebab($this->theme['name']) . ' Theme Folder Already Exist !!!'); + if (! $force && File::isDirectory($createdThemePath)) { + $this->error('Sorry, '.Str::kebab($this->theme['name']).' Theme Folder Already Exist !!!'); + return; } @@ -86,12 +78,12 @@ protected function init(): void $this->makeDir($createdThemePath); foreach ($this->themeFolders as $folder) { - $this->makeDir($createdThemePath . '/' . $folder); + $this->makeDir($createdThemePath.'/'.$folder); } $this->createStubs($themeStubFiles, $createdThemePath); - $this->info(ucfirst($this->theme['name']) . ' Theme Folder Successfully Generated !!!'); + $this->info(ucfirst($this->theme['name']).' Theme Folder Successfully Generated !!!'); // if ($this->confirm('Are you want to activate this theme?', true)) { // $this->call('theme:active', ['theme' => $this->theme['name']]); @@ -100,28 +92,22 @@ protected function init(): void /** * Console command ask questions. - * - * @return void */ public function generateThemeInfo(): void { $this->theme['title'] = $this->option('title') ?? Str::ucfirst($this->theme['name']); $this->theme['description'] = $this->option('description') - ?? Str::ucfirst($this->theme['name']) . ' description'; + ?? Str::ucfirst($this->theme['name']).' description'; $this->theme['author'] = $this->option('author'); $this->theme['version'] = $this->option('ver'); } /** * Make directory. - * - * @param string $directory - * - * @return void */ protected function makeDir(string $directory): void { - if (!File::isDirectory($directory)) { + if (! File::isDirectory($directory)) { File::makeDirectory($directory, 0755, true); } } @@ -129,28 +115,26 @@ protected function makeDir(string $directory): void /** * Create theme stubs. * - * @param array $themeStubFiles - * @param string $createdThemePath * @throws FileNotFoundException */ public function createStubs(array $themeStubFiles, string $createdThemePath): void { foreach ($themeStubFiles as $filename => $storePath) { if ($filename == 'changelog') { - $filename = 'changelog' . pathinfo($storePath, PATHINFO_EXTENSION); + $filename = 'changelog'.pathinfo($storePath, PATHINFO_EXTENSION); } elseif ($filename == 'theme') { $filename = pathinfo($storePath, PATHINFO_EXTENSION); } elseif ($filename == 'css' || $filename == 'js') { $this->theme[$filename] = ltrim( $storePath, - rtrim('assets', '/') . '/' + rtrim('assets', '/').'/' ); } $storePath = str_replace('[NAME]', Str::kebab($this->theme['name']), $storePath); - $themeStubFile = $this->themeStubPath . '/' . $filename . '.stub'; - $filePath = $createdThemePath . '/' . $storePath; + $themeStubFile = $this->themeStubPath.'/'.$filename.'.stub'; + $filePath = $createdThemePath.'/'.$storePath; if (! File::isDirectory(dirname($filePath))) { File::makeDirectory(dirname($filePath), 0755, true); @@ -163,10 +147,7 @@ public function createStubs(array $themeStubFiles, string $createdThemePath): vo /** * Make file. * - * @param string $file - * @param string $storePath * - * @return void * @throws FileNotFoundException */ protected function makeFile(string $file, string $storePath): void @@ -179,10 +160,6 @@ protected function makeFile(string $file, string $storePath): void /** * Replace Stub string. - * - * @param string $contents - * - * @return string */ protected function replaceStubs(string $contents): string { @@ -206,7 +183,7 @@ protected function replaceStubs(string $contents): string $this->theme['version'], $this->theme['css'] ?? 'assets/css/theme.css', $this->theme['js'] ?? 'assets/js/theme.js', - 'Juzaweb\\Themes\\' . Str::studly($this->theme['name']), + 'Juzaweb\\Themes\\'.Str::studly($this->theme['name']), Str::studly($this->theme['name']), ]; diff --git a/src/Commands/Themes/ThemeSeedCommand.php b/src/Commands/Themes/ThemeSeedCommand.php index d889ba2..f244af1 100644 --- a/src/Commands/Themes/ThemeSeedCommand.php +++ b/src/Commands/Themes/ThemeSeedCommand.php @@ -1,10 +1,12 @@ argument('theme')); - if (!$theme) { + if (! $theme) { $this->error('Theme not found.'); + return Command::FAILURE; } $seederClass = "Juzaweb\\Themes\\{$theme->studlyName()}\\Database\\Seeders\\DatabaseSeeder"; - if (!class_exists($seederClass)) { + if (! class_exists($seederClass)) { $this->error("Seeder not found for theme: {$theme->studlyName()}"); + return Command::FAILURE; } diff --git a/src/Generators/FileGenerator.php b/src/Generators/FileGenerator.php index 4a20abd..273728d 100644 --- a/src/Generators/FileGenerator.php +++ b/src/Generators/FileGenerator.php @@ -9,41 +9,31 @@ class FileGenerator extends Generator { /** * The path wil be used. - * - * @var string */ protected string $path; /** * The contens will be used. - * - * @var string */ protected string $contents; /** * The laravel filesystem or null. - * - * @var \Illuminate\Filesystem\Filesystem|null */ protected ?Filesystem $filesystem; - /** - * @var bool - */ + private bool $overwriteFile = false; /** * The constructor. * - * @param $path - * @param $contents - * @param null $filesystem + * @param null $filesystem */ public function __construct($path, $contents, $filesystem = null) { $this->path = $path; $this->contents = $contents; - $this->filesystem = $filesystem ?: new Filesystem(); + $this->filesystem = $filesystem ?: new Filesystem; } /** @@ -59,7 +49,6 @@ public function getContents() /** * Set contents. * - * @param mixed $contents * * @return $this */ @@ -83,7 +72,6 @@ public function getFilesystem() /** * Set filesystem. * - * @param Filesystem $filesystem * * @return $this */ @@ -107,7 +95,6 @@ public function getPath() /** * Set path. * - * @param mixed $path * * @return $this */ @@ -131,7 +118,7 @@ public function withFileOverwrite(bool $overwrite): FileGenerator public function generate() { $path = $this->getPath(); - if (!$this->filesystem->exists($path)) { + if (! $this->filesystem->exists($path)) { return $this->filesystem->put($path, $this->getContents()); } if ($this->overwriteFile === true) { diff --git a/src/Generators/Generator.php b/src/Generators/Generator.php index b4234ce..ae686e8 100644 --- a/src/Generators/Generator.php +++ b/src/Generators/Generator.php @@ -2,6 +2,4 @@ namespace Juzaweb\DevTool\Generators; -abstract class Generator -{ -} +abstract class Generator {} diff --git a/src/Generators/ModuleGenerator.php b/src/Generators/ModuleGenerator.php index c715e91..b2795a4 100644 --- a/src/Generators/ModuleGenerator.php +++ b/src/Generators/ModuleGenerator.php @@ -50,7 +50,6 @@ class ModuleGenerator extends Generator */ protected $component; - /** * The activator instance * @@ -88,11 +87,6 @@ class ModuleGenerator extends Generator /** * The constructor. - * @param $name - * @param FileRepository $module - * @param Config $config - * @param Filesystem $filesystem - * @param Console $console */ public function __construct( $name, @@ -113,7 +107,6 @@ public function __construct( /** * Set type. * - * @param string $type * * @return $this */ @@ -127,7 +120,6 @@ public function setType(string $type) /** * Set active flag. * - * @param bool $active * * @return $this */ @@ -171,7 +163,6 @@ public function getConfig() /** * Set the laravel config instance. * - * @param Config $config * * @return $this */ @@ -185,7 +176,6 @@ public function setConfig(Config $config) /** * Set the modules activator * - * @param ActivatorInterface $activator * * @return $this */ @@ -209,7 +199,6 @@ public function getFilesystem() /** * Set the laravel filesystem instance. * - * @param Filesystem $filesystem * * @return $this */ @@ -233,7 +222,6 @@ public function getConsole() /** * Set the laravel console instance. * - * @param Console $console * * @return $this */ @@ -244,21 +232,15 @@ public function setConsole(Console $console) return $this; } - /** - * @return Factory - */ public function getComponent(): Factory { return $this->component; } - /** - * @param Factory $component - * @return ModuleGenerator - */ public function setComponent(Factory $component): self { $this->component = $component; + return $this; } @@ -275,7 +257,6 @@ public function getModule() /** * Set the module instance. * - * @param mixed $module * * @return $this */ @@ -309,7 +290,6 @@ public function getFiles() /** * Set force status. * - * @param bool|int $force * * @return $this */ @@ -372,7 +352,7 @@ public function generateFolders() continue; } - $path = $this->module->getModulePath($this->getName()) . '/' . $folder->getPath(); + $path = $this->module->getModulePath($this->getName()).'/'.$folder->getPath(); $this->filesystem->makeDirectory($path, 0755, true); if (config('dev-tool.modules.stubs.gitkeep')) { @@ -383,12 +363,10 @@ public function generateFolders() /** * Generate git keep to the specified path. - * - * @param string $path */ public function generateGitKeep(string $path) { - $this->filesystem->put($path . '/.gitkeep', ''); + $this->filesystem->put($path.'/.gitkeep', ''); } /** @@ -397,10 +375,10 @@ public function generateGitKeep(string $path) public function generateFiles() { foreach ($this->getFiles() as $stub => $file) { - $path = $this->module->getModulePath($this->getName()) . $file; + $path = $this->module->getModulePath($this->getName()).$file; $this->component->task("Generating file {$path}", function () use ($stub, $path) { - if (!$this->filesystem->isDirectory($dir = dirname($path))) { + if (! $this->filesystem->isDirectory($dir = dirname($path))) { $this->filesystem->makeDirectory($dir, 0775, true); } @@ -424,7 +402,7 @@ public function generateResources() if (GenerateConfigReader::read('provider')->generate() === true) { $this->console->call('module:make-provider', [ - 'name' => $this->getName() . 'ServiceProvider', + 'name' => $this->getName().'ServiceProvider', 'module' => $this->getName(), '--master' => true, ]); @@ -445,14 +423,13 @@ public function generateResources() /** * Get the contents of the specified stub file by given stub name. * - * @param $stub * * @return string */ protected function getStubContents($stub) { return (new Stub( - '/' . $stub . '.stub', + '/'.$stub.'.stub', $this->getReplacement($stub) ) )->render(); @@ -469,7 +446,6 @@ public function getReplacements() /** * Get array replacement for the specified stub. * - * @param $stub * * @return array */ @@ -477,7 +453,7 @@ protected function getReplacement($stub) { $replacements = config('dev-tool.modules.stubs.replacements'); - if (!isset($replacements[$stub])) { + if (! isset($replacements[$stub])) { return []; } @@ -491,7 +467,7 @@ protected function getReplacement($stub) } } foreach ($keys as $key) { - if (method_exists($this, $method = 'get' . ucfirst(Str::studly(strtolower($key))) . 'Replacement')) { + if (method_exists($this, $method = 'get'.ucfirst(Str::studly(strtolower($key))).'Replacement')) { $replaces[$key] = $this->$method(); } else { $replaces[$key] = null; @@ -506,10 +482,10 @@ protected function getReplacement($stub) */ private function generateModuleJsonFile() { - $path = $this->module->getModulePath($this->getName()) . 'module.json'; + $path = $this->module->getModulePath($this->getName()).'module.json'; $this->component->task("Generating file $path", function () use ($path) { - if (!$this->filesystem->isDirectory($dir = dirname($path))) { + if (! $this->filesystem->isDirectory($dir = dirname($path))) { $this->filesystem->makeDirectory($dir, 0775, true); } @@ -523,13 +499,13 @@ private function generateModuleJsonFile() */ private function cleanModuleJsonFile() { - $path = $this->module->getModulePath($this->getName()) . 'module.json'; + $path = $this->module->getModulePath($this->getName()).'module.json'; $content = $this->filesystem->get($path); $namespace = $this->getModuleNamespaceReplacement(); $studlyName = $this->getStudlyNameReplacement(); - $provider = '"' . $namespace . '\\\\' . $studlyName . '\\\\Providers\\\\' . $studlyName . 'ServiceProvider"'; + $provider = '"'.$namespace.'\\\\'.$studlyName.'\\\\Providers\\\\'.$studlyName.'ServiceProvider"'; $content = str_replace($provider, '', $content); diff --git a/src/Providers/ConsoleServiceProvider.php b/src/Providers/ConsoleServiceProvider.php index 8836bc9..6d396f1 100644 --- a/src/Providers/ConsoleServiceProvider.php +++ b/src/Providers/ConsoleServiceProvider.php @@ -3,69 +3,121 @@ namespace Juzaweb\DevTool\Providers; use Illuminate\Support\ServiceProvider; +use Juzaweb\DevTool\Commands\Modules\CommandMakeCommand; +use Juzaweb\DevTool\Commands\Modules\ComponentClassMakeCommand; +use Juzaweb\DevTool\Commands\Modules\ComponentViewMakeCommand; +use Juzaweb\DevTool\Commands\Modules\ControllerMakeCommand; +use Juzaweb\DevTool\Commands\Modules\Cruds\AdminCrudMakeCommand; +use Juzaweb\DevTool\Commands\Modules\Cruds\APICrudMakeCommand; +use Juzaweb\DevTool\Commands\Modules\Cruds\CrudMakeCommand; +use Juzaweb\DevTool\Commands\Modules\Databases\FactoryMakeCommand; +use Juzaweb\DevTool\Commands\Modules\Databases\MigrateCommand; +use Juzaweb\DevTool\Commands\Modules\Databases\MigrateFreshCommand; +use Juzaweb\DevTool\Commands\Modules\Databases\MigrateRefreshCommand; +use Juzaweb\DevTool\Commands\Modules\Databases\MigrateResetCommand; +use Juzaweb\DevTool\Commands\Modules\Databases\MigrateRollbackCommand; +use Juzaweb\DevTool\Commands\Modules\Databases\MigrateStatusCommand; +use Juzaweb\DevTool\Commands\Modules\Databases\MigrationMakeCommand; +use Juzaweb\DevTool\Commands\Modules\Databases\SeedCommand; +use Juzaweb\DevTool\Commands\Modules\Databases\SeedMakeCommand; +use Juzaweb\DevTool\Commands\Modules\DatatableMakeCommand; +use Juzaweb\DevTool\Commands\Modules\DumpCommand; +use Juzaweb\DevTool\Commands\Modules\EventMakeCommand; +use Juzaweb\DevTool\Commands\Modules\JobMakeCommand; +use Juzaweb\DevTool\Commands\Modules\ListenerMakeCommand; +use Juzaweb\DevTool\Commands\Modules\MailMakeCommand; +use Juzaweb\DevTool\Commands\Modules\MiddlewareMakeCommand; +use Juzaweb\DevTool\Commands\Modules\ModelMakeCommand; +use Juzaweb\DevTool\Commands\Modules\ModelShowCommand; +use Juzaweb\DevTool\Commands\Modules\ModuleDeleteCommand; +use Juzaweb\DevTool\Commands\Modules\ModuleMakeCommand; +use Juzaweb\DevTool\Commands\Modules\NotificationMakeCommand; +use Juzaweb\DevTool\Commands\Modules\PolicyMakeCommand; +use Juzaweb\DevTool\Commands\Modules\ProviderMakeCommand; +use Juzaweb\DevTool\Commands\Modules\PublishCommand; +use Juzaweb\DevTool\Commands\Modules\PublishConfigurationCommand; +use Juzaweb\DevTool\Commands\Modules\PublishMigrationCommand; +use Juzaweb\DevTool\Commands\Modules\PublishTranslationCommand; +use Juzaweb\DevTool\Commands\Modules\RequestMakeCommand; +use Juzaweb\DevTool\Commands\Modules\ResourceMakeCommand; +use Juzaweb\DevTool\Commands\Modules\RouteProviderMakeCommand; +use Juzaweb\DevTool\Commands\Modules\RuleMakeCommand; +use Juzaweb\DevTool\Commands\Modules\SetupCommand; +use Juzaweb\DevTool\Commands\Modules\TestMakeCommand; +use Juzaweb\DevTool\Commands\Modules\UnUseCommand; +use Juzaweb\DevTool\Commands\Modules\UseCommand; +use Juzaweb\DevTool\Commands\PublishAgentsCommand; +use Juzaweb\DevTool\Commands\Themes\DownloadStyleCommand; +use Juzaweb\DevTool\Commands\Themes\DownloadTemplateCommand; +use Juzaweb\DevTool\Commands\Themes\MakeControllerCommand; +use Juzaweb\DevTool\Commands\Themes\MakePageBlockCommand; +use Juzaweb\DevTool\Commands\Themes\MakeTemplateCommand; +use Juzaweb\DevTool\Commands\Themes\MakeViewCommand; +use Juzaweb\DevTool\Commands\Themes\MakeWidgetCommand; +use Juzaweb\DevTool\Commands\Themes\ThemeGeneratorCommand; +use Juzaweb\DevTool\Commands\Themes\ThemeSeedCommand; use Juzaweb\Modules\Core\Modules\Support\Stub; class ConsoleServiceProvider extends ServiceProvider { /** * The available commands - * @var array */ protected array $commands = [ - \Juzaweb\DevTool\Commands\PublishAgentsCommand::class, - \Juzaweb\DevTool\Commands\Modules\CommandMakeCommand::class, - \Juzaweb\DevTool\Commands\Modules\ControllerMakeCommand::class, - \Juzaweb\DevTool\Commands\Modules\DumpCommand::class, - \Juzaweb\DevTool\Commands\Modules\EventMakeCommand::class, - \Juzaweb\DevTool\Commands\Modules\JobMakeCommand::class, - \Juzaweb\DevTool\Commands\Modules\ListenerMakeCommand::class, - \Juzaweb\DevTool\Commands\Modules\MailMakeCommand::class, - \Juzaweb\DevTool\Commands\Modules\MiddlewareMakeCommand::class, - \Juzaweb\DevTool\Commands\Modules\NotificationMakeCommand::class, - \Juzaweb\DevTool\Commands\Modules\ProviderMakeCommand::class, - \Juzaweb\DevTool\Commands\Modules\RouteProviderMakeCommand::class, - \Juzaweb\DevTool\Commands\Modules\ModuleDeleteCommand::class, - \Juzaweb\DevTool\Commands\Modules\ModuleMakeCommand::class, - \Juzaweb\DevTool\Commands\Modules\Databases\FactoryMakeCommand::class, - \Juzaweb\DevTool\Commands\Modules\PolicyMakeCommand::class, - \Juzaweb\DevTool\Commands\Modules\RequestMakeCommand::class, - \Juzaweb\DevTool\Commands\Modules\RuleMakeCommand::class, - \Juzaweb\DevTool\Commands\Modules\Databases\MigrateCommand::class, - \Juzaweb\DevTool\Commands\Modules\Databases\MigrateRefreshCommand::class, - \Juzaweb\DevTool\Commands\Modules\Databases\MigrateResetCommand::class, - \Juzaweb\DevTool\Commands\Modules\Databases\MigrateFreshCommand::class, - \Juzaweb\DevTool\Commands\Modules\Databases\MigrateRollbackCommand::class, - \Juzaweb\DevTool\Commands\Modules\Databases\MigrateStatusCommand::class, - \Juzaweb\DevTool\Commands\Modules\Databases\MigrationMakeCommand::class, - \Juzaweb\DevTool\Commands\Modules\ModelMakeCommand::class, - \Juzaweb\DevTool\Commands\Modules\ModelShowCommand::class, - \Juzaweb\DevTool\Commands\Modules\PublishCommand::class, - \Juzaweb\DevTool\Commands\Modules\PublishConfigurationCommand::class, - \Juzaweb\DevTool\Commands\Modules\PublishMigrationCommand::class, - \Juzaweb\DevTool\Commands\Modules\PublishTranslationCommand::class, - \Juzaweb\DevTool\Commands\Modules\Databases\SeedCommand::class, - \Juzaweb\DevTool\Commands\Modules\Databases\SeedMakeCommand::class, - \Juzaweb\DevTool\Commands\Modules\SetupCommand::class, - \Juzaweb\DevTool\Commands\Modules\UnUseCommand::class, - \Juzaweb\DevTool\Commands\Modules\UseCommand::class, - \Juzaweb\DevTool\Commands\Modules\ResourceMakeCommand::class, - \Juzaweb\DevTool\Commands\Modules\TestMakeCommand::class, - \Juzaweb\DevTool\Commands\Modules\ComponentClassMakeCommand::class, - \Juzaweb\DevTool\Commands\Modules\ComponentViewMakeCommand::class, - \Juzaweb\DevTool\Commands\Modules\DatatableMakeCommand::class, - \Juzaweb\DevTool\Commands\Modules\Cruds\AdminCrudMakeCommand::class, - \Juzaweb\DevTool\Commands\Modules\Cruds\APICrudMakeCommand::class, - \Juzaweb\DevTool\Commands\Modules\Cruds\CrudMakeCommand::class, + PublishAgentsCommand::class, + CommandMakeCommand::class, + ControllerMakeCommand::class, + DumpCommand::class, + EventMakeCommand::class, + JobMakeCommand::class, + ListenerMakeCommand::class, + MailMakeCommand::class, + MiddlewareMakeCommand::class, + NotificationMakeCommand::class, + ProviderMakeCommand::class, + RouteProviderMakeCommand::class, + ModuleDeleteCommand::class, + ModuleMakeCommand::class, + FactoryMakeCommand::class, + PolicyMakeCommand::class, + RequestMakeCommand::class, + RuleMakeCommand::class, + MigrateCommand::class, + MigrateRefreshCommand::class, + MigrateResetCommand::class, + MigrateFreshCommand::class, + MigrateRollbackCommand::class, + MigrateStatusCommand::class, + MigrationMakeCommand::class, + ModelMakeCommand::class, + ModelShowCommand::class, + PublishCommand::class, + PublishConfigurationCommand::class, + PublishMigrationCommand::class, + PublishTranslationCommand::class, + SeedCommand::class, + SeedMakeCommand::class, + SetupCommand::class, + UnUseCommand::class, + UseCommand::class, + ResourceMakeCommand::class, + TestMakeCommand::class, + ComponentClassMakeCommand::class, + ComponentViewMakeCommand::class, + DatatableMakeCommand::class, + AdminCrudMakeCommand::class, + APICrudMakeCommand::class, + CrudMakeCommand::class, // Theme commands - \Juzaweb\DevTool\Commands\Themes\DownloadStyleCommand::class, - \Juzaweb\DevTool\Commands\Themes\DownloadTemplateCommand::class, - \Juzaweb\DevTool\Commands\Themes\MakeControllerCommand::class, - \Juzaweb\DevTool\Commands\Themes\MakePageBlockCommand::class, - \Juzaweb\DevTool\Commands\Themes\MakeTemplateCommand::class, - \Juzaweb\DevTool\Commands\Themes\MakeViewCommand::class, - \Juzaweb\DevTool\Commands\Themes\MakeWidgetCommand::class, - \Juzaweb\DevTool\Commands\Themes\ThemeGeneratorCommand::class, - \Juzaweb\DevTool\Commands\Themes\ThemeSeedCommand::class, + DownloadStyleCommand::class, + DownloadTemplateCommand::class, + MakeControllerCommand::class, + MakePageBlockCommand::class, + MakeTemplateCommand::class, + MakeViewCommand::class, + MakeWidgetCommand::class, + ThemeGeneratorCommand::class, + ThemeSeedCommand::class, ]; public function boot() @@ -107,7 +159,7 @@ public function provides(): array */ protected function registerNamespaces() { - $stubsPath = dirname(__DIR__, 2) . '/stubs'; + $stubsPath = dirname(__DIR__, 2).'/stubs'; $this->publishes([ $stubsPath => resource_path('stubs'), diff --git a/src/Providers/DevToolServiceProvider.php b/src/Providers/DevToolServiceProvider.php index 078470e..ecd351d 100644 --- a/src/Providers/DevToolServiceProvider.php +++ b/src/Providers/DevToolServiceProvider.php @@ -9,7 +9,7 @@ class DevToolServiceProvider extends ServiceProvider { public function register() { - $this->mergeConfigFrom(__DIR__ . '/../../config/dev-tool.php', 'dev-tool'); + $this->mergeConfigFrom(__DIR__.'/../../config/dev-tool.php', 'dev-tool'); $this->app->register(ConsoleServiceProvider::class); } diff --git a/tests/TestCase.php b/tests/TestCase.php index ae03d24..96058d0 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -3,7 +3,10 @@ namespace Juzaweb\DevTool\Tests; use Juzaweb\DevTool\Providers\DevToolServiceProvider; +use Juzaweb\Modules\Core\Facades\Module; +use Juzaweb\Modules\Core\Facades\Theme; use Juzaweb\Modules\Core\Providers\CoreServiceProvider; +use Juzaweb\QueryCache\QueryCacheServiceProvider; use Orchestra\Testbench\TestCase as BaseTestCase; abstract class TestCase extends BaseTestCase @@ -11,7 +14,7 @@ abstract class TestCase extends BaseTestCase protected function getPackageProviders($app) { return [ - \Juzaweb\QueryCache\QueryCacheServiceProvider::class, + QueryCacheServiceProvider::class, CoreServiceProvider::class, DevToolServiceProvider::class, ]; @@ -20,8 +23,8 @@ protected function getPackageProviders($app) protected function getPackageAliases($app) { return [ - 'Theme' => \Juzaweb\Modules\Core\Facades\Theme::class, - 'Module' => \Juzaweb\Modules\Core\Facades\Module::class, + 'Theme' => Theme::class, + 'Module' => Module::class, ]; } } diff --git a/tests/Unit/CommandMakeCommandTest.php b/tests/Unit/CommandMakeCommandTest.php index 56837e6..697d321 100644 --- a/tests/Unit/CommandMakeCommandTest.php +++ b/tests/Unit/CommandMakeCommandTest.php @@ -16,13 +16,13 @@ protected function setUp(): void $this->app['config']->set('modules.paths.modules', base_path('modules')); $this->app['config']->set('modules.paths.generator.command.path', 'src/Commands'); $this->app['config']->set('modules.paths.generator.command.generate', true); - $this->app['config']->set('dev-tool.modules.stubs.path', dirname(__DIR__, 2) . '/stubs/modules/'); - $this->app['config']->set('modules.stubs.path', dirname(__DIR__, 2) . '/stubs/modules/'); + $this->app['config']->set('dev-tool.modules.stubs.path', dirname(__DIR__, 2).'/stubs/modules/'); + $this->app['config']->set('modules.stubs.path', dirname(__DIR__, 2).'/stubs/modules/'); - Stub::setBasePath(dirname(__DIR__, 2) . '/stubs/modules/'); + Stub::setBasePath(dirname(__DIR__, 2).'/stubs/modules/'); // Create a dummy module - if (!File::isDirectory(base_path('modules/Blog'))) { + if (! File::isDirectory(base_path('modules/Blog'))) { File::makeDirectory(base_path('modules/Blog'), 0755, true); } @@ -37,7 +37,7 @@ protected function setUp(): void 'providers' => [], 'aliases' => [], 'files' => [], - 'requires' => [] + 'requires' => [], ])); } diff --git a/tests/Unit/ComponentClassMakeCommandTest.php b/tests/Unit/ComponentClassMakeCommandTest.php index 5baefac..f92cc82 100644 --- a/tests/Unit/ComponentClassMakeCommandTest.php +++ b/tests/Unit/ComponentClassMakeCommandTest.php @@ -25,13 +25,13 @@ protected function setUp(): void $this->app['config']->set('modules.paths.generator.component-view.generate', true); // Stubs path - $this->app['config']->set('dev-tool.modules.stubs.path', dirname(__DIR__, 2) . '/stubs/modules/'); - $this->app['config']->set('modules.stubs.path', dirname(__DIR__, 2) . '/stubs/modules/'); + $this->app['config']->set('dev-tool.modules.stubs.path', dirname(__DIR__, 2).'/stubs/modules/'); + $this->app['config']->set('modules.stubs.path', dirname(__DIR__, 2).'/stubs/modules/'); - Stub::setBasePath(dirname(__DIR__, 2) . '/stubs/modules/'); + Stub::setBasePath(dirname(__DIR__, 2).'/stubs/modules/'); // Create a dummy module - if (!File::isDirectory(base_path('modules/Blog'))) { + if (! File::isDirectory(base_path('modules/Blog'))) { File::makeDirectory(base_path('modules/Blog'), 0755, true); } @@ -46,7 +46,7 @@ protected function setUp(): void 'providers' => [], 'aliases' => [], 'files' => [], - 'requires' => [] + 'requires' => [], ])); } diff --git a/tests/Unit/CrudMakeCommandTest.php b/tests/Unit/CrudMakeCommandTest.php index e2520c6..27daf87 100644 --- a/tests/Unit/CrudMakeCommandTest.php +++ b/tests/Unit/CrudMakeCommandTest.php @@ -4,8 +4,8 @@ use Illuminate\Support\Facades\File; use Juzaweb\DevTool\Tests\TestCase; -use Juzaweb\Modules\Core\Modules\Support\Stub; use Juzaweb\Modules\Core\Models\Model; +use Juzaweb\Modules\Core\Modules\Support\Stub; class CrudMakeCommandTest extends TestCase { @@ -37,7 +37,7 @@ protected function setUp(): void $this->app['config']->set('modules.paths.generator.routes.generate', true); // Stubs path - $stubsPath = dirname(__DIR__, 2) . '/stubs/modules/'; + $stubsPath = dirname(__DIR__, 2).'/stubs/modules/'; $this->app['config']->set('dev-tool.modules.stubs.path', $stubsPath); $this->app['config']->set('modules.stubs.path', $stubsPath); @@ -61,7 +61,7 @@ protected function setUp(): void 'providers' => [], 'aliases' => [], 'files' => [], - 'requires' => [] + 'requires' => [], ])); // Create routes file diff --git a/tests/Unit/DatatableMakeCommandTest.php b/tests/Unit/DatatableMakeCommandTest.php index 8579598..6aa013f 100644 --- a/tests/Unit/DatatableMakeCommandTest.php +++ b/tests/Unit/DatatableMakeCommandTest.php @@ -17,13 +17,13 @@ protected function setUp(): void $this->app['config']->set('modules.paths.generator.datatable.path', 'src/Http/DataTables'); $this->app['config']->set('modules.paths.generator.datatable.generate', true); $this->app['config']->set('modules.paths.generator.datatable.namespace', 'Http/DataTables'); - $this->app['config']->set('dev-tool.modules.stubs.path', dirname(__DIR__, 2) . '/stubs/modules/'); - $this->app['config']->set('modules.stubs.path', dirname(__DIR__, 2) . '/stubs/modules/'); + $this->app['config']->set('dev-tool.modules.stubs.path', dirname(__DIR__, 2).'/stubs/modules/'); + $this->app['config']->set('modules.stubs.path', dirname(__DIR__, 2).'/stubs/modules/'); - Stub::setBasePath(dirname(__DIR__, 2) . '/stubs/modules/'); + Stub::setBasePath(dirname(__DIR__, 2).'/stubs/modules/'); // Create a dummy module - if (!File::isDirectory(base_path('modules/Blog'))) { + if (! File::isDirectory(base_path('modules/Blog'))) { File::makeDirectory(base_path('modules/Blog'), 0755, true); } @@ -38,7 +38,7 @@ protected function setUp(): void 'providers' => [], 'aliases' => [], 'files' => [], - 'requires' => [] + 'requires' => [], ])); } diff --git a/tests/Unit/DownloadStyleCommandTest.php b/tests/Unit/DownloadStyleCommandTest.php index 6f22211..82ab39b 100644 --- a/tests/Unit/DownloadStyleCommandTest.php +++ b/tests/Unit/DownloadStyleCommandTest.php @@ -7,8 +7,11 @@ use GuzzleHttp\HandlerStack; use GuzzleHttp\Psr7\Response; use Illuminate\Support\Facades\File; +use Juzaweb\DevTool\Commands\Themes\DownloadStyleCommand; use Juzaweb\DevTool\Tests\TestCase; use Juzaweb\Modules\Core\Facades\Theme; +use Symfony\Component\Console\Input\ArrayInput; +use Symfony\Component\Console\Output\BufferedOutput; class DownloadStyleCommandTest extends TestCase { @@ -17,7 +20,7 @@ protected function setUp(): void parent::setUp(); $this->app['config']->set('themes.path', base_path('themes')); - $stubsPath = dirname(__DIR__, 2) . '/stubs/themes'; + $stubsPath = dirname(__DIR__, 2).'/stubs/themes'; $this->app['config']->set('dev-tool.themes.stubs.path', $stubsPath); if (File::isDirectory(base_path('themes'))) { @@ -49,7 +52,7 @@ public function test_download_style() $handlerStack = HandlerStack::create($mock); $client = new Client(['handler' => $handlerStack]); - $command = $this->getMockBuilder(\Juzaweb\DevTool\Commands\Themes\DownloadStyleCommand::class) + $command = $this->getMockBuilder(DownloadStyleCommand::class) ->setConstructorArgs([$client]) ->onlyMethods(['ask']) ->getMock(); @@ -57,14 +60,14 @@ public function test_download_style() $command->method('ask')->willReturn('http://example.com'); $command->setLaravel($this->app); - $input = new \Symfony\Component\Console\Input\ArrayInput([ + $input = new ArrayInput([ 'theme' => 'test-theme', ]); - $output = new \Symfony\Component\Console\Output\BufferedOutput(); + $output = new BufferedOutput; // Create necessary directory for generateMixFile $mixDir = base_path('themes/test-theme/assets'); - if (!File::isDirectory($mixDir)) { + if (! File::isDirectory($mixDir)) { File::makeDirectory($mixDir, 0755, true); } diff --git a/tests/Unit/DumpCommandTest.php b/tests/Unit/DumpCommandTest.php index eeb1dec..2dd923d 100644 --- a/tests/Unit/DumpCommandTest.php +++ b/tests/Unit/DumpCommandTest.php @@ -2,6 +2,7 @@ namespace Juzaweb\DevTool\Tests\Unit; +use Illuminate\Contracts\Console\Kernel; use Juzaweb\DevTool\Commands\Modules\DumpCommand; use Juzaweb\DevTool\Tests\TestCase; use Mockery; @@ -16,10 +17,10 @@ protected function tearDown(): void public function test_it_dumps_specific_module() { - $command = Mockery::mock(DumpCommand::class . '[dump]')->makePartial(); + $command = Mockery::mock(DumpCommand::class.'[dump]')->makePartial(); $command->shouldReceive('dump')->with('Blog')->once(); - $this->app[\Illuminate\Contracts\Console\Kernel::class]->registerCommand($command); + $this->app[Kernel::class]->registerCommand($command); $this->artisan('module:dump', ['module' => 'Blog']) ->assertExitCode(0); @@ -27,10 +28,10 @@ public function test_it_dumps_specific_module() public function test_it_dumps_all_modules() { - $command = Mockery::mock(DumpCommand::class . '[dumpAll]')->makePartial(); + $command = Mockery::mock(DumpCommand::class.'[dumpAll]')->makePartial(); $command->shouldReceive('dumpAll')->once(); - $this->app[\Illuminate\Contracts\Console\Kernel::class]->registerCommand($command); + $this->app[Kernel::class]->registerCommand($command); $this->artisan('module:dump') ->assertExitCode(0); diff --git a/tests/Unit/EventMakeCommandTest.php b/tests/Unit/EventMakeCommandTest.php index fc01847..72122b4 100644 --- a/tests/Unit/EventMakeCommandTest.php +++ b/tests/Unit/EventMakeCommandTest.php @@ -17,13 +17,13 @@ protected function setUp(): void $this->app['config']->set('modules.namespace', 'Juzaweb\\Modules'); $this->app['config']->set('modules.paths.generator.event.path', 'src/Events'); $this->app['config']->set('modules.paths.generator.event.generate', true); - $this->app['config']->set('dev-tool.modules.stubs.path', dirname(__DIR__, 2) . '/stubs/modules/'); - $this->app['config']->set('modules.stubs.path', dirname(__DIR__, 2) . '/stubs/modules/'); + $this->app['config']->set('dev-tool.modules.stubs.path', dirname(__DIR__, 2).'/stubs/modules/'); + $this->app['config']->set('modules.stubs.path', dirname(__DIR__, 2).'/stubs/modules/'); - Stub::setBasePath(dirname(__DIR__, 2) . '/stubs/modules/'); + Stub::setBasePath(dirname(__DIR__, 2).'/stubs/modules/'); // Create a dummy module - if (!File::isDirectory(base_path('modules/Blog'))) { + if (! File::isDirectory(base_path('modules/Blog'))) { File::makeDirectory(base_path('modules/Blog'), 0755, true); } @@ -38,7 +38,7 @@ protected function setUp(): void 'providers' => [], 'aliases' => [], 'files' => [], - 'requires' => [] + 'requires' => [], ])); } diff --git a/tests/Unit/FactoryMakeCommandTest.php b/tests/Unit/FactoryMakeCommandTest.php index c25eb34..c74f699 100644 --- a/tests/Unit/FactoryMakeCommandTest.php +++ b/tests/Unit/FactoryMakeCommandTest.php @@ -26,13 +26,13 @@ protected function setUp(): void $this->app['config']->set('dev-tool.modules.paths.generator.model.namespace', 'Models'); // Stubs path - $this->app['config']->set('dev-tool.modules.stubs.path', dirname(__DIR__, 2) . '/stubs/modules/'); - $this->app['config']->set('modules.stubs.path', dirname(__DIR__, 2) . '/stubs/modules/'); + $this->app['config']->set('dev-tool.modules.stubs.path', dirname(__DIR__, 2).'/stubs/modules/'); + $this->app['config']->set('modules.stubs.path', dirname(__DIR__, 2).'/stubs/modules/'); - Stub::setBasePath(dirname(__DIR__, 2) . '/stubs/modules/'); + Stub::setBasePath(dirname(__DIR__, 2).'/stubs/modules/'); // Create a dummy module - if (!File::isDirectory(base_path('modules/Blog'))) { + if (! File::isDirectory(base_path('modules/Blog'))) { File::makeDirectory(base_path('modules/Blog'), 0755, true); } @@ -47,7 +47,7 @@ protected function setUp(): void 'providers' => [], 'aliases' => [], 'files' => [], - 'requires' => [] + 'requires' => [], ])); } diff --git a/tests/Unit/GithubReleaseModuleCommandTest.php b/tests/Unit/GithubReleaseModuleCommandTest.php index dc3933d..c685061 100644 --- a/tests/Unit/GithubReleaseModuleCommandTest.php +++ b/tests/Unit/GithubReleaseModuleCommandTest.php @@ -2,6 +2,7 @@ namespace Juzaweb\DevTool\Tests\Unit; +use Illuminate\Contracts\Console\Kernel; use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\Http; use Juzaweb\DevTool\Commands\GithubReleaseModuleCommand; @@ -10,9 +11,9 @@ class GithubReleaseModuleCommandTest extends TestCase { - public function testNothingToRelease() + public function test_nothing_to_release() { - $command = Mockery::mock(GithubReleaseModuleCommand::class . '[runCmd,getGithubToken]') + $command = Mockery::mock(GithubReleaseModuleCommand::class.'[runCmd,getGithubToken]') ->shouldAllowMockingProtectedMethods(); $command->shouldReceive('getGithubToken')->andReturn('fake-token'); @@ -42,20 +43,20 @@ public function testNothingToRelease() }) ->andReturn(''); - $this->app[\Illuminate\Contracts\Console\Kernel::class]->registerCommand($command); + $this->app[Kernel::class]->registerCommand($command); File::shouldReceive('isDirectory')->andReturn(true); $this->artisan('github:release', [ - 'path' => '/fake/path' + 'path' => '/fake/path', ]) ->expectsOutput('Nothing to release') ->assertExitCode(0); } - public function testReleaseWithChangelog() + public function test_release_with_changelog() { - $command = Mockery::mock(GithubReleaseModuleCommand::class . '[runCmd,getGithubToken]') + $command = Mockery::mock(GithubReleaseModuleCommand::class.'[runCmd,getGithubToken]') ->shouldAllowMockingProtectedMethods(); $command->shouldReceive('getGithubToken')->andReturn('fake-token'); @@ -103,12 +104,12 @@ public function testReleaseWithChangelog() }) ->andReturn(''); - $this->app[\Illuminate\Contracts\Console\Kernel::class]->registerCommand($command); + $this->app[Kernel::class]->registerCommand($command); File::shouldReceive('isDirectory')->andReturn(true); File::shouldReceive('prepend') ->withArgs(function ($path, $content) { - return str_contains($path, 'changelog.md') && str_contains($content, 'v1.0.1') && str_contains($content, 'Feature 1') && !str_contains($content, ':construction:'); + return str_contains($path, 'changelog.md') && str_contains($content, 'v1.0.1') && str_contains($content, 'Feature 1') && ! str_contains($content, ':construction:'); }) ->once(); @@ -117,7 +118,7 @@ public function testReleaseWithChangelog() ]); $this->artisan('github:release', [ - 'path' => '/fake/path' + 'path' => '/fake/path', ]) ->expectsOutput('Add changelog') ->expectsOutput('Release v1.0.1') @@ -132,9 +133,9 @@ public function testReleaseWithChangelog() }); } - public function testReleaseWithoutChangelog() + public function test_release_without_changelog() { - $command = Mockery::mock(GithubReleaseModuleCommand::class . '[runCmd,getGithubToken]') + $command = Mockery::mock(GithubReleaseModuleCommand::class.'[runCmd,getGithubToken]') ->shouldAllowMockingProtectedMethods(); $command->shouldReceive('getGithubToken')->andReturn('fake-token'); @@ -162,9 +163,9 @@ public function testReleaseWithoutChangelog() ->withArgs(function ($path, $cmd) { return is_string($cmd) && str_contains($cmd, 'git log'); }) - ->andReturn("* Fix bug 1"); + ->andReturn('* Fix bug 1'); - $this->app[\Illuminate\Contracts\Console\Kernel::class]->registerCommand($command); + $this->app[Kernel::class]->registerCommand($command); File::shouldReceive('isDirectory')->andReturn(true); // Prepend shouldn't be called @@ -185,7 +186,7 @@ public function testReleaseWithoutChangelog() Http::assertSent(function ($request) { return $request->url() == 'https://api.github.com/repos/fake/repo/releases' && $request['tag_name'] == '1.0.1' && - $request['body'] == "* Fix bug 1" && + $request['body'] == '* Fix bug 1' && $request->header('Authorization')[0] == 'Bearer fake-token'; }); } diff --git a/tests/Unit/JobMakeCommandTest.php b/tests/Unit/JobMakeCommandTest.php index 4d24e34..9e9a50d 100644 --- a/tests/Unit/JobMakeCommandTest.php +++ b/tests/Unit/JobMakeCommandTest.php @@ -19,13 +19,13 @@ protected function setUp(): void $this->app['config']->set('modules.paths.generator.jobs.generate', true); // Stubs path - $this->app['config']->set('dev-tool.modules.stubs.path', dirname(__DIR__, 2) . '/stubs/modules/'); - $this->app['config']->set('modules.stubs.path', dirname(__DIR__, 2) . '/stubs/modules/'); + $this->app['config']->set('dev-tool.modules.stubs.path', dirname(__DIR__, 2).'/stubs/modules/'); + $this->app['config']->set('modules.stubs.path', dirname(__DIR__, 2).'/stubs/modules/'); - Stub::setBasePath(dirname(__DIR__, 2) . '/stubs/modules/'); + Stub::setBasePath(dirname(__DIR__, 2).'/stubs/modules/'); // Create a dummy module - if (!File::isDirectory(base_path('modules/Blog'))) { + if (! File::isDirectory(base_path('modules/Blog'))) { File::makeDirectory(base_path('modules/Blog'), 0755, true); } @@ -40,7 +40,7 @@ protected function setUp(): void 'providers' => [], 'aliases' => [], 'files' => [], - 'requires' => [] + 'requires' => [], ])); } diff --git a/tests/Unit/ListenerMakeCommandTest.php b/tests/Unit/ListenerMakeCommandTest.php index 6d7bc14..4edf76e 100644 --- a/tests/Unit/ListenerMakeCommandTest.php +++ b/tests/Unit/ListenerMakeCommandTest.php @@ -17,14 +17,14 @@ protected function setUp(): void $this->app['config']->set('modules.paths.generator.listener.path', 'src/Listeners'); $this->app['config']->set('modules.paths.generator.listener.generate', true); $this->app['config']->set('dev-tool.modules.paths.generator.event', ['path' => 'src/Events', 'generate' => false, 'namespace' => 'Events']); - $this->app['config']->set('dev-tool.modules.stubs.path', dirname(__DIR__, 2) . '/stubs/modules/'); - $this->app['config']->set('modules.stubs.path', dirname(__DIR__, 2) . '/stubs/modules/'); + $this->app['config']->set('dev-tool.modules.stubs.path', dirname(__DIR__, 2).'/stubs/modules/'); + $this->app['config']->set('modules.stubs.path', dirname(__DIR__, 2).'/stubs/modules/'); $this->app['config']->set('modules.namespace', 'Modules'); - Stub::setBasePath(dirname(__DIR__, 2) . '/stubs/modules/'); + Stub::setBasePath(dirname(__DIR__, 2).'/stubs/modules/'); // Create a dummy module - if (!File::isDirectory(base_path('modules/Blog'))) { + if (! File::isDirectory(base_path('modules/Blog'))) { File::makeDirectory(base_path('modules/Blog'), 0755, true); } @@ -39,7 +39,7 @@ protected function setUp(): void 'providers' => [], 'aliases' => [], 'files' => [], - 'requires' => [] + 'requires' => [], ])); } diff --git a/tests/Unit/MailMakeCommandTest.php b/tests/Unit/MailMakeCommandTest.php index bfa8c97..7e51823 100644 --- a/tests/Unit/MailMakeCommandTest.php +++ b/tests/Unit/MailMakeCommandTest.php @@ -16,13 +16,13 @@ protected function setUp(): void $this->app['config']->set('modules.paths.modules', base_path('modules')); $this->app['config']->set('modules.paths.generator.emails.path', 'src/Emails'); $this->app['config']->set('modules.paths.generator.emails.generate', true); - $this->app['config']->set('dev-tool.modules.stubs.path', dirname(__DIR__, 2) . '/stubs/modules/'); - $this->app['config']->set('modules.stubs.path', dirname(__DIR__, 2) . '/stubs/modules/'); + $this->app['config']->set('dev-tool.modules.stubs.path', dirname(__DIR__, 2).'/stubs/modules/'); + $this->app['config']->set('modules.stubs.path', dirname(__DIR__, 2).'/stubs/modules/'); - Stub::setBasePath(dirname(__DIR__, 2) . '/stubs/modules/'); + Stub::setBasePath(dirname(__DIR__, 2).'/stubs/modules/'); // Create a dummy module - if (!File::isDirectory(base_path('modules/Blog'))) { + if (! File::isDirectory(base_path('modules/Blog'))) { File::makeDirectory(base_path('modules/Blog'), 0755, true); } @@ -37,7 +37,7 @@ protected function setUp(): void 'providers' => [], 'aliases' => [], 'files' => [], - 'requires' => [] + 'requires' => [], ])); } diff --git a/tests/Unit/MiddlewareMakeCommandTest.php b/tests/Unit/MiddlewareMakeCommandTest.php index b5b3ce8..8c84dd1 100644 --- a/tests/Unit/MiddlewareMakeCommandTest.php +++ b/tests/Unit/MiddlewareMakeCommandTest.php @@ -20,13 +20,13 @@ protected function setUp(): void $this->app['config']->set('modules.paths.generator.filter.generate', true); // Stubs path - $this->app['config']->set('dev-tool.modules.stubs.path', dirname(__DIR__, 2) . '/stubs/modules/'); - $this->app['config']->set('modules.stubs.path', dirname(__DIR__, 2) . '/stubs/modules/'); + $this->app['config']->set('dev-tool.modules.stubs.path', dirname(__DIR__, 2).'/stubs/modules/'); + $this->app['config']->set('modules.stubs.path', dirname(__DIR__, 2).'/stubs/modules/'); - Stub::setBasePath(dirname(__DIR__, 2) . '/stubs/modules/'); + Stub::setBasePath(dirname(__DIR__, 2).'/stubs/modules/'); // Create a dummy module - if (!File::isDirectory(base_path('modules/Blog'))) { + if (! File::isDirectory(base_path('modules/Blog'))) { File::makeDirectory(base_path('modules/Blog'), 0755, true); } @@ -41,7 +41,7 @@ protected function setUp(): void 'providers' => [], 'aliases' => [], 'files' => [], - 'requires' => [] + 'requires' => [], ])); } diff --git a/tests/Unit/MigrateCommandTest.php b/tests/Unit/MigrateCommandTest.php index 27b8653..eaf860e 100644 --- a/tests/Unit/MigrateCommandTest.php +++ b/tests/Unit/MigrateCommandTest.php @@ -15,7 +15,7 @@ protected function setUp(): void $this->app['config']->set('modules.paths.modules', base_path('modules')); // Create a dummy module - if (!File::isDirectory(base_path('modules/Blog'))) { + if (! File::isDirectory(base_path('modules/Blog'))) { File::makeDirectory(base_path('modules/Blog'), 0755, true); } @@ -30,7 +30,7 @@ protected function setUp(): void 'providers' => [], 'aliases' => [], 'files' => [], - 'requires' => [] + 'requires' => [], ])); File::put(base_path('modules_statuses.json'), json_encode(['Blog' => true])); @@ -50,6 +50,6 @@ protected function tearDown(): void public function test_it_migrates_specific_module() { $this->artisan('module:migrate', ['module' => 'Blog']) - ->assertExitCode(0); + ->assertExitCode(0); } } diff --git a/tests/Unit/MigrateFreshCommandTest.php b/tests/Unit/MigrateFreshCommandTest.php index a81fba9..1293bde 100644 --- a/tests/Unit/MigrateFreshCommandTest.php +++ b/tests/Unit/MigrateFreshCommandTest.php @@ -15,7 +15,7 @@ protected function setUp(): void $this->app['config']->set('modules.paths.modules', base_path('modules')); // Create a dummy module - if (!File::isDirectory(base_path('modules/Blog'))) { + if (! File::isDirectory(base_path('modules/Blog'))) { File::makeDirectory(base_path('modules/Blog'), 0755, true); } @@ -30,7 +30,7 @@ protected function setUp(): void 'providers' => [], 'aliases' => [], 'files' => [], - 'requires' => [] + 'requires' => [], ])); File::put(base_path('modules_statuses.json'), json_encode(['Blog' => true])); @@ -50,6 +50,6 @@ protected function tearDown(): void public function test_it_migrates_fresh_module() { $this->artisan('module:migrate-fresh', ['module' => 'Blog']) - ->assertExitCode(0); + ->assertExitCode(0); } } diff --git a/tests/Unit/MigrateRefreshCommandTest.php b/tests/Unit/MigrateRefreshCommandTest.php index 43d3271..ef95a97 100644 --- a/tests/Unit/MigrateRefreshCommandTest.php +++ b/tests/Unit/MigrateRefreshCommandTest.php @@ -15,7 +15,7 @@ protected function setUp(): void $this->app['config']->set('modules.paths.modules', base_path('modules')); // Create a dummy module - if (!File::isDirectory(base_path('modules/Blog'))) { + if (! File::isDirectory(base_path('modules/Blog'))) { File::makeDirectory(base_path('modules/Blog'), 0755, true); } @@ -30,7 +30,7 @@ protected function setUp(): void 'providers' => [], 'aliases' => [], 'files' => [], - 'requires' => [] + 'requires' => [], ])); File::put(base_path('modules_statuses.json'), json_encode(['Blog' => true])); @@ -50,6 +50,6 @@ protected function tearDown(): void public function test_it_migrates_refresh_module() { $this->artisan('module:migrate-refresh', ['module' => 'Blog']) - ->assertExitCode(0); + ->assertExitCode(0); } } diff --git a/tests/Unit/MigrateResetCommandTest.php b/tests/Unit/MigrateResetCommandTest.php index b89e30f..2f7d954 100644 --- a/tests/Unit/MigrateResetCommandTest.php +++ b/tests/Unit/MigrateResetCommandTest.php @@ -15,7 +15,7 @@ protected function setUp(): void $this->app['config']->set('modules.paths.modules', base_path('modules')); // Create a dummy module - if (!File::isDirectory(base_path('modules/Blog'))) { + if (! File::isDirectory(base_path('modules/Blog'))) { File::makeDirectory(base_path('modules/Blog'), 0755, true); } @@ -30,7 +30,7 @@ protected function setUp(): void 'providers' => [], 'aliases' => [], 'files' => [], - 'requires' => [] + 'requires' => [], ])); File::put(base_path('modules_statuses.json'), json_encode(['Blog' => true])); @@ -50,6 +50,6 @@ protected function tearDown(): void public function test_it_migrates_reset_module() { $this->artisan('module:migrate-reset', ['module' => 'Blog']) - ->assertExitCode(0); + ->assertExitCode(0); } } diff --git a/tests/Unit/MigrateRollbackCommandTest.php b/tests/Unit/MigrateRollbackCommandTest.php index 3309bd9..3f14487 100644 --- a/tests/Unit/MigrateRollbackCommandTest.php +++ b/tests/Unit/MigrateRollbackCommandTest.php @@ -15,7 +15,7 @@ protected function setUp(): void $this->app['config']->set('modules.paths.modules', base_path('modules')); // Create a dummy module - if (!File::isDirectory(base_path('modules/Blog'))) { + if (! File::isDirectory(base_path('modules/Blog'))) { File::makeDirectory(base_path('modules/Blog'), 0755, true); } @@ -30,7 +30,7 @@ protected function setUp(): void 'providers' => [], 'aliases' => [], 'files' => [], - 'requires' => [] + 'requires' => [], ])); File::put(base_path('modules_statuses.json'), json_encode(['Blog' => true])); @@ -75,9 +75,9 @@ public function down() { // Run migrate first $this->artisan('module:migrate', ['module' => 'Blog']) - ->assertExitCode(0); + ->assertExitCode(0); $this->artisan('module:migrate-rollback', ['module' => 'Blog']) - ->assertExitCode(0); + ->assertExitCode(0); } } diff --git a/tests/Unit/MigrateStatusCommandTest.php b/tests/Unit/MigrateStatusCommandTest.php index 294b27b..a620564 100644 --- a/tests/Unit/MigrateStatusCommandTest.php +++ b/tests/Unit/MigrateStatusCommandTest.php @@ -15,7 +15,7 @@ protected function setUp(): void $this->app['config']->set('modules.paths.modules', base_path('modules')); // Create a dummy module - if (!File::isDirectory(base_path('modules/Blog'))) { + if (! File::isDirectory(base_path('modules/Blog'))) { File::makeDirectory(base_path('modules/Blog'), 0755, true); } @@ -30,7 +30,7 @@ protected function setUp(): void 'providers' => [], 'aliases' => [], 'files' => [], - 'requires' => [] + 'requires' => [], ])); File::put(base_path('modules_statuses.json'), json_encode(['Blog' => true])); @@ -52,6 +52,6 @@ public function test_it_migrates_status_module() // migrate:status might fail if table not found, but default is creating migrations table. // It outputs a table. $this->artisan('module:migrate-status', ['module' => 'Blog']) - ->assertExitCode(0); + ->assertExitCode(0); } } diff --git a/tests/Unit/MigrationMakeCommandTest.php b/tests/Unit/MigrationMakeCommandTest.php index 4c4efd3..57420db 100644 --- a/tests/Unit/MigrationMakeCommandTest.php +++ b/tests/Unit/MigrationMakeCommandTest.php @@ -20,13 +20,13 @@ protected function setUp(): void $this->app['config']->set('modules.paths.generator.migration.generate', true); // Stubs path - $this->app['config']->set('dev-tool.modules.stubs.path', dirname(__DIR__, 2) . '/stubs/modules/'); - $this->app['config']->set('modules.stubs.path', dirname(__DIR__, 2) . '/stubs/modules/'); + $this->app['config']->set('dev-tool.modules.stubs.path', dirname(__DIR__, 2).'/stubs/modules/'); + $this->app['config']->set('modules.stubs.path', dirname(__DIR__, 2).'/stubs/modules/'); - Stub::setBasePath(dirname(__DIR__, 2) . '/stubs/modules/'); + Stub::setBasePath(dirname(__DIR__, 2).'/stubs/modules/'); // Create a dummy module - if (!File::isDirectory(base_path('modules/Blog'))) { + if (! File::isDirectory(base_path('modules/Blog'))) { File::makeDirectory(base_path('modules/Blog'), 0755, true); } @@ -41,7 +41,7 @@ protected function setUp(): void 'providers' => [], 'aliases' => [], 'files' => [], - 'requires' => [] + 'requires' => [], ])); } @@ -72,7 +72,7 @@ public function test_it_creates_migration_file_create() $this->artisan('module:make-migration', [ 'name' => 'create_posts_table', 'module' => 'Blog', - '--fields' => 'title:string, body:text' + '--fields' => 'title:string, body:text', ]) ->assertExitCode(0); @@ -93,7 +93,7 @@ public function test_it_creates_migration_file_add() $this->artisan('module:make-migration', [ 'name' => 'add_active_to_posts_table', 'module' => 'Blog', - '--fields' => 'active:boolean' + '--fields' => 'active:boolean', ]) ->assertExitCode(0); @@ -113,7 +113,7 @@ public function test_it_creates_migration_file_delete() $this->artisan('module:make-migration', [ 'name' => 'remove_title_from_posts_table', 'module' => 'Blog', - '--fields' => 'title:string' + '--fields' => 'title:string', ]) ->assertExitCode(0); @@ -132,7 +132,7 @@ public function test_it_creates_migration_file_drop() { $this->artisan('module:make-migration', [ 'name' => 'drop_posts_table', - 'module' => 'Blog' + 'module' => 'Blog', ]) ->assertExitCode(0); diff --git a/tests/Unit/ModelMakeCommandTest.php b/tests/Unit/ModelMakeCommandTest.php index 6ea264e..c6cf2a7 100644 --- a/tests/Unit/ModelMakeCommandTest.php +++ b/tests/Unit/ModelMakeCommandTest.php @@ -40,13 +40,13 @@ protected function setUp(): void $this->app['config']->set('modules.paths.generator.request.namespace', 'Http\\Requests'); // Stubs path - $this->app['config']->set('dev-tool.modules.stubs.path', dirname(__DIR__, 2) . '/stubs/modules/'); - $this->app['config']->set('modules.stubs.path', dirname(__DIR__, 2) . '/stubs/modules/'); + $this->app['config']->set('dev-tool.modules.stubs.path', dirname(__DIR__, 2).'/stubs/modules/'); + $this->app['config']->set('modules.stubs.path', dirname(__DIR__, 2).'/stubs/modules/'); - Stub::setBasePath(dirname(__DIR__, 2) . '/stubs/modules/'); + Stub::setBasePath(dirname(__DIR__, 2).'/stubs/modules/'); // Create a dummy module - if (!File::isDirectory(base_path('modules/Blog'))) { + if (! File::isDirectory(base_path('modules/Blog'))) { File::makeDirectory(base_path('modules/Blog'), 0755, true); } @@ -61,7 +61,7 @@ protected function setUp(): void 'providers' => [], 'aliases' => [], 'files' => [], - 'requires' => [] + 'requires' => [], ])); } diff --git a/tests/Unit/ModelShowCommandTest.php b/tests/Unit/ModelShowCommandTest.php index eaeb45a..2548642 100644 --- a/tests/Unit/ModelShowCommandTest.php +++ b/tests/Unit/ModelShowCommandTest.php @@ -10,6 +10,7 @@ class ModelShowCommandTest extends TestCase { protected string $originalCwd; + protected string $tempDir; protected function setUp(): void @@ -18,9 +19,9 @@ protected function setUp(): void // Create a temporary directory for testing $this->originalCwd = getcwd(); - $this->tempDir = sys_get_temp_dir() . '/juzaweb_test_' . uniqid(); + $this->tempDir = sys_get_temp_dir().'/juzaweb_test_'.uniqid(); - if (!file_exists($this->tempDir)) { + if (! file_exists($this->tempDir)) { mkdir($this->tempDir, 0755, true); } @@ -33,10 +34,10 @@ protected function setUp(): void // Create a dummy module in the temp dir // Since we chdir'd, 'modules' is relative to tempDir - $modulesPath = $this->tempDir . '/modules'; + $modulesPath = $this->tempDir.'/modules'; - if (!File::isDirectory($modulesPath . '/Blog/src/Models')) { - File::makeDirectory($modulesPath . '/Blog/src/Models', 0755, true); + if (! File::isDirectory($modulesPath.'/Blog/src/Models')) { + File::makeDirectory($modulesPath.'/Blog/src/Models', 0755, true); } // Create a dummy model file @@ -52,7 +53,7 @@ class Post extends Model // } PHP; - File::put($modulesPath . '/Blog/src/Models/Post.php', $content); + File::put($modulesPath.'/Blog/src/Models/Post.php', $content); } protected function tearDown(): void @@ -70,7 +71,7 @@ protected function tearDown(): void public function test_qualify_model_finds_model_in_module() { - $command = new ModelShowCommand(); + $command = new ModelShowCommand; $command->setLaravel($this->app); $method = new ReflectionMethod(ModelShowCommand::class, 'qualifyModel'); @@ -83,7 +84,7 @@ public function test_qualify_model_finds_model_in_module() public function test_qualify_model_returns_fully_qualified_class_if_exists() { - $command = new ModelShowCommand(); + $command = new ModelShowCommand; $command->setLaravel($this->app); $method = new ReflectionMethod(ModelShowCommand::class, 'qualifyModel'); @@ -97,7 +98,7 @@ public function test_qualify_model_returns_fully_qualified_class_if_exists() public function test_qualify_model_returns_original_if_not_found() { - $command = new ModelShowCommand(); + $command = new ModelShowCommand; $command->setLaravel($this->app); $method = new ReflectionMethod(ModelShowCommand::class, 'qualifyModel'); diff --git a/tests/Unit/ModuleDeleteCommandTest.php b/tests/Unit/ModuleDeleteCommandTest.php index 6696cfc..8c2bcd7 100644 --- a/tests/Unit/ModuleDeleteCommandTest.php +++ b/tests/Unit/ModuleDeleteCommandTest.php @@ -17,13 +17,13 @@ protected function setUp(): void // Setup module configuration $this->app['config']->set('modules.paths.modules', base_path('modules')); - $this->app['config']->set('dev-tool.modules.stubs.path', dirname(__DIR__, 2) . '/stubs/modules/'); - $this->app['config']->set('modules.stubs.path', dirname(__DIR__, 2) . '/stubs/modules/'); + $this->app['config']->set('dev-tool.modules.stubs.path', dirname(__DIR__, 2).'/stubs/modules/'); + $this->app['config']->set('modules.stubs.path', dirname(__DIR__, 2).'/stubs/modules/'); - Stub::setBasePath(dirname(__DIR__, 2) . '/stubs/modules/'); + Stub::setBasePath(dirname(__DIR__, 2).'/stubs/modules/'); // Create a dummy module - if (!File::isDirectory(base_path('modules/Blog'))) { + if (! File::isDirectory(base_path('modules/Blog'))) { File::makeDirectory(base_path('modules/Blog'), 0755, true); } @@ -38,7 +38,7 @@ protected function setUp(): void 'providers' => [], 'aliases' => [], 'files' => [], - 'requires' => [] + 'requires' => [], ])); } diff --git a/tests/Unit/ModuleMakeCommandTest.php b/tests/Unit/ModuleMakeCommandTest.php index 7b6869a..33dc690 100644 --- a/tests/Unit/ModuleMakeCommandTest.php +++ b/tests/Unit/ModuleMakeCommandTest.php @@ -27,7 +27,7 @@ protected function setUp(): void $this->app['config']->set('dev-tool.modules.namespace', 'Juzaweb'); // Setup stubs path - $stubsPath = dirname(__DIR__, 2) . '/stubs/modules/'; + $stubsPath = dirname(__DIR__, 2).'/stubs/modules/'; $this->app['config']->set('dev-tool.modules.stubs.path', $stubsPath); $this->app['config']->set('modules.stubs.path', $stubsPath); @@ -88,7 +88,7 @@ public function test_it_creates_module_api() public function test_it_fails_if_module_exists() { // Create a dummy module - if (!File::isDirectory(base_path('modules/blog'))) { + if (! File::isDirectory(base_path('modules/blog'))) { File::makeDirectory(base_path('modules/blog'), 0755, true); } File::put(base_path('modules/blog/module.json'), json_encode(['name' => 'Blog', 'alias' => 'blog', 'providers' => [], 'files' => []])); @@ -100,7 +100,7 @@ public function test_it_fails_if_module_exists() public function test_it_overwrites_if_force() { // Create a dummy module - if (!File::isDirectory(base_path('modules/blog'))) { + if (! File::isDirectory(base_path('modules/blog'))) { File::makeDirectory(base_path('modules/blog'), 0755, true); } File::put(base_path('modules/blog/module.json'), json_encode(['name' => 'Blog', 'alias' => 'blog', 'providers' => [], 'files' => []])); diff --git a/tests/Unit/NotificationMakeCommandTest.php b/tests/Unit/NotificationMakeCommandTest.php index e7904d9..a4f3805 100644 --- a/tests/Unit/NotificationMakeCommandTest.php +++ b/tests/Unit/NotificationMakeCommandTest.php @@ -16,13 +16,13 @@ protected function setUp(): void $this->app['config']->set('modules.paths.modules', base_path('modules')); $this->app['config']->set('modules.paths.generator.notifications.path', 'src/Notifications'); $this->app['config']->set('modules.paths.generator.notifications.generate', true); - $this->app['config']->set('dev-tool.modules.stubs.path', dirname(__DIR__, 2) . '/stubs/modules/'); - $this->app['config']->set('modules.stubs.path', dirname(__DIR__, 2) . '/stubs/modules/'); + $this->app['config']->set('dev-tool.modules.stubs.path', dirname(__DIR__, 2).'/stubs/modules/'); + $this->app['config']->set('modules.stubs.path', dirname(__DIR__, 2).'/stubs/modules/'); - Stub::setBasePath(dirname(__DIR__, 2) . '/stubs/modules/'); + Stub::setBasePath(dirname(__DIR__, 2).'/stubs/modules/'); // Create a dummy module - if (!File::isDirectory(base_path('modules/Blog'))) { + if (! File::isDirectory(base_path('modules/Blog'))) { File::makeDirectory(base_path('modules/Blog'), 0755, true); } @@ -37,7 +37,7 @@ protected function setUp(): void 'providers' => [], 'aliases' => [], 'files' => [], - 'requires' => [] + 'requires' => [], ])); } diff --git a/tests/Unit/PolicyMakeCommandTest.php b/tests/Unit/PolicyMakeCommandTest.php index 42a27ae..00fcf95 100644 --- a/tests/Unit/PolicyMakeCommandTest.php +++ b/tests/Unit/PolicyMakeCommandTest.php @@ -17,13 +17,13 @@ protected function setUp(): void $this->app['config']->set('modules.paths.generator.policies.path', 'src/Policies'); $this->app['config']->set('modules.paths.generator.policies.generate', true); - $this->app['config']->set('dev-tool.modules.stubs.path', dirname(__DIR__, 2) . '/stubs/modules/'); - $this->app['config']->set('modules.stubs.path', dirname(__DIR__, 2) . '/stubs/modules/'); + $this->app['config']->set('dev-tool.modules.stubs.path', dirname(__DIR__, 2).'/stubs/modules/'); + $this->app['config']->set('modules.stubs.path', dirname(__DIR__, 2).'/stubs/modules/'); - Stub::setBasePath(dirname(__DIR__, 2) . '/stubs/modules/'); + Stub::setBasePath(dirname(__DIR__, 2).'/stubs/modules/'); // Create a dummy module - if (!File::isDirectory(base_path('modules/Blog'))) { + if (! File::isDirectory(base_path('modules/Blog'))) { File::makeDirectory(base_path('modules/Blog'), 0755, true); } @@ -38,7 +38,7 @@ protected function setUp(): void 'providers' => [], 'aliases' => [], 'files' => [], - 'requires' => [] + 'requires' => [], ])); } diff --git a/tests/Unit/ProviderMakeCommandTest.php b/tests/Unit/ProviderMakeCommandTest.php index 75a3808..7a32578 100644 --- a/tests/Unit/ProviderMakeCommandTest.php +++ b/tests/Unit/ProviderMakeCommandTest.php @@ -17,13 +17,13 @@ protected function setUp(): void $this->app['config']->set('modules.paths.generator.provider.path', 'src/Providers'); $this->app['config']->set('modules.paths.generator.provider.generate', true); - $this->app['config']->set('dev-tool.modules.stubs.path', dirname(__DIR__, 2) . '/stubs/modules/'); - $this->app['config']->set('modules.stubs.path', dirname(__DIR__, 2) . '/stubs/modules/'); + $this->app['config']->set('dev-tool.modules.stubs.path', dirname(__DIR__, 2).'/stubs/modules/'); + $this->app['config']->set('modules.stubs.path', dirname(__DIR__, 2).'/stubs/modules/'); - Stub::setBasePath(dirname(__DIR__, 2) . '/stubs/modules/'); + Stub::setBasePath(dirname(__DIR__, 2).'/stubs/modules/'); // Create a dummy module - if (!File::isDirectory(base_path('modules/Blog'))) { + if (! File::isDirectory(base_path('modules/Blog'))) { File::makeDirectory(base_path('modules/Blog'), 0755, true); } @@ -37,7 +37,7 @@ protected function setUp(): void 'providers' => [], 'aliases' => [], 'files' => [], - 'requires' => [] + 'requires' => [], ])); } diff --git a/tests/Unit/PublishAgentsCommandTest.php b/tests/Unit/PublishAgentsCommandTest.php index 4ece9ff..aa5da67 100644 --- a/tests/Unit/PublishAgentsCommandTest.php +++ b/tests/Unit/PublishAgentsCommandTest.php @@ -11,7 +11,9 @@ class PublishAgentsCommandTest extends TestCase { protected MockInterface|Filesystem $files; + protected string $baseSourcePath; + protected string $destinationPath; protected function setUp(): void @@ -23,8 +25,8 @@ protected function setUp(): void // The command class calculates the source directory like this: // dirname(__DIR__, 2) . '/agents' (where __DIR__ is src/Commands) - $commandDir = realpath(__DIR__ . '/../../src/Commands'); // Changed from ../../../ to ../../ since the test moved up one directory - $this->baseSourcePath = dirname($commandDir, 2) . '/agents'; + $commandDir = realpath(__DIR__.'/../../src/Commands'); // Changed from ../../../ to ../../ since the test moved up one directory + $this->baseSourcePath = dirname($commandDir, 2).'/agents'; $this->destinationPath = base_path('.agent'); } @@ -36,20 +38,20 @@ public function test_it_publishes_all_agents() $this->files->shouldReceive('makeDirectory')->with($this->destinationPath, 0755, true)->once()->andReturn(true); $mockFile1 = Mockery::mock(SplFileInfo::class); - $mockFile1->shouldReceive('getPathname')->andReturn($this->baseSourcePath . DIRECTORY_SEPARATOR . 'rules/test-rule.md'); + $mockFile1->shouldReceive('getPathname')->andReturn($this->baseSourcePath.DIRECTORY_SEPARATOR.'rules/test-rule.md'); $this->files->shouldReceive('allFiles')->with($this->baseSourcePath)->once()->andReturn([$mockFile1]); - $this->files->shouldReceive('directories')->with($this->baseSourcePath)->once()->andReturn([$this->baseSourcePath . DIRECTORY_SEPARATOR . 'rules']); - $this->files->shouldReceive('directories')->with($this->baseSourcePath . DIRECTORY_SEPARATOR . 'rules')->once()->andReturn([]); + $this->files->shouldReceive('directories')->with($this->baseSourcePath)->once()->andReturn([$this->baseSourcePath.DIRECTORY_SEPARATOR.'rules']); + $this->files->shouldReceive('directories')->with($this->baseSourcePath.DIRECTORY_SEPARATOR.'rules')->once()->andReturn([]); - $targetDir = $this->destinationPath . DIRECTORY_SEPARATOR . 'rules'; + $targetDir = $this->destinationPath.DIRECTORY_SEPARATOR.'rules'; $this->files->shouldReceive('isDirectory')->with($targetDir)->once()->andReturn(false); $this->files->shouldReceive('makeDirectory')->with($targetDir, 0755, true)->once()->andReturn(true); - $targetPath = $this->destinationPath . DIRECTORY_SEPARATOR . 'rules/test-rule.md'; + $targetPath = $this->destinationPath.DIRECTORY_SEPARATOR.'rules/test-rule.md'; $this->files->shouldReceive('exists')->with($targetPath)->once()->andReturn(false); - $this->files->shouldReceive('copy')->with($this->baseSourcePath . DIRECTORY_SEPARATOR . 'rules/test-rule.md', $targetPath)->once()->andReturn(true); + $this->files->shouldReceive('copy')->with($this->baseSourcePath.DIRECTORY_SEPARATOR.'rules/test-rule.md', $targetPath)->once()->andReturn(true); $this->artisan('agents:publish') ->expectsOutputToContain('Publishing dev-tool agents...') @@ -59,22 +61,22 @@ public function test_it_publishes_all_agents() public function test_it_publishes_only_skills() { - $sourcePath = $this->baseSourcePath . DIRECTORY_SEPARATOR . 'skills'; - $targetDestination = $this->destinationPath . DIRECTORY_SEPARATOR . 'skills'; + $sourcePath = $this->baseSourcePath.DIRECTORY_SEPARATOR.'skills'; + $targetDestination = $this->destinationPath.DIRECTORY_SEPARATOR.'skills'; $this->files->shouldReceive('isDirectory')->with($sourcePath)->once()->andReturn(true); $this->files->shouldReceive('isDirectory')->with($targetDestination)->once()->andReturn(false); $this->files->shouldReceive('makeDirectory')->with($targetDestination, 0755, true)->once()->andReturn(true); $mockFile1 = Mockery::mock(SplFileInfo::class); - $mockFile1->shouldReceive('getPathname')->andReturn($sourcePath . DIRECTORY_SEPARATOR . 'test-skill.md'); + $mockFile1->shouldReceive('getPathname')->andReturn($sourcePath.DIRECTORY_SEPARATOR.'test-skill.md'); $this->files->shouldReceive('allFiles')->with($sourcePath)->once()->andReturn([$mockFile1]); $this->files->shouldReceive('directories')->with($sourcePath)->once()->andReturn([]); - $targetPath = $targetDestination . DIRECTORY_SEPARATOR . 'test-skill.md'; + $targetPath = $targetDestination.DIRECTORY_SEPARATOR.'test-skill.md'; $this->files->shouldReceive('exists')->with($targetPath)->once()->andReturn(false); - $this->files->shouldReceive('copy')->with($sourcePath . DIRECTORY_SEPARATOR . 'test-skill.md', $targetPath)->once()->andReturn(true); + $this->files->shouldReceive('copy')->with($sourcePath.DIRECTORY_SEPARATOR.'test-skill.md', $targetPath)->once()->andReturn(true); $this->artisan('agents:publish', ['--skills' => true]) ->expectsOutputToContain('Publishing skills...') @@ -84,21 +86,21 @@ public function test_it_publishes_only_skills() public function test_it_publishes_only_rules() { - $sourcePath = $this->baseSourcePath . DIRECTORY_SEPARATOR . 'rules'; - $targetDestination = $this->destinationPath . DIRECTORY_SEPARATOR . 'rules'; + $sourcePath = $this->baseSourcePath.DIRECTORY_SEPARATOR.'rules'; + $targetDestination = $this->destinationPath.DIRECTORY_SEPARATOR.'rules'; $this->files->shouldReceive('isDirectory')->with($sourcePath)->once()->andReturn(true); $this->files->shouldReceive('isDirectory')->with($targetDestination)->once()->andReturn(true); $mockFile1 = Mockery::mock(SplFileInfo::class); - $mockFile1->shouldReceive('getPathname')->andReturn($sourcePath . DIRECTORY_SEPARATOR . 'test-rule.md'); + $mockFile1->shouldReceive('getPathname')->andReturn($sourcePath.DIRECTORY_SEPARATOR.'test-rule.md'); $this->files->shouldReceive('allFiles')->with($sourcePath)->once()->andReturn([$mockFile1]); $this->files->shouldReceive('directories')->with($sourcePath)->once()->andReturn([]); - $targetPath = $targetDestination . DIRECTORY_SEPARATOR . 'test-rule.md'; + $targetPath = $targetDestination.DIRECTORY_SEPARATOR.'test-rule.md'; $this->files->shouldReceive('exists')->with($targetPath)->once()->andReturn(false); - $this->files->shouldReceive('copy')->with($sourcePath . DIRECTORY_SEPARATOR . 'test-rule.md', $targetPath)->once()->andReturn(true); + $this->files->shouldReceive('copy')->with($sourcePath.DIRECTORY_SEPARATOR.'test-rule.md', $targetPath)->once()->andReturn(true); $this->artisan('agents:publish', ['--rules' => true]) ->expectsOutputToContain('Publishing rules...') @@ -112,12 +114,12 @@ public function test_it_asks_for_confirmation_when_file_exists() $this->files->shouldReceive('isDirectory')->with($this->destinationPath)->once()->andReturn(true); $mockFile1 = Mockery::mock(SplFileInfo::class); - $mockFile1->shouldReceive('getPathname')->andReturn($this->baseSourcePath . DIRECTORY_SEPARATOR . 'test-rule.md'); + $mockFile1->shouldReceive('getPathname')->andReturn($this->baseSourcePath.DIRECTORY_SEPARATOR.'test-rule.md'); $this->files->shouldReceive('allFiles')->with($this->baseSourcePath)->once()->andReturn([$mockFile1]); $this->files->shouldReceive('directories')->with($this->baseSourcePath)->once()->andReturn([]); - $targetPath = $this->destinationPath . DIRECTORY_SEPARATOR . 'test-rule.md'; + $targetPath = $this->destinationPath.DIRECTORY_SEPARATOR.'test-rule.md'; $this->files->shouldReceive('exists')->with($targetPath)->once()->andReturn(true); $this->files->shouldNotReceive('copy'); @@ -134,15 +136,15 @@ public function test_it_forces_overwrite_when_file_exists() $this->files->shouldReceive('isDirectory')->with($this->destinationPath)->once()->andReturn(true); $mockFile1 = Mockery::mock(SplFileInfo::class); - $mockFile1->shouldReceive('getPathname')->andReturn($this->baseSourcePath . DIRECTORY_SEPARATOR . 'test-rule.md'); + $mockFile1->shouldReceive('getPathname')->andReturn($this->baseSourcePath.DIRECTORY_SEPARATOR.'test-rule.md'); $this->files->shouldReceive('allFiles')->with($this->baseSourcePath)->once()->andReturn([$mockFile1]); $this->files->shouldReceive('directories')->with($this->baseSourcePath)->once()->andReturn([]); - $targetPath = $this->destinationPath . DIRECTORY_SEPARATOR . 'test-rule.md'; + $targetPath = $this->destinationPath.DIRECTORY_SEPARATOR.'test-rule.md'; $this->files->shouldReceive('exists')->with($targetPath)->once()->andReturn(true); - $this->files->shouldReceive('copy')->with($this->baseSourcePath . DIRECTORY_SEPARATOR . 'test-rule.md', $targetPath)->once()->andReturn(true); + $this->files->shouldReceive('copy')->with($this->baseSourcePath.DIRECTORY_SEPARATOR.'test-rule.md', $targetPath)->once()->andReturn(true); $this->artisan('agents:publish', ['--force' => true]) ->expectsOutputToContain('Agents published successfully!') diff --git a/tests/Unit/PublishCommandTest.php b/tests/Unit/PublishCommandTest.php index 73a7817..84d2831 100644 --- a/tests/Unit/PublishCommandTest.php +++ b/tests/Unit/PublishCommandTest.php @@ -18,12 +18,12 @@ protected function setUp(): void $this->app['config']->set('modules.paths.generator.assets.generate', true); // Create a dummy module - if (!File::isDirectory(base_path('modules/Blog'))) { + if (! File::isDirectory(base_path('modules/Blog'))) { File::makeDirectory(base_path('modules/Blog'), 0755, true); } // Create assets directory in module - if (!File::isDirectory(base_path('modules/Blog/assets/public'))) { + if (! File::isDirectory(base_path('modules/Blog/assets/public'))) { File::makeDirectory(base_path('modules/Blog/assets/public'), 0755, true); } File::put(base_path('modules/Blog/assets/public/style.css'), 'body { color: red; }'); @@ -38,7 +38,7 @@ protected function setUp(): void 'providers' => [], 'aliases' => [], 'files' => [], - 'requires' => [] + 'requires' => [], ])); } diff --git a/tests/Unit/PublishConfigurationCommandTest.php b/tests/Unit/PublishConfigurationCommandTest.php index dfd6e4b..d3e64aa 100644 --- a/tests/Unit/PublishConfigurationCommandTest.php +++ b/tests/Unit/PublishConfigurationCommandTest.php @@ -16,7 +16,7 @@ protected function setUp(): void $this->app['config']->set('modules.namespace', 'Juzaweb\\Modules'); // Create a dummy module - if (!File::isDirectory(base_path('modules/Blog'))) { + if (! File::isDirectory(base_path('modules/Blog'))) { File::makeDirectory(base_path('modules/Blog'), 0755, true); } @@ -30,7 +30,7 @@ protected function setUp(): void 'providers' => [], 'aliases' => [], 'files' => [], - 'requires' => [] + 'requires' => [], ])); } diff --git a/tests/Unit/PublishMigrationCommandTest.php b/tests/Unit/PublishMigrationCommandTest.php index 519d9ac..dd4b823 100644 --- a/tests/Unit/PublishMigrationCommandTest.php +++ b/tests/Unit/PublishMigrationCommandTest.php @@ -19,12 +19,12 @@ protected function setUp(): void $this->app['config']->set('modules.paths.generator.migration.generate', true); // Create a dummy module - if (!File::isDirectory(base_path('modules/Blog'))) { + if (! File::isDirectory(base_path('modules/Blog'))) { File::makeDirectory(base_path('modules/Blog'), 0755, true); } // Create migration source - if (!File::isDirectory(base_path('modules/Blog/database/migrations'))) { + if (! File::isDirectory(base_path('modules/Blog/database/migrations'))) { File::makeDirectory(base_path('modules/Blog/database/migrations'), 0755, true); } File::put(base_path('modules/Blog/database/migrations/2023_01_01_000000_create_posts_table.php'), ' [], 'aliases' => [], 'files' => [], - 'requires' => [] + 'requires' => [], ])); } diff --git a/tests/Unit/PublishTranslationCommandTest.php b/tests/Unit/PublishTranslationCommandTest.php index c67dbe3..63b273f 100644 --- a/tests/Unit/PublishTranslationCommandTest.php +++ b/tests/Unit/PublishTranslationCommandTest.php @@ -19,12 +19,12 @@ protected function setUp(): void $this->app['config']->set('modules.paths.generator.lang.generate', true); // Create a dummy module - if (!File::isDirectory(base_path('modules/Blog'))) { + if (! File::isDirectory(base_path('modules/Blog'))) { File::makeDirectory(base_path('modules/Blog'), 0755, true); } // Create lang source - if (!File::isDirectory(base_path('modules/Blog/src/resources/lang/en'))) { + if (! File::isDirectory(base_path('modules/Blog/src/resources/lang/en'))) { File::makeDirectory(base_path('modules/Blog/src/resources/lang/en'), 0755, true, true); } File::put(base_path('modules/Blog/src/resources/lang/en/messages.php'), " 'Welcome'];"); @@ -39,7 +39,7 @@ protected function setUp(): void 'providers' => [], 'aliases' => [], 'files' => [], - 'requires' => [] + 'requires' => [], ])); } diff --git a/tests/Unit/RequestMakeCommandTest.php b/tests/Unit/RequestMakeCommandTest.php index 29e8c01..71305b4 100644 --- a/tests/Unit/RequestMakeCommandTest.php +++ b/tests/Unit/RequestMakeCommandTest.php @@ -17,13 +17,13 @@ protected function setUp(): void $this->app['config']->set('modules.paths.generator.request.path', 'src/Http/Requests'); $this->app['config']->set('modules.paths.generator.request.generate', true); - $this->app['config']->set('dev-tool.modules.stubs.path', dirname(__DIR__, 2) . '/stubs/modules/'); - $this->app['config']->set('modules.stubs.path', dirname(__DIR__, 2) . '/stubs/modules/'); + $this->app['config']->set('dev-tool.modules.stubs.path', dirname(__DIR__, 2).'/stubs/modules/'); + $this->app['config']->set('modules.stubs.path', dirname(__DIR__, 2).'/stubs/modules/'); - Stub::setBasePath(dirname(__DIR__, 2) . '/stubs/modules/'); + Stub::setBasePath(dirname(__DIR__, 2).'/stubs/modules/'); // Create a dummy module - if (!File::isDirectory(base_path('modules/Blog'))) { + if (! File::isDirectory(base_path('modules/Blog'))) { File::makeDirectory(base_path('modules/Blog'), 0755, true); } @@ -37,7 +37,7 @@ protected function setUp(): void 'providers' => [], 'aliases' => [], 'files' => [], - 'requires' => [] + 'requires' => [], ])); } diff --git a/tests/Unit/ResourceMakeCommandTest.php b/tests/Unit/ResourceMakeCommandTest.php index 1af8859..18bcba8 100644 --- a/tests/Unit/ResourceMakeCommandTest.php +++ b/tests/Unit/ResourceMakeCommandTest.php @@ -17,13 +17,13 @@ protected function setUp(): void $this->app['config']->set('modules.paths.generator.resource.path', 'src/Http/Resources'); $this->app['config']->set('modules.paths.generator.resource.generate', true); - $this->app['config']->set('dev-tool.modules.stubs.path', dirname(__DIR__, 2) . '/stubs/modules/'); - $this->app['config']->set('modules.stubs.path', dirname(__DIR__, 2) . '/stubs/modules/'); + $this->app['config']->set('dev-tool.modules.stubs.path', dirname(__DIR__, 2).'/stubs/modules/'); + $this->app['config']->set('modules.stubs.path', dirname(__DIR__, 2).'/stubs/modules/'); - Stub::setBasePath(dirname(__DIR__, 2) . '/stubs/modules/'); + Stub::setBasePath(dirname(__DIR__, 2).'/stubs/modules/'); // Create a dummy module - if (!File::isDirectory(base_path('modules/Blog'))) { + if (! File::isDirectory(base_path('modules/Blog'))) { File::makeDirectory(base_path('modules/Blog'), 0755, true); } @@ -37,7 +37,7 @@ protected function setUp(): void 'providers' => [], 'aliases' => [], 'files' => [], - 'requires' => [] + 'requires' => [], ])); } diff --git a/tests/Unit/RouteProviderMakeCommandTest.php b/tests/Unit/RouteProviderMakeCommandTest.php index 2cd655c..09921bc 100644 --- a/tests/Unit/RouteProviderMakeCommandTest.php +++ b/tests/Unit/RouteProviderMakeCommandTest.php @@ -17,13 +17,13 @@ protected function setUp(): void $this->app['config']->set('modules.paths.generator.provider.path', 'src/Providers'); $this->app['config']->set('modules.paths.generator.provider.generate', true); - $this->app['config']->set('dev-tool.modules.stubs.path', dirname(__DIR__, 2) . '/stubs/modules/'); - $this->app['config']->set('modules.stubs.path', dirname(__DIR__, 2) . '/stubs/modules/'); + $this->app['config']->set('dev-tool.modules.stubs.path', dirname(__DIR__, 2).'/stubs/modules/'); + $this->app['config']->set('modules.stubs.path', dirname(__DIR__, 2).'/stubs/modules/'); - Stub::setBasePath(dirname(__DIR__, 2) . '/stubs/modules/'); + Stub::setBasePath(dirname(__DIR__, 2).'/stubs/modules/'); // Create a dummy module - if (!File::isDirectory(base_path('modules/Blog'))) { + if (! File::isDirectory(base_path('modules/Blog'))) { File::makeDirectory(base_path('modules/Blog'), 0755, true); } @@ -37,7 +37,7 @@ protected function setUp(): void 'providers' => [], 'aliases' => [], 'files' => [], - 'requires' => [] + 'requires' => [], ])); } diff --git a/tests/Unit/RuleMakeCommandTest.php b/tests/Unit/RuleMakeCommandTest.php index f80d12f..3bf85cf 100644 --- a/tests/Unit/RuleMakeCommandTest.php +++ b/tests/Unit/RuleMakeCommandTest.php @@ -17,13 +17,13 @@ protected function setUp(): void $this->app['config']->set('modules.paths.generator.rules.path', 'src/Rules'); $this->app['config']->set('modules.paths.generator.rules.generate', true); - $this->app['config']->set('dev-tool.modules.stubs.path', dirname(__DIR__, 2) . '/stubs/modules/'); - $this->app['config']->set('modules.stubs.path', dirname(__DIR__, 2) . '/stubs/modules/'); + $this->app['config']->set('dev-tool.modules.stubs.path', dirname(__DIR__, 2).'/stubs/modules/'); + $this->app['config']->set('modules.stubs.path', dirname(__DIR__, 2).'/stubs/modules/'); - Stub::setBasePath(dirname(__DIR__, 2) . '/stubs/modules/'); + Stub::setBasePath(dirname(__DIR__, 2).'/stubs/modules/'); // Create a dummy module - if (!File::isDirectory(base_path('modules/Blog'))) { + if (! File::isDirectory(base_path('modules/Blog'))) { File::makeDirectory(base_path('modules/Blog'), 0755, true); } @@ -37,7 +37,7 @@ protected function setUp(): void 'providers' => [], 'aliases' => [], 'files' => [], - 'requires' => [] + 'requires' => [], ])); } diff --git a/tests/Unit/SeedCommandTest.php b/tests/Unit/SeedCommandTest.php index 26ed7d3..95e870f 100644 --- a/tests/Unit/SeedCommandTest.php +++ b/tests/Unit/SeedCommandTest.php @@ -15,7 +15,7 @@ protected function setUp(): void $this->app['config']->set('modules.paths.modules', base_path('modules')); // Create a dummy module - if (!File::isDirectory(base_path('modules/Blog'))) { + if (! File::isDirectory(base_path('modules/Blog'))) { File::makeDirectory(base_path('modules/Blog'), 0755, true); } @@ -30,7 +30,7 @@ protected function setUp(): void 'providers' => [], 'aliases' => [], 'files' => [], - 'requires' => [] + 'requires' => [], ])); File::put(base_path('modules_statuses.json'), json_encode(['Blog' => true])); @@ -59,6 +59,6 @@ public function test_it_seeds_specific_module() // Since we don't have seeders, it should do nothing and return 0. $this->artisan('module:seed', ['module' => 'Blog']) - ->assertExitCode(0); + ->assertExitCode(0); } } diff --git a/tests/Unit/SeedMakeCommandTest.php b/tests/Unit/SeedMakeCommandTest.php index 6c5c94f..8f09114 100644 --- a/tests/Unit/SeedMakeCommandTest.php +++ b/tests/Unit/SeedMakeCommandTest.php @@ -21,13 +21,13 @@ protected function setUp(): void $this->app['config']->set('dev-tool.modules.paths.generator.seeder.namespace', 'Database\\Seeders'); // Stubs path - $this->app['config']->set('dev-tool.modules.stubs.path', dirname(__DIR__, 2) . '/stubs/modules/'); - $this->app['config']->set('modules.stubs.path', dirname(__DIR__, 2) . '/stubs/modules/'); + $this->app['config']->set('dev-tool.modules.stubs.path', dirname(__DIR__, 2).'/stubs/modules/'); + $this->app['config']->set('modules.stubs.path', dirname(__DIR__, 2).'/stubs/modules/'); - Stub::setBasePath(dirname(__DIR__, 2) . '/stubs/modules/'); + Stub::setBasePath(dirname(__DIR__, 2).'/stubs/modules/'); // Create a dummy module - if (!File::isDirectory(base_path('modules/Blog'))) { + if (! File::isDirectory(base_path('modules/Blog'))) { File::makeDirectory(base_path('modules/Blog'), 0755, true); } @@ -42,7 +42,7 @@ protected function setUp(): void 'providers' => [], 'aliases' => [], 'files' => [], - 'requires' => [] + 'requires' => [], ])); } diff --git a/tests/Unit/TestMakeCommandTest.php b/tests/Unit/TestMakeCommandTest.php index d5ee518..e99dadf 100644 --- a/tests/Unit/TestMakeCommandTest.php +++ b/tests/Unit/TestMakeCommandTest.php @@ -23,13 +23,13 @@ protected function setUp(): void $this->app['config']->set('modules.paths.generator.test-feature.path', 'tests/Feature'); $this->app['config']->set('modules.paths.generator.test-feature.generate', true); - $this->app['config']->set('dev-tool.modules.stubs.path', dirname(__DIR__, 2) . '/stubs/modules/'); - $this->app['config']->set('modules.stubs.path', dirname(__DIR__, 2) . '/stubs/modules/'); + $this->app['config']->set('dev-tool.modules.stubs.path', dirname(__DIR__, 2).'/stubs/modules/'); + $this->app['config']->set('modules.stubs.path', dirname(__DIR__, 2).'/stubs/modules/'); - Stub::setBasePath(dirname(__DIR__, 2) . '/stubs/modules/'); + Stub::setBasePath(dirname(__DIR__, 2).'/stubs/modules/'); // Create a dummy module - if (!File::isDirectory(base_path('modules/Blog'))) { + if (! File::isDirectory(base_path('modules/Blog'))) { File::makeDirectory(base_path('modules/Blog'), 0755, true); } @@ -43,7 +43,7 @@ protected function setUp(): void 'providers' => [], 'aliases' => [], 'files' => [], - 'requires' => [] + 'requires' => [], ])); } diff --git a/tests/Unit/ThemeGeneratorCommandTest.php b/tests/Unit/ThemeGeneratorCommandTest.php index 495ebe5..a98854c 100644 --- a/tests/Unit/ThemeGeneratorCommandTest.php +++ b/tests/Unit/ThemeGeneratorCommandTest.php @@ -16,7 +16,7 @@ protected function setUp(): void $this->app['config']->set('themes.path', base_path('themes')); // Setup stubs path - $stubsPath = dirname(__DIR__, 2) . '/stubs/themes'; + $stubsPath = dirname(__DIR__, 2).'/stubs/themes'; $this->app['config']->set('dev-tool.themes.stubs.path', $stubsPath); // Ensure stub base path is set for Stub class @@ -51,7 +51,7 @@ public function test_it_creates_theme_structure() public function test_it_fails_if_theme_exists() { // Create dummy theme - if (!File::isDirectory(base_path('themes/test-theme'))) { + if (! File::isDirectory(base_path('themes/test-theme'))) { File::makeDirectory(base_path('themes/test-theme'), 0755, true); } @@ -64,15 +64,15 @@ public function test_it_overwrites_if_force() { // Create dummy theme $themePath = base_path('themes/test-theme'); - if (!File::isDirectory($themePath)) { + if (! File::isDirectory($themePath)) { File::makeDirectory($themePath, 0755, true); } - File::put($themePath . '/dummy.txt', 'content'); + File::put($themePath.'/dummy.txt', 'content'); $this->artisan('theme:make', ['name' => 'test-theme', '--force' => true]) ->assertExitCode(0); - $this->assertFileExists($themePath . '/theme.json'); + $this->assertFileExists($themePath.'/theme.json'); // The dummy file should be gone if directory was deleted and recreated // But looking at ThemeGeneratorCommand.php, it does NOT delete directory first. // It calls generateThemeInfo(), makeDir(), createStubs(). @@ -94,6 +94,6 @@ protected function makeFile(string $file, string $storePath): void // The test assertion should verify that theme files exist, not that dummy files are gone, unless we expect clean slate. // I will just check theme.json exists. - $this->assertFileExists($themePath . '/theme.json'); + $this->assertFileExists($themePath.'/theme.json'); } } diff --git a/tests/Unit/ThemeMakeCommandsTest.php b/tests/Unit/ThemeMakeCommandsTest.php index e8b6cf8..e20a0d5 100644 --- a/tests/Unit/ThemeMakeCommandsTest.php +++ b/tests/Unit/ThemeMakeCommandsTest.php @@ -4,8 +4,8 @@ use Illuminate\Support\Facades\File; use Juzaweb\DevTool\Tests\TestCase; -use Juzaweb\Modules\Core\Modules\Support\Stub; use Juzaweb\Modules\Core\Facades\Theme; +use Juzaweb\Modules\Core\Modules\Support\Stub; class ThemeMakeCommandsTest extends TestCase { @@ -16,7 +16,7 @@ protected function setUp(): void // Setup theme configuration $this->app['config']->set('themes.path', base_path('themes')); - $stubsPath = dirname(__DIR__, 2) . '/stubs/themes'; + $stubsPath = dirname(__DIR__, 2).'/stubs/themes'; $this->app['config']->set('dev-tool.themes.stubs.path', $stubsPath); // Ensure stub base path is set for Stub class @@ -67,13 +67,13 @@ public function test_it_creates_template() $this->assertFileExists($providerPath); $providerContent = File::get($providerPath); - $this->assertStringContainsString("PageTemplate::make(", $providerContent); + $this->assertStringContainsString('PageTemplate::make(', $providerContent); $this->assertStringContainsString("'custom-page',", $providerContent); } public function test_it_fails_create_template_home() { - $this->artisan('theme:make-template', [ + $this->artisan('theme:make-template', [ 'name' => 'home', 'theme' => 'test-theme', ])->assertExitCode(1); @@ -104,7 +104,7 @@ public function test_it_creates_widget() $this->assertFileExists($providerPath); $providerContent = File::get($providerPath); - $this->assertStringContainsString("Widget::make(", $providerContent); + $this->assertStringContainsString('Widget::make(', $providerContent); $this->assertStringContainsString("'testwidget',", $providerContent); } @@ -123,7 +123,7 @@ public function test_it_creates_block() $this->assertFileExists($providerPath); $providerContent = File::get($providerPath); - $this->assertStringContainsString("PageBlock::make(", $providerContent); + $this->assertStringContainsString('PageBlock::make(', $providerContent); $this->assertStringContainsString("'testblock',", $providerContent); } } diff --git a/tests/Unit/UseCommandTest.php b/tests/Unit/UseCommandTest.php index 224159b..5110c5c 100644 --- a/tests/Unit/UseCommandTest.php +++ b/tests/Unit/UseCommandTest.php @@ -15,7 +15,7 @@ protected function setUp(): void $this->app['config']->set('modules.paths.modules', base_path('modules')); // Create a dummy module - if (!File::isDirectory(base_path('modules/Blog'))) { + if (! File::isDirectory(base_path('modules/Blog'))) { File::makeDirectory(base_path('modules/Blog'), 0755, true); } @@ -29,7 +29,7 @@ protected function setUp(): void 'providers' => [], 'aliases' => [], 'files' => [], - 'requires' => [] + 'requires' => [], ])); }