Skip to content

DatePeriod with start, interval and end generates too many errors #7048

@janbarasek

Description

@janbarasek

Bug report

When using the DatePeriod object, I am dealing with many errors at the same time that cannot be easily fixed.

Code snippet that reproduces the problem

https://phpstan.org/r/d8c2c1e8-1bab-410d-90bf-252709b5eab4

return new \DatePeriod(
	start: new \DateTime('now'),
	interval: new \DateInterval('P1D'),
	end: new \DateTime('now + 3 days'),
);

Snímek obrazovky 2022-04-17 v 11 59 27

Expected output

The DatePeriod object can use 3 possible constructors with named arguments and different types: https://www.php.net/manual/en/dateperiod.construct.php

public DatePeriod::__construct(
    DateTimeInterface $start,
    DateInterval $interval,
    int $recurrences,
    int $options = 0
);

public DatePeriod::__construct(
    DateTimeInterface $start,
    DateInterval $interval,
    DateTimeInterface $end,
    int $options = 0
);

public DatePeriod::__construct(string $isostr, int $options = 0);

Did PHPStan help you today? Did it make you happy in any way?

I really love PhpStan!

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions