Skip to content

phpstan: Missing parameter $isostr (DateTimeInterface) in call to DatePeriod constructor. #5553

@MickaelCa

Description

@MickaelCa

Bug report

Code snippet that reproduces the problem

    public function weekNumberToWorkRange(int $week, int $year): DatePeriod
    {
        $dto = new DateTime();
        $dto->setISODate($year, $week);
        $dto->setTime(8, 0, 0, 0);

        $start = clone $dto;
        $dto->modify('+4 days');
        $end = clone $dto;
        $end->setTime(18, 0, 0, 0);

        return new DatePeriod(
            start: $start,
            interval: new \DateInterval('P1D'),
            end: $end
        );
    }
 ------ ----------------------------------------------------------------------------------
  Line   Service/WeekService.php
 ------ ----------------------------------------------------------------------------------
  29     Missing parameter $isostr (DateTimeInterface) in call to DatePeriod constructor.
  30     Unknown parameter $start in call to DatePeriod constructor.
  31     Unknown parameter $interval in call to DatePeriod constructor.
 ------ ----------------------------------------------------------------------------------

https://phpstan.org/r/e3a7ab6f-80be-441d-a033-cccfd3bb1100

Expected output

No Errors, since DatePeriod has 3 constructors, and one of them correctly match

    /**
    * @param DateTimeInterface $start
    * @param DateInterval $interval
    * @param DateTimeInterface $end
    * @param int $options Can be set to DatePeriod::EXCLUDE_START_DATE.
    * @link https://php.net/manual/en/dateperiod.construct.php
    */
   public function __construct(DateTimeInterface $start, DateInterval $interval, DateTimeInterface $end, $options = 0) {}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions