From 66420a89f6321e0bc4072fe3e922853967787f2c Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Fri, 1 Sep 2023 16:11:56 +0800 Subject: [PATCH] wip Signed-off-by: Mior Muhammad Zaki --- pint.json | 2 +- src/CodeGenerator.php | 1 - src/Commands/Generator.php | 4 +--- src/CommandsProvider.php | 2 -- src/Contracts/GeneratesCodeListener.php | 4 +--- src/GeneratesCode.php | 10 +++++++++- src/GeneratesCodeWithComponent.php | 6 +++--- src/GeneratesCodeWithEloquent.php | 6 +++--- src/GeneratesCodeWithMarkdown.php | 6 +++--- src/GeneratesCommandCode.php | 8 +++----- src/Presets/Laravel.php | 1 - src/Presets/Package.php | 1 - 12 files changed, 24 insertions(+), 27 deletions(-) diff --git a/pint.json b/pint.json index 628bd22..cca4ed9 100644 --- a/pint.json +++ b/pint.json @@ -6,7 +6,7 @@ "scope": "namespaced", "strict": true }, - "no_superfluous_phpdoc_tags": false, + "no_superfluous_phpdoc_tags": true, "php_unit_method_casing": false, "nullable_type_declaration_for_default_null_value": { "use_nullable_type_declaration": true diff --git a/src/CodeGenerator.php b/src/CodeGenerator.php index 73a2379..f48279e 100644 --- a/src/CodeGenerator.php +++ b/src/CodeGenerator.php @@ -14,7 +14,6 @@ trait CodeGenerator /** * Set Preset for generator. * - * @param \Orchestra\Canvas\Core\Presets\Preset $preset * @return $this */ public function setPreset(Presets\Preset $preset) diff --git a/src/Commands/Generator.php b/src/Commands/Generator.php index 8e9e06d..bcae11d 100644 --- a/src/Commands/Generator.php +++ b/src/Commands/Generator.php @@ -85,9 +85,7 @@ protected function execute(InputInterface $input, OutputInterface $output) } /** - * Code successfully generated. - * - * @return string + * Handle generating code. */ public function generatingCode(string $stub, string $className): string { diff --git a/src/CommandsProvider.php b/src/CommandsProvider.php index 43583d5..314c504 100644 --- a/src/CommandsProvider.php +++ b/src/CommandsProvider.php @@ -8,8 +8,6 @@ trait CommandsProvider { /** * Setup preset for laravel. - * - * @return \Orchestra\Canvas\Core\Presets\Preset */ protected function presetForLaravel(Container $app): Presets\Preset { diff --git a/src/Contracts/GeneratesCodeListener.php b/src/Contracts/GeneratesCodeListener.php index 29c330c..b808675 100644 --- a/src/Contracts/GeneratesCodeListener.php +++ b/src/Contracts/GeneratesCodeListener.php @@ -12,9 +12,7 @@ interface GeneratesCodeListener public function codeAlreadyExists(string $className); /** - * Code successfully generated. - * - * @return string + * Handle generating code. */ public function generatingCode(string $stub, string $className): string; diff --git a/src/GeneratesCode.php b/src/GeneratesCode.php index 5b573b2..86375c2 100644 --- a/src/GeneratesCode.php +++ b/src/GeneratesCode.php @@ -143,8 +143,16 @@ protected function makeDirectory(string $path): string */ protected function buildClass(string $name): string { - $stub = $this->files->get($this->getListenerStubFile()); + return $this->generatingCode( + $this->files->get($this->getListenerStubFile()), $name + ); + } + /** + * Handle generating code. + */ + protected function generatingCode(string $stub, string $name): string + { return $this->listener->generatingCode( $this->replaceClass( $this->replaceNamespace($stub, $name), $name diff --git a/src/GeneratesCodeWithComponent.php b/src/GeneratesCodeWithComponent.php index 98eeba9..79386aa 100644 --- a/src/GeneratesCodeWithComponent.php +++ b/src/GeneratesCodeWithComponent.php @@ -11,11 +11,11 @@ class GeneratesCodeWithComponent extends GeneratesCode { /** - * Replace the namespace for the given stub. + * Handle generating code. */ - protected function replaceNamespace(string $stub, string $name): string + protected function generatingCode(string $stub, string $name): string { - $stub = parent::replaceNamespace($stub, $name); + $stub = parent::generatingCode($stub, $name); if (! empty($this->options['inline'])) { $stub = str_replace( diff --git a/src/GeneratesCodeWithEloquent.php b/src/GeneratesCodeWithEloquent.php index aa544e4..81df51e 100644 --- a/src/GeneratesCodeWithEloquent.php +++ b/src/GeneratesCodeWithEloquent.php @@ -11,11 +11,11 @@ class GeneratesCodeWithEloquent extends GeneratesCode { /** - * Replace the namespace for the given stub. + * Handle generating code. */ - protected function replaceNamespace(string $stub, string $name): string + protected function generatingCode(string $stub, string $name): string { - $stub = parent::replaceNamespace($stub, $name); + $stub = parent::generatingCode($stub, $name); $model = $this->options['model']; diff --git a/src/GeneratesCodeWithMarkdown.php b/src/GeneratesCodeWithMarkdown.php index 387faac..cdbe111 100644 --- a/src/GeneratesCodeWithMarkdown.php +++ b/src/GeneratesCodeWithMarkdown.php @@ -5,11 +5,11 @@ class GeneratesCodeWithMarkdown extends GeneratesCode { /** - * Replace the namespace for the given stub. + * Handle generating code. */ - protected function replaceNamespace(string $stub, string $name): string + protected function generatingCode(string $stub, string $name): string { - $stub = parent::replaceNamespace($stub, $name); + $stub = parent::generatingCode($stub, $name); if (! empty($this->options['view'])) { $stub = str_replace(['DummyView', '{{ view }}', '{{view}}'], $this->options['view'], $stub); diff --git a/src/GeneratesCommandCode.php b/src/GeneratesCommandCode.php index 479913b..46ec797 100644 --- a/src/GeneratesCommandCode.php +++ b/src/GeneratesCommandCode.php @@ -8,13 +8,11 @@ class GeneratesCommandCode extends GeneratesCode { /** - * Replace the class name for the given stub. - * - * @todo need to be updated + * Handle generating code. */ - protected function replaceClass(string $stub, string $name): string + protected function generatingCode(string $stub, string $name): string { - $stub = parent::replaceClass($stub, $name); + $stub = parent::generatingCode($stub, $name); return str_replace(['dummy:command', '{{ command }}', '{{command}}'], $this->options['command'], $stub); } diff --git a/src/Presets/Laravel.php b/src/Presets/Laravel.php index d32eb6c..ec059dc 100644 --- a/src/Presets/Laravel.php +++ b/src/Presets/Laravel.php @@ -18,7 +18,6 @@ class Laravel extends Preset * Add global command. * * @param array> $generators - * @return void */ public static function commands(array $generators): void { diff --git a/src/Presets/Package.php b/src/Presets/Package.php index a0413a5..1ca3dcc 100644 --- a/src/Presets/Package.php +++ b/src/Presets/Package.php @@ -19,7 +19,6 @@ class Package extends Preset * Add global command. * * @param array> $generators - * @return void */ public static function commands(array $generators): void {