barryvdh / laravel-ide-helper

IDE Helper for Laravel
MIT License
14.17k stars 1.16k forks source link

Some migration datatypes get documented as string instead of actual datatype #1346

Closed valdezet closed 2 years ago

valdezet commented 2 years ago

Versions:

Description:

Timestamps

Timestamp datatypes are documented as string without the Eloquent $casts attribute

Decimals

decimal()->nullable() migration fields get documented as string|null instead of float.

Steps To Reproduce:

Timestamps

One of the fields included in Users table migration is $email_verified_at and with the migration:

$table->timestamp('email_verified_at')->nullable();

With $casts eloquent attribute, this gets documented properly as a timestamp

Cast
    protected $casts = [
        'email_verified_at' => 'datetime',
    ];
Resulting Docblock property:
 * @property \Illuminate\Support\Carbon|null $email_verified_at

But without the cast, this gets documented as string|null.

 * @property string|null $email_verified_at

Decimals / Floats

decimals get documented as a string|null property instead of float

Migration:
 $table->decimal('total_amount', 9, 2)->nullable();
resulting Docblock
 * @property string|null $total_amount
mfn commented 2 years ago

It's late and I didn't fully think it through, but I think both cases are expected this way.

Can you check this?

valdezet commented 2 years ago

I don't know when I'll get the time to check this out.

I agree with you with the datetime.

And, while I didn't expect decimal fields to not give a float, I think it makes sense for people who work with high-precision floats. I just didn't have experience having to work with one though.

valdezet commented 2 years ago

Just checked it out using VSCode XDebug and Chrome DevTools.

The XDebug gets the type as double but the variable gets sent to the browser as string.

Code

        $total_amount = $model->total_amount;
        $typeof_total_amount = gettype($model->total_amount);

XDebug on VSCode

$total_amount = 255.16
$typeof_total_amount = "double"

Chrome DevTools

total_amount: "255.16"

mfn commented 2 years ago

So no error in ide-helper \o/, that's just the way how it works ™️

And indeed, if you want a different type in PHP, setting casts it the way to go and ide-helper will pick it up correctly.

Closing, as I don't see an issue with this library!