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

Model field (enum via $casts) has type mixed #1505

Closed
levu42 opened this issue Jan 3, 2023 · 2 comments · Fixed by #1494
Closed

Model field (enum via $casts) has type mixed #1505

levu42 opened this issue Jan 3, 2023 · 2 comments · Fixed by #1494

Comments

@levu42
Copy link

levu42 commented Jan 3, 2023

  • Larastan Version: 2.3.4
  • --level used: 8

Description

I have a model where one column is represented as a PHP Enum (string backed enum with currently only one possible option), declared via $casts, but PHPStan reports the type incorrectly as mixed.

Laravel code where the issue was found

enum MyModelType: string
{
    case Foo = 'foo';
}

class MyModel {
    protected $casts = [
        'type' => MyModelType::class,
    ];
}

class Bar {
    function baz(MyModel $m): int
    {
        return match($m->type) {
            MyModelType::Foo => 42,
        };
    }
}

I get now the error message Match expression does not handle remaining value: mixed and when I use \PHPStan\dumpType($m->type) I get Dumped type: mixed instead of the expected MyModelType.

It seems like this only starts happening since I upgraded from 2.3.0 -> 2.3.4 but I'm not 100% sure about that.

@canvural
Copy link
Collaborator

canvural commented Jan 3, 2023

This might be fixed with #1494

@levu42
Copy link
Author

levu42 commented Jan 3, 2023

@canvural Awesome!

@canvural canvural linked a pull request Jan 12, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants