From f5759e200192b7759f71ae5ef1f88628191fb8ab Mon Sep 17 00:00:00 2001 From: Bram Date: Fri, 12 Jul 2024 16:08:08 +0200 Subject: [PATCH] Add `static` to `isBuiltin()` check in `ide-helper:models` (#1541) * Add `\\static` as check For some reason, the `static` keyword as a return type, does not return `isBuiltin()` === true, so a `\\` is added. We need to manually add it to the built in check. * Update ModelsCommand.php * Add tests * Add CHANGELOG.md entry --------- Co-authored-by: Markus Podar Co-authored-by: Barry vd. Heuvel --- CHANGELOG.md | 1 + src/Console/ModelsCommand.php | 2 +- .../CustomCasterWithStaticReturnType.php | 19 +++++++++++++++++++ .../LaravelCustomCasts/Models/CustomCast.php | 2 ++ .../__snapshots__/Test__test__1.php | 3 +++ 5 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 tests/Console/ModelsCommand/LaravelCustomCasts/Casts/CustomCasterWithStaticReturnType.php diff --git a/CHANGELOG.md b/CHANGELOG.md index c2b9751..b0cca66 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file. ### Fixed - Fix return value of query scopes from parent class [#1366 / sforward](https://github.com/barryvdh/laravel-ide-helper/pull/1366) +- Add static to isBuiltin() check in ide-helper:models [#1541 / bram-pkg](https://github.com/barryvdh/laravel-ide-helper/pull/1541) - Fix for getSomethingAttribute functions which return a collection with type templating in the phpDoc. [#1567 / stefanScrumble](https://github.com/barryvdh/laravel-ide-helper/pull/1567) ### Changed diff --git a/src/Console/ModelsCommand.php b/src/Console/ModelsCommand.php index f9571ca..9e808d8 100644 --- a/src/Console/ModelsCommand.php +++ b/src/Console/ModelsCommand.php @@ -1633,7 +1633,7 @@ class ModelsCommand extends Command protected function getReflectionNamedType(ReflectionNamedType $paramType): string { $parameterName = $paramType->getName(); - if (!$paramType->isBuiltin()) { + if (!$paramType->isBuiltin() && $paramType->getName() !== 'static') { $parameterName = '\\' . $parameterName; } diff --git a/tests/Console/ModelsCommand/LaravelCustomCasts/Casts/CustomCasterWithStaticReturnType.php b/tests/Console/ModelsCommand/LaravelCustomCasts/Casts/CustomCasterWithStaticReturnType.php new file mode 100644 index 0000000..5a65eaf --- /dev/null +++ b/tests/Console/ModelsCommand/LaravelCustomCasts/Casts/CustomCasterWithStaticReturnType.php @@ -0,0 +1,19 @@ + CustomCasterWithReturnType::class, + 'casted_property_with_static_return_type' => CustomCasterWithStaticReturnType::class, 'casted_property_with_return_docblock' => CustomCasterWithDocblockReturn::class, 'casted_property_with_return_docblock_fqn' => CustomCasterWithDocblockReturnFqn::class, 'casted_property_with_return_primitive' => CustomCasterWithPrimitiveReturn::class, diff --git a/tests/Console/ModelsCommand/LaravelCustomCasts/__snapshots__/Test__test__1.php b/tests/Console/ModelsCommand/LaravelCustomCasts/__snapshots__/Test__test__1.php index 44a4fc8..e9e446d 100644 --- a/tests/Console/ModelsCommand/LaravelCustomCasts/__snapshots__/Test__test__1.php +++ b/tests/Console/ModelsCommand/LaravelCustomCasts/__snapshots__/Test__test__1.php @@ -15,6 +15,7 @@ use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Cas 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; +use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CustomCasterWithStaticReturnType; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\ExtendedSelfCastingCasterWithStaticDocblockReturn; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\ExtendedSelfCastingCasterWithThisDocblockReturn; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\InboundAttributeCaster; @@ -39,6 +40,7 @@ use Illuminate\Database\Eloquent\Model; * @property ExtendedSelfCastingCasterWithStaticDocblockReturn $extended_casted_property_with_static_return_docblock * @property ExtendedSelfCastingCasterWithThisDocblockReturn $extended_casted_property_with_this_return_docblock * @property SelfCastingCasterWithStaticDocblockReturn $casted_property_with_static_return_docblock_and_param + * @property CustomCasterWithStaticReturnType $casted_property_with_static_return_type * @property \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CastedProperty $casted_property_with_castable * @property \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CastedProperty $casted_property_with_anonymous_cast * @property CastableWithoutReturnType $casted_property_without_return_type @@ -67,6 +69,7 @@ class CustomCast extends Model { protected $casts = [ 'casted_property_with_return_type' => CustomCasterWithReturnType::class, + 'casted_property_with_static_return_type' => CustomCasterWithStaticReturnType::class, 'casted_property_with_return_docblock' => CustomCasterWithDocblockReturn::class, 'casted_property_with_return_docblock_fqn' => CustomCasterWithDocblockReturnFqn::class, 'casted_property_with_return_primitive' => CustomCasterWithPrimitiveReturn::class,