Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHPStan reports that there is no constructor for DateTimeImmutable #36

Open
rquadling opened this issue Feb 20, 2018 · 1 comment
Open

Comments

@rquadling
Copy link

phpstan/phpstan#842

We have just started using Timecop for controlling time in our unit tests. Works REALLY well.

We also run PHPStan against all our code, to make sure things are sane and that they obey our standards.

One of the things the PHPStan is picking up on is a lack of a constructor in Timecop's DateTimeImmutable.

I've linked the PHPStan issue above, but the here is a snippet of the code and the error that PHPStan is generating.

<?php

namespace DT\ValueObjects;

use DateTimeImmutable;

class DateTimeMicro extends DateTimeImmutable
{
    public function __construct($time = 'now', $timezone = null)
    {
        if ($time === 'now') {
            list($dateTime, $micro) = explode('.', microtime(true));
            $time = date('Y-m-d H:i:s.', $dateTime).$micro;
        }
        parent::__construct($time, $timezone);
    }
}

With the Timecop extension enabled, we'll get an error:

DT\ValueObjects\DateTimeMicro::__construct() calls parent constructor but parent does not have one.

We have now configured things to only enable Timecop when running unit tests and use a polyfill for the Timecop functions we are using for PHPStan. That is all working fine.

But it is all a bit of a kerfuffle which could probably be fixed within Timecop.

@ondrejmirtes
Copy link

FYI this fix in PHPStan allegedly works: phpstan/phpstan#2801 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants