Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thread docs bloks as primary source of type #1550

Open
matysekmichal opened this issue May 18, 2024 · 0 comments
Open

Thread docs bloks as primary source of type #1550

matysekmichal opened this issue May 18, 2024 · 0 comments

Comments

@matysekmichal
Copy link

I'm interested in the custom Laravel casts where I propose to thread a docs block as a primary source of type and then use a PHP type. I think that this approach is right, because in case below the docs block have more precise return type than the PHP type.

/**
 * @inheritDoc
 * @return CastedProperty[]
 */
public function get($model, string $key, $value, array $attributes): array
{
    return [];
}

Consequently a docs block should looks like below.

/**
 * 
 *
 * @property \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CastedProperty[] $casted_property_with_return_primitive_and_return_primitive_docblock
 *
 * instead
 * @property array $casted_property_with_return_primitive_and_return_primitive_docblock
 */

I know a workaround for this problem where you just need to remove the PHP type but that behavior was unexpected for me when I saw it for the first time.

Another example can by with the collection.

/**
 * @inheritDoc
 * @return Collection<int, CastedProperty>
 */
public function get($model, string $key, $value, array $attributes): Collection
{
    return [];
}

The change of the approach to threat docs blocks as a primary source of type is a little braking change but at the end of a day we have a better types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant