laravel-ide-helper
laravel-ide-helper copied to clipboard
Redundant null type for CastsAttributes class
Versions:
- ide-helper Version: 2.12.3
- Laravel Version: 9.29.0
- PHP Version: 8.1
Description:
For castable witch return T|null
IDE helper generates T|null|null
type, for example:
protected $casts = [
'timezone' => AsTimeZone::class,
];
class AsTimeZone implements CastsAttributes
{
/**
* @inheritDoc
*/
public function get($model, string $key, $value, array $attributes): ?DateTimeZone
{
...
}
/**
* @inheritDoc
*/
public function set($model, string $key, $value, array $attributes): ?string
{
...
}
}
@property \DateTimeZone|null|null $timezone
👍🏼
PRs welcome!
This bug is annoying. Everytime i generate the model phpdocs i just replace null|null
to null
in my IDE
I fixed this bug on my local ModelsCommand.
Everywhere i saw something like:
if ($nullable) {
$newType .= '|null';
}
I changed it with:
if ($nullable && !str_ends_with($newType, '|null')) {
$newType .= '|null';
}
This was fixed in the latest release; I saw also in my projects the "double null" disappear.