Passed
Push — master ( 9223d2...163f52 )
by Christian
55s queued 10s
created

Time::getTimeStamp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace RemotelyLiving\PHPDNS\Resolvers\Traits;
4
5
trait Time
6
{
7
    /**
8
     * @var \DateTimeImmutable|null
9
     */
10
    private $dateTimeImmutable = null;
11
12
    public function setDateTimeImmutable(\DateTimeImmutable $dateTimeImmutable): void
13
    {
14
        $this->dateTimeImmutable = $dateTimeImmutable;
15
    }
16
17
    public function getTimeStamp() : int
18
    {
19
        return $this->getNewDateTimeImmutable()->getTimestamp();
20
    }
21
22
    private function getNewDateTimeImmutable(): \DateTimeImmutable
23
    {
24
        if (!$this->dateTimeImmutable) {
25
            $this->dateTimeImmutable = new \DateTimeImmutable();
26
        }
27
28
        return /** @scrutinizer ignore-type */ $this->dateTimeImmutable
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->dateTimeIm...e->setTimestamp(time()) could return the type false which is incompatible with the type-hinted return DateTimeImmutable. Consider adding an additional type-check to rule them out.
Loading history...
29
            ->setTimestamp(time());
30
    }
31
}
32