Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

phpstan > 1.12.0 has droped support for models casts #2038

Closed
jenriquez-bit opened this issue Sep 12, 2024 · 3 comments
Closed

phpstan > 1.12.0 has droped support for models casts #2038

jenriquez-bit opened this issue Sep 12, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@jenriquez-bit
Copy link

jenriquez-bit commented Sep 12, 2024

  • Larastan Version: 2.9.8
  • Laravel Version: 11.22.0

Description

After upgrade phpstan to a version greater than 1.12.0 casted enums, array, customs casts are not treated as casted type

Laravel code where the issue was found

class Order extends Model
{
    /**
     * @return array{
     *     status: 'App\Enums\Status',
     * }
     */
    protected function casts(): array
    {
        return [
            'status' => Status::class,
        ];
    }
}

If I run

$order = Order::first();
$order->status === Status::PAID;

phpstan output:

 ------ -------------------------------------------------------------------------------------------------------------------------------------------- 
  Line   OrderController.php                                                                                                                         
 ------ -------------------------------------------------------------------------------------------------------------------------------------------- 
  24     Strict comparison using === between string and App\Enums\Status::PAID will always evaluate to false.                                    
         💡 Because the type is coming from a PHPDoc, you can turn off this check by setting treatPhpDocTypesAsCertain: false in your phpstan.neon.                                                                                                              
 ------ -------------------------------------------------------------------------------------------------------------------------------------------- 

In phpstan 1.12.0 everything works fine

@jenriquez-bit jenriquez-bit added the bug Something isn't working label Sep 12, 2024
@calebdw
Copy link
Contributor

calebdw commented Sep 12, 2024

CI is passing on > PHPStan 1.12 after fixing the incorrect docs and stubs #2028

The Laravel 11 failures on that PR are related to #1990 and not model casting

@sirikkoster
Copy link

When is this fix going to be released?

@canvural
Copy link
Collaborator

When is this fix going to be released?

Hopefully soon. I still need to test some stuff to be sure it works correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants