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

Time   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 25
rs 10
c 1
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setDateTimeImmutable() 0 3 1
A getTimeStamp() 0 3 1
A getNewDateTimeImmutable() 0 8 2
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