laravel-ide-helper icon indicating copy to clipboard operation
laravel-ide-helper copied to clipboard

Redundant null type for CastsAttributes class

Open bbprojectnet opened this issue 2 years ago • 1 comments

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

bbprojectnet avatar Sep 12 '22 10:09 bbprojectnet

👍🏼

PRs welcome!

mfn avatar Sep 12 '22 11:09 mfn

This bug is annoying. Everytime i generate the model phpdocs i just replace null|null to null in my IDE

Sergiobop avatar Aug 03 '23 08:08 Sergiobop

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';
}

Sergiobop avatar Sep 06 '23 09:09 Sergiobop

This was fixed in the latest release; I saw also in my projects the "double null" disappear.

mfn avatar Feb 16 '24 22:02 mfn