jbboehr / phpstan-laravel-validation

GNU Affero General Public License v3.0
4 stars 1 forks source link

Validating required|integer is turning into float|int|numeric-string #2

Closed Firehed closed 1 year ago

Firehed commented 1 year ago

Hi - thanks for putting this together! It's helping me out a lot with typechecking Laravel validation results :)

I noticed that the following validation appears to be producing the wrong type:


        $valid = $request->validate([
            'amount' => 'required|integer',
        ])->validated();
        \PHPStan\dumpType($valid); //  array{amount: float|int|numeric-string}

Unless Laravel's integer validation is doing something really odd, it seems like the result of this should instead be int|numeric-string, without the float in the union.

I'm currently using dev-master 1fe0f3b of this extension.

jbboehr commented 1 year ago

Yeah definitely looks like a problem: https://github.com/jbboehr/phpstan-laravel-validation/blob/1fe0f3b4a5bddb3ae4df7d59025cd181caa1142a/src/Validation/TypeResolver.php#L158

I'm testing against a dump from the laravel test suite but that only catches too-specific types, not the other way around :)