We use php-timecop in our application for test cases with time ("time travel"). And phpstan find errors for all standard time php functions like time(), microtime(), etc.
Example file timecop.php:
<?php
time(); // phpstan error
microtime(); // phpstan error
new DateTime(); // no error
timecop_travel(new DateTime('2018-01-01')); // no error
phpstan result for this file:
------ ---------------------------------------------------------------------
Line timecop.php
------ ---------------------------------------------------------------------
3 Call to function timecop_time() with incorrect case: time
4 Call to function timecop_microtime() with incorrect case: microtime
------ ---------------------------------------------------------------------
Perhaps you have a solution to this problem?
The problem is that function reflection behaves incorrectly when this extension is loaded:
$reflection = new \ReflectionFunction('time');
$reflection->getName() // returns timecop_time, confusing PHPStan
I could definitely improve this piece of code in CallToNonExistentFunctionRule so that it checks that strtolower() of both $reflection->getName() and resolved function name as called in the code matches before I report the incorrect case:
if ($function->getName() !== $this->broker->resolveFunctionName($node->name, $scope)) {
return [sprintf('Call to function %s() with incorrect case: %s', $function->getName(), $name)];
}
Did the proposed fix: https://github.com/phpstan/phpstan/commit/8fe942a5c44eb0656270b5d6096e307cd0d079aa
@ondrejmirtes thank you! Now it's working good!
Most helpful comment
Did the proposed fix: https://github.com/phpstan/phpstan/commit/8fe942a5c44eb0656270b5d6096e307cd0d079aa