diff --git a/CHANGELOG.md b/CHANGELOG.md index f940271..78881c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file. [Next release](https://github.com/barryvdh/laravel-ide-helper/compare/v2.8.1...master) -------------- +### Added +- Fix phpdoc generate for custom cast with parameter [\#986 / artelkr](https://github.com/barryvdh/laravel-ide-helper/pull/986) + 2020-09-07, 2.8.1 ----------------- ### Added diff --git a/src/Console/ModelsCommand.php b/src/Console/ModelsCommand.php index 651c041..09526b8 100644 --- a/src/Console/ModelsCommand.php +++ b/src/Console/ModelsCommand.php @@ -344,6 +344,9 @@ class ModelsCommand extends Command $realType = '\Illuminate\Support\Collection'; break; default: + // In case of an optional custom cast parameter , only evaluate + // the `$type` until the `:` + $type = strtok($type, ':'); $realType = class_exists($type) ? ('\\' . $type) : 'mixed'; break; } diff --git a/tests/Console/ModelsCommand/LaravelCustomCasts/Casts/CustomCasterWithParam.php b/tests/Console/ModelsCommand/LaravelCustomCasts/Casts/CustomCasterWithParam.php new file mode 100644 index 0000000..84bdadf --- /dev/null +++ b/tests/Console/ModelsCommand/LaravelCustomCasts/Casts/CustomCasterWithParam.php @@ -0,0 +1,24 @@ + CustomCasterWithPrimitiveDocblockReturn::class, 'casted_property_with_return_nullable_primitive' => CustomCasterWithNullablePrimitiveReturn::class, 'casted_property_without_return' => CustomCasterWithoutReturnType::class, + 'casted_property_with_param' => CustomCasterWithParam::class . ':param', ]; } diff --git a/tests/Console/ModelsCommand/LaravelCustomCasts/__snapshots__/Test__test__1.php b/tests/Console/ModelsCommand/LaravelCustomCasts/__snapshots__/Test__test__1.php index a431f81..8b55303 100644 --- a/tests/Console/ModelsCommand/LaravelCustomCasts/__snapshots__/Test__test__1.php +++ b/tests/Console/ModelsCommand/LaravelCustomCasts/__snapshots__/Test__test__1.php @@ -8,6 +8,7 @@ use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Cas use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CustomCasterWithDocblockReturnFqn; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CustomCasterWithNullablePrimitiveReturn; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CustomCasterWithoutReturnType; +use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CustomCasterWithParam; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CustomCasterWithPrimitiveDocblockReturn; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CustomCasterWithPrimitiveReturn; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CustomCasterWithReturnType; @@ -23,9 +24,11 @@ use Illuminate\Database\Eloquent\Model; * @property array|null $casted_property_with_return_primitive_docblock * @property array|null $casted_property_with_return_nullable_primitive * @property $casted_property_without_return + * @property \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CastedProperty $casted_property_with_param * @method static \Illuminate\Database\Eloquent\Builder|CustomCast newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|CustomCast newQuery() * @method static \Illuminate\Database\Eloquent\Builder|CustomCast query() + * @method static \Illuminate\Database\Eloquent\Builder|CustomCast whereCastedPropertyWithParam($value) * @method static \Illuminate\Database\Eloquent\Builder|CustomCast whereCastedPropertyWithReturnDocblock($value) * @method static \Illuminate\Database\Eloquent\Builder|CustomCast whereCastedPropertyWithReturnDocblockFqn($value) * @method static \Illuminate\Database\Eloquent\Builder|CustomCast whereCastedPropertyWithReturnNullablePrimitive($value) @@ -45,5 +48,6 @@ class CustomCast extends Model 'casted_property_with_return_primitive_docblock' => CustomCasterWithPrimitiveDocblockReturn::class, 'casted_property_with_return_nullable_primitive' => CustomCasterWithNullablePrimitiveReturn::class, 'casted_property_without_return' => CustomCasterWithoutReturnType::class, + 'casted_property_with_param' => CustomCasterWithParam::class . ':param', ]; } diff --git a/tests/Console/ModelsCommand/migrations/____custom_casts_table.php b/tests/Console/ModelsCommand/migrations/____custom_casts_table.php index 105e57a..ccf3e54 100644 --- a/tests/Console/ModelsCommand/migrations/____custom_casts_table.php +++ b/tests/Console/ModelsCommand/migrations/____custom_casts_table.php @@ -18,6 +18,7 @@ class CustomCastsTable extends Migration $table->string('casted_property_with_return_primitive_docblock'); $table->string('casted_property_with_return_nullable_primitive'); $table->string('casted_property_without_return'); + $table->string('casted_property_with_param'); }); } }