Skip to content

TimeFuncCallToCarbonRector: time() returns int, while Carbon::now()->timestamp returns float|int|string #9018

@melbings

Description

@melbings

Bug Report

Subject Details
Rector version v2.0.7

TimeFuncCallToCarbonRector refactors $time = time(); to Carbon::now()->timestamp.

This breaks for example Phpstan validation:

  • time() returns int
  • Carbon's timestamp property may return float, int or string (at least, per docblock)

Minimal PHP Code Causing Issue

See https://getrector.com/demo/26b5038a-7f90-46df-bbb7-3f6143e51621

<?php

time();

Results in:

<?php
 
-time();
+\Carbon\Carbon::now()->timestamp;

Expected Behaviour

Rector might be better off using Carbon's getTimestamp() method, which does return int:

<?php
 
-time();
+\Carbon\Carbon::now()->getTimestamp();

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions