Skip to content

Null comparison detection stored on a boolean variable #800

@soullivaneuh

Description

@soullivaneuh

Summary of a problem or a feature request

When a null comparison is store on a variable, it not considered by PHPSTan.

Code snippet that reproduces the problem

$isLastInvoice = null !== $purchase->getCancellationDate() && $purchase->getCancellationDate()->getTimestamp() < $invoice->getPeriodEnd()->getTimestamp();

$proportionBeginDate = $purchase->getNextInvoiceDate();
$proportionEndDate = $isLastInvoice ? $purchase->getCancellationDate() : $invoice->getPeriodEnd();
$proportionDiffMonths = DateDiff::diffMonths($proportionBeginDate, $proportionEndDate);

$purchase->getCancellationDate() is checked against null on $isLastInvoice.

Expected output

Nothing, it should be good AFAIK. But I have:

Parameter #2 $date2 of static method AppBundle\Tools\DateDiff::diffMonths() expects DateTime, DateTime|null given.  

I don't have the issue without boo-lean variable storage:

$proportionBeginDate = $purchase->getNextInvoiceDate();
$proportionEndDate =
    null !== $purchase->getCancellationDate()
    && $purchase->getCancellationDate()->getTimestamp() < $invoice->getPeriodEnd()->getTimestamp()
        ? $purchase->getCancellationDate() : $invoice->getPeriodEnd()
;
$proportionDiffMonths = DateDiff::diffMonths($proportionBeginDate, $proportionEndDate);

Maybe already reported, but I can't find something similar on the issue list.

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