larastan: Access to undefined property after squashing migrations with prune

  • Larastan Version: 2.7.0
  • --level used: 5

Description

After squashing migrations and pruning them, PHPStan generates a whole lot of new errors: Access to an undefined property Model::$exampleProperty. This is because the migrations do not longer exist, but this should not be problem since Larastan should use the dumped schema instead.

The same problem has been described in an old issue here, which seemed to be solved, but it seems to not be working for us. I also found another user stating the same.

About this issue

  • Original URL
  • State: closed
  • Created 3 months ago
  • Comments: 16 (6 by maintainers)

Most upvoted comments

I found the issue, and it’s not related to Larastan. If I have a closer look at which properties are undefined, there’s an important detail: The properties in question are not defined in a table column, but in the $casts property of a model, like so:

class SomeModel extends Model
{
    protected $casts => [
        'principal' => MoneyCast::class . ':principal_in_cents',
    ];
}

So the principal column does not exist in my table, so it makes sense why Larastan throws an error. But then that would mean that Larastan should’ve failed on an earlier stage, so why would this fail after squashing my migrations? The answer lays in my schema dump: the column has changed in the table from principal to principal_in_cents: Larastan was using our outdated dump which resulted in the errors not being shown before. We don’t have calls to principal_in_cents, so it makes sense why no errors were generated even if the column can’t be found by Larastan.

I thank you @calebdw and @szepeviktor for trying to help me figure this one out, and sorry for it being a issue not related to Larastan 😅