From 0fa96e572d3ac8f280ad1be89e9c3747c481cdda Mon Sep 17 00:00:00 2001 From: Marvin Naumann <1013829+nivseb@users.noreply.github.com> Date: Tue, 22 Apr 2025 15:31:43 +0200 Subject: [PATCH] detect default parameter from type float and adding tests for scopes with typed parameters (#1697) --- src/Console/ModelsCommand.php | 2 +- .../Models/Comment.php | 251 +++++++++++++++ .../Test.php | 24 ++ .../__snapshots__/Test__test__1.php | 289 ++++++++++++++++++ 4 files changed, 565 insertions(+), 1 deletion(-) create mode 100644 tests/Console/ModelsCommand/GeneratePhpDocWithTypedScopeParameter/Models/Comment.php create mode 100644 tests/Console/ModelsCommand/GeneratePhpDocWithTypedScopeParameter/Test.php create mode 100644 tests/Console/ModelsCommand/GeneratePhpDocWithTypedScopeParameter/__snapshots__/Test__test__1.php diff --git a/src/Console/ModelsCommand.php b/src/Console/ModelsCommand.php index aa389ec..1c82e93 100644 --- a/src/Console/ModelsCommand.php +++ b/src/Console/ModelsCommand.php @@ -1186,7 +1186,7 @@ class ModelsCommand extends Command $default = '[]'; } elseif (is_null($default)) { $default = 'null'; - } elseif (is_int($default)) { + } elseif (is_int($default) || is_float($default)) { //$default = $default; } elseif ($default instanceof \UnitEnum) { $default = '\\' . get_class($default) . '::' . $default->name; diff --git a/tests/Console/ModelsCommand/GeneratePhpDocWithTypedScopeParameter/Models/Comment.php b/tests/Console/ModelsCommand/GeneratePhpDocWithTypedScopeParameter/Models/Comment.php new file mode 100644 index 0000000..99ccae5 --- /dev/null +++ b/tests/Console/ModelsCommand/GeneratePhpDocWithTypedScopeParameter/Models/Comment.php @@ -0,0 +1,251 @@ +where('type', $value); + } + + /** + * @comment Scope with optional boolean parameter and default true + */ + protected function scopeTyped02(Builder $query, bool $value = true) + { + $query->where('type', $value); + } + + /** + * @comment Scope with optional boolean parameter and default false + */ + protected function scopeTyped03(Builder $query, bool $value = false) + { + $query->where('type', $value); + } + + /** + * @comment Scope with required string parameter + */ + protected function scopeTyped04(Builder $query, string $value) + { + $query->where('type', $value); + } + + /** + * @comment Scope with optional string parameter and default value + */ + protected function scopeTyped05(Builder $query, string $value = 'dummy123') + { + $query->where('type', $value); + } + + /** + * @comment Scope with required integer parameter + */ + protected function scopeTyped06(Builder $query, int $value) + { + $query->where('type', $value); + } + + /** + * @comment Scope with optional integer parameter and default positive value + */ + protected function scopeTyped07(Builder $query, int $value = 123) + { + $query->where('type', $value); + } + + /** + * @comment Scope with optional integer parameter and default negative value + */ + protected function scopeTyped08(Builder $query, int $value = -123) + { + $query->where('type', $value); + } + + /** + * @comment Scope with required float parameter + */ + protected function scopeTyped09(Builder $query, float $value) + { + $query->where('type', $value); + } + + /** + * @comment Scope with optional float parameter and default positive integer value + */ + protected function scopeTyped10(Builder $query, float $value = 123) + { + $query->where('type', $value); + } + + /** + * @comment Scope with optional float parameter and default negative integer value + */ + protected function scopeTyped11(Builder $query, float $value = -123) + { + $query->where('type', $value); + } + + /** + * @comment Scope with optional float parameter and default positive float value + */ + protected function scopeTyped12(Builder $query, float $value = 1.23) + { + $query->where('type', $value); + } + + /** + * @comment Scope with optional float parameter and default negative float value + */ + protected function scopeTyped13(Builder $query, float $value = -1.23) + { + $query->where('type', $value); + } + + /** + * @comment Scope with required nullable boolean parameter + */ + protected function scopeTyped14(Builder $query, ?bool $value) + { + $query->where('type', $value); + } + + /** + * @comment Scope with optional nullable boolean parameter and default true + */ + protected function scopeTyped15(Builder $query, ?bool $value = true) + { + $query->where('type', $value); + } + + /** + * @comment Scope with optional nullable boolean parameter and default false + */ + protected function scopeTyped16(Builder $query, ?bool $value = false) + { + $query->where('type', $value); + } + + /** + * @comment Scope with optional nullable boolean parameter and default null + */ + protected function scopeTyped17(Builder $query, ?bool $value = null) + { + $query->where('type', $value); + } + + /** + * @comment Scope with required nullable string parameter + */ + protected function scopeTyped18(Builder $query, ?string $value) + { + $query->where('type', $value); + } + + /** + * @comment Scope with optional nullable string parameter and default value + */ + protected function scopeTyped19(Builder $query, ?string $value = 'dummy123') + { + $query->where('type', $value); + } + + /** + * @comment Scope with optional nullable string parameter and default null + */ + protected function scopeTyped20(Builder $query, ?string $value = null) + { + $query->where('type', $value); + } + + /** + * @comment Scope with required nullable integer parameter + */ + protected function scopeTyped21(Builder $query, ?int $value) + { + $query->where('type', $value); + } + + /** + * @comment Scope with optional nullable integer parameter and default positive value + */ + protected function scopeTyped22(Builder $query, ?int $value = 123) + { + $query->where('type', $value); + } + + /** + * @comment Scope with optional nullable integer parameter and default negative value + */ + protected function scopeTyped23(Builder $query, ?int $value = -123) + { + $query->where('type', $value); + } + + /** + * @comment Scope with optional nullable integer parameter and default null + */ + protected function scopeTyped24(Builder $query, ?int $value = null) + { + $query->where('type', $value); + } + + /** + * @comment Scope with required float nullable parameter + */ + protected function scopeTyped25(Builder $query, ?float $value) + { + $query->where('type', $value); + } + + /** + * @comment Scope with optional nullable float parameter and default positive integer value + */ + protected function scopeTyped26(Builder $query, ?float $value = 123) + { + $query->where('type', $value); + } + + /** + * @comment Scope with optional nullable float parameter and default negative integer value + */ + protected function scopeTyped27(Builder $query, ?float $value = -123) + { + $query->where('type', $value); + } + + /** + * @comment Scope with optional float parameter and default positive float value + */ + protected function scopeTyped28(Builder $query, ?float $value = 1.23) + { + $query->where('type', $value); + } + + /** + * @comment Scope with optional float parameter and default negative float value + */ + protected function scopeTyped29(Builder $query, ?float $value = -1.23) + { + $query->where('type', $value); + } + + /** + * @comment Scope with optional float parameter and default null + */ + protected function scopeTyped30(Builder $query, ?float $value = null) + { + $query->where('type', $value); + } +} diff --git a/tests/Console/ModelsCommand/GeneratePhpDocWithTypedScopeParameter/Test.php b/tests/Console/ModelsCommand/GeneratePhpDocWithTypedScopeParameter/Test.php new file mode 100644 index 0000000..e725cb8 --- /dev/null +++ b/tests/Console/ModelsCommand/GeneratePhpDocWithTypedScopeParameter/Test.php @@ -0,0 +1,24 @@ +app->make(ModelsCommand::class); + + $tester = $this->runCommand($command, [ + '--write' => true, + ]); + + $this->assertSame(0, $tester->getStatusCode()); + $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); + $this->assertMatchesMockedSnapshot(); + } +} diff --git a/tests/Console/ModelsCommand/GeneratePhpDocWithTypedScopeParameter/__snapshots__/Test__test__1.php b/tests/Console/ModelsCommand/GeneratePhpDocWithTypedScopeParameter/__snapshots__/Test__test__1.php new file mode 100644 index 0000000..da52497 --- /dev/null +++ b/tests/Console/ModelsCommand/GeneratePhpDocWithTypedScopeParameter/__snapshots__/Test__test__1.php @@ -0,0 +1,289 @@ +|Comment newModelQuery() + * @method static Builder|Comment newQuery() + * @method static Builder|Comment query() + * @method static Builder|Comment typed01(bool $value) Scope with required boolean parameter + * @method static Builder|Comment typed02(bool $value = true) Scope with optional boolean parameter and default true + * @method static Builder|Comment typed03(bool $value = false) Scope with optional boolean parameter and default false + * @method static Builder|Comment typed04(string $value) Scope with required string parameter + * @method static Builder|Comment typed05(string $value = 'dummy123') Scope with optional string parameter and default value + * @method static Builder|Comment typed06(int $value) Scope with required integer parameter + * @method static Builder|Comment typed07(int $value = 123) Scope with optional integer parameter and default positive value + * @method static Builder|Comment typed08(int $value = -123) Scope with optional integer parameter and default negative value + * @method static Builder|Comment typed09(float $value) Scope with required float parameter + * @method static Builder|Comment typed10(float $value = 123) Scope with optional float parameter and default positive integer value + * @method static Builder|Comment typed11(float $value = -123) Scope with optional float parameter and default negative integer value + * @method static Builder|Comment typed12(float $value = 1.23) Scope with optional float parameter and default positive float value + * @method static Builder|Comment typed13(float $value = -1.23) Scope with optional float parameter and default negative float value + * @method static Builder|Comment typed14(?bool $value) Scope with required nullable boolean parameter + * @method static Builder|Comment typed15(?bool $value = true) Scope with optional nullable boolean parameter and default true + * @method static Builder|Comment typed16(?bool $value = false) Scope with optional nullable boolean parameter and default false + * @method static Builder|Comment typed17(?bool $value = null) Scope with optional nullable boolean parameter and default null + * @method static Builder|Comment typed18(?string $value) Scope with required nullable string parameter + * @method static Builder|Comment typed19(?string $value = 'dummy123') Scope with optional nullable string parameter and default value + * @method static Builder|Comment typed20(?string $value = null) Scope with optional nullable string parameter and default null + * @method static Builder|Comment typed21(?int $value) Scope with required nullable integer parameter + * @method static Builder|Comment typed22(?int $value = 123) Scope with optional nullable integer parameter and default positive value + * @method static Builder|Comment typed23(?int $value = -123) Scope with optional nullable integer parameter and default negative value + * @method static Builder|Comment typed24(?int $value = null) Scope with optional nullable integer parameter and default null + * @method static Builder|Comment typed25(?float $value) Scope with required float nullable parameter + * @method static Builder|Comment typed26(?float $value = 123) Scope with optional nullable float parameter and default positive integer value + * @method static Builder|Comment typed27(?float $value = -123) Scope with optional nullable float parameter and default negative integer value + * @method static Builder|Comment typed28(?float $value = 1.23) Scope with optional float parameter and default positive float value + * @method static Builder|Comment typed29(?float $value = -1.23) Scope with optional float parameter and default negative float value + * @method static Builder|Comment typed30(?float $value = null) Scope with optional float parameter and default null + * @mixin \Eloquent + */ +class Comment extends Model +{ + /** + * @comment Scope with required boolean parameter + */ + protected function scopeTyped01(Builder $query, bool $value) + { + $query->where('type', $value); + } + + /** + * @comment Scope with optional boolean parameter and default true + */ + protected function scopeTyped02(Builder $query, bool $value = true) + { + $query->where('type', $value); + } + + /** + * @comment Scope with optional boolean parameter and default false + */ + protected function scopeTyped03(Builder $query, bool $value = false) + { + $query->where('type', $value); + } + + /** + * @comment Scope with required string parameter + */ + protected function scopeTyped04(Builder $query, string $value) + { + $query->where('type', $value); + } + + /** + * @comment Scope with optional string parameter and default value + */ + protected function scopeTyped05(Builder $query, string $value = 'dummy123') + { + $query->where('type', $value); + } + + /** + * @comment Scope with required integer parameter + */ + protected function scopeTyped06(Builder $query, int $value) + { + $query->where('type', $value); + } + + /** + * @comment Scope with optional integer parameter and default positive value + */ + protected function scopeTyped07(Builder $query, int $value = 123) + { + $query->where('type', $value); + } + + /** + * @comment Scope with optional integer parameter and default negative value + */ + protected function scopeTyped08(Builder $query, int $value = -123) + { + $query->where('type', $value); + } + + /** + * @comment Scope with required float parameter + */ + protected function scopeTyped09(Builder $query, float $value) + { + $query->where('type', $value); + } + + /** + * @comment Scope with optional float parameter and default positive integer value + */ + protected function scopeTyped10(Builder $query, float $value = 123) + { + $query->where('type', $value); + } + + /** + * @comment Scope with optional float parameter and default negative integer value + */ + protected function scopeTyped11(Builder $query, float $value = -123) + { + $query->where('type', $value); + } + + /** + * @comment Scope with optional float parameter and default positive float value + */ + protected function scopeTyped12(Builder $query, float $value = 1.23) + { + $query->where('type', $value); + } + + /** + * @comment Scope with optional float parameter and default negative float value + */ + protected function scopeTyped13(Builder $query, float $value = -1.23) + { + $query->where('type', $value); + } + + /** + * @comment Scope with required nullable boolean parameter + */ + protected function scopeTyped14(Builder $query, ?bool $value) + { + $query->where('type', $value); + } + + /** + * @comment Scope with optional nullable boolean parameter and default true + */ + protected function scopeTyped15(Builder $query, ?bool $value = true) + { + $query->where('type', $value); + } + + /** + * @comment Scope with optional nullable boolean parameter and default false + */ + protected function scopeTyped16(Builder $query, ?bool $value = false) + { + $query->where('type', $value); + } + + /** + * @comment Scope with optional nullable boolean parameter and default null + */ + protected function scopeTyped17(Builder $query, ?bool $value = null) + { + $query->where('type', $value); + } + + /** + * @comment Scope with required nullable string parameter + */ + protected function scopeTyped18(Builder $query, ?string $value) + { + $query->where('type', $value); + } + + /** + * @comment Scope with optional nullable string parameter and default value + */ + protected function scopeTyped19(Builder $query, ?string $value = 'dummy123') + { + $query->where('type', $value); + } + + /** + * @comment Scope with optional nullable string parameter and default null + */ + protected function scopeTyped20(Builder $query, ?string $value = null) + { + $query->where('type', $value); + } + + /** + * @comment Scope with required nullable integer parameter + */ + protected function scopeTyped21(Builder $query, ?int $value) + { + $query->where('type', $value); + } + + /** + * @comment Scope with optional nullable integer parameter and default positive value + */ + protected function scopeTyped22(Builder $query, ?int $value = 123) + { + $query->where('type', $value); + } + + /** + * @comment Scope with optional nullable integer parameter and default negative value + */ + protected function scopeTyped23(Builder $query, ?int $value = -123) + { + $query->where('type', $value); + } + + /** + * @comment Scope with optional nullable integer parameter and default null + */ + protected function scopeTyped24(Builder $query, ?int $value = null) + { + $query->where('type', $value); + } + + /** + * @comment Scope with required float nullable parameter + */ + protected function scopeTyped25(Builder $query, ?float $value) + { + $query->where('type', $value); + } + + /** + * @comment Scope with optional nullable float parameter and default positive integer value + */ + protected function scopeTyped26(Builder $query, ?float $value = 123) + { + $query->where('type', $value); + } + + /** + * @comment Scope with optional nullable float parameter and default negative integer value + */ + protected function scopeTyped27(Builder $query, ?float $value = -123) + { + $query->where('type', $value); + } + + /** + * @comment Scope with optional float parameter and default positive float value + */ + protected function scopeTyped28(Builder $query, ?float $value = 1.23) + { + $query->where('type', $value); + } + + /** + * @comment Scope with optional float parameter and default negative float value + */ + protected function scopeTyped29(Builder $query, ?float $value = -1.23) + { + $query->where('type', $value); + } + + /** + * @comment Scope with optional float parameter and default null + */ + protected function scopeTyped30(Builder $query, ?float $value = null) + { + $query->where('type', $value); + } +}