Thread docs bloks as primary source of type
matysekmichal opened this issue · comments
michal commented
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.