Skip to content

Commit

Permalink
Add static to isBuiltin() check in ide-helper:models (#1541)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
Co-authored-by: Barry vd. Heuvel <[email protected]>
  • Loading branch information
3 people authored Jul 12, 2024
1 parent f7a3dc8 commit f5759e2
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Console/ModelsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -1633,7 +1633,7 @@ protected function extractReflectionTypes(ReflectionType $reflection_type)
protected function getReflectionNamedType(ReflectionNamedType $paramType): string
{
$parameterName = $paramType->getName();
if (!$paramType->isBuiltin()) {
if (!$paramType->isBuiltin() && $paramType->getName() !== 'static') {
$parameterName = '\\' . $parameterName;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts;

use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
use Illuminate\Database\Eloquent\Model;

class CustomCasterWithStaticReturnType implements CastsAttributes
{
public function get(Model $model, string $key, mixed $value, array $attributes): static
{
// TODO: Implement get() method.
}

public function set(Model $model, string $key, mixed $value, array $attributes): array
{
// TODO: Implement set() method.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
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;
Expand All @@ -26,6 +27,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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
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;
Expand All @@ -39,6 +40,7 @@
* @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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit f5759e2

Please sign in to comment.