Cannot ignore line, cannot not ignore line #4314
-
I have this little snippet of code in a trait: trait Commentable
{
final protected static function bootCommentable(): void
{
static::deleted(static function (self $commentable): void {
$softDeletes = in_array(SoftDeletes::class, class_uses(static::class));
$forceDeleting = $softDeletes ? $commentable->isForceDeleting() : false;
if (!($softDeletes xor $forceDeleting)) {
$commentable->comments()->delete();
}
});
}
// ...
} Running phpstan gives me this:
Now I know my code is fine, so if I tell phpstan to ignore that line... $forceDeleting = $softDeletes ? $commentable->isForceDeleting() : false; // @phpstan-ignore-line phpstan gives me the following:
What am I missing here? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
I think it's an issue with PHP-Parser, I remember a similar issue that have been recently opened here. |
Beta Was this translation helpful? Give feedback.
-
For a short-term solution, I just added the error to the "ignored errors" list in my |
Beta Was this translation helpful? Give feedback.
-
Hello, I think that the problem is that:
Trait is analysed in context of each class that uses the trait, so PHPStan complains there's nothing to ignore when analyzing Commentable in the context of You could change your code like this and get rid of the need for ignoring: $forceDeleting = method_exists($commentable, 'isForceDeleting') ? $commentable->isForceDeleting() : false; Let me know how it works :) |
Beta Was this translation helpful? Give feedback.
For a short-term solution, I just added the error to the "ignored errors" list in my
phpstan.neon
file. It's not ideal, but it works.