Skip to content

(minor) PHPStan warning #41

@BrekiTomasson

Description

@BrekiTomasson

I'm going through my codebase to reduce the amount of warnings thrown by PHPStan (using Larastan), and I've run into one that I'm not entirely sure how to handle as it relates to an interaction with this package. In one of my models, I have the following method:

public function getFlagDate(string $name): string|null
{
    return $this->flags->firstWhere('name', $name)?->created_at->toDateString();
}

This allows me to do something like this, assuming the flag migrated was added to the user on March 19th, 2025:

User::firstWhere('email', 'test@example.com')->getFlagDate('migrated');
> "2025-03-19"

However, when I run PHPStan, I get the following warning regarding this method:

  215    Access to an undefined property Illuminate\Database\Eloquent\Model::$created_at.
         🪪  property.notFound
         💡 Learn more: https://phpstan.org/blog/solving-phpstan-access-to-undefined-property

This could be fixed if the Model file in this package contained a PHPDoc header, something like:

/**
 * @property int $id
 * @property string $name
 * @property string $flaggable_type
 * @property int $flaggable_id
 * @property Carbon\Carbon $created_at
 * @property Carbon\Carbon|null $updated_at
 */

Naturally, this is just a suggestion; I absolutely understand if this feels like a pointless thing to add, but it would help reduce the need to extend the model class for something so minor.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions