DateTimeCreator::getNowDateTime()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace Smartbox\CoreBundle\Utils\Helper;
4
5
class DateTimeCreator
6
{
7
    /**
8
     * Using the same strategy as Monolog does for creating time stamps with micro seconds.
9
     *
10
     * microtime without \ is used as it we need to be able to ClockMock it.
11
     *
12
     * @return \DateTime
13
     */
14
    public static function getNowDateTime()
15
    {
16
        if (PHP_VERSION_ID < 70100) {
17
            $now = \DateTime::createFromFormat('U.u', \sprintf('%.6F', microtime(true)));
0 ignored issues
show
Comprehensibility Best Practice introduced by
The expression \DateTime::createFromFor...6F', microtime(true))); of type DateTime|false adds false to the return on line 22 which is incompatible with the return type documented by Smartbox\CoreBundle\Util...Creator::getNowDateTime of type DateTime. It seems like you forgot to handle an error condition.
Loading history...
18
        } else {
19
            $now = new \DateTime(null);
20
        }
21
22
        return $now;
23
    }
24
}
25