DateTime   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 42.11%

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 43
ccs 8
cts 19
cp 0.4211
rs 10
c 0
b 0
f 0
wmc 8

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setMinute() 0 3 1
A setMicroseconds() 0 3 1
A setHour() 0 3 1
A getFormatFromTimePrecision() 0 9 2
A setTime() 0 5 1
A setSecond() 0 3 1
A __construct() 0 3 1
1
<?php
2
3
namespace Palmtree\Chrono;
4
5
use Palmtree\Chrono\Option\DatePeriods;
6
use Palmtree\Chrono\Option\TimePeriods;
7
8
/**
9
 * @method self   add(int $value, string $period)
10
 * @method self   subtract(int $value, string $period)
11
 * @method self   setDate(int $year, int $month, int $day)
12
 * @method self   setDay(int $day)
13
 * @method self   setMonth(int $month)
14
 * @method self   setYear(int $year)
15
 * @method static self   fromNative(\DateTime $dateTime)
16
 * @method static null|self min(...$dates)
17
 * @method static null|self max(...$dates)
18
 */
19
class DateTime extends Date
20
{
21 12
    public function __construct(string $time = 'now', $timezone = null)
22
    {
23 12
        $this->dateTime = $this->createInternalDateTime($time, $timezone);
24 12
    }
25
26
    public function setTime(int $hour, int $minute, int $second = 0, int $microseconds = 0): self
27
    {
28
        $this->dateTime->setTime($hour, $minute, $second, $microseconds);
29
30
        return $this;
31
    }
32
33
    public function setHour(int $hour): self
34
    {
35
        return $this->setTime($hour, $this->dateTime->format('i'), $this->dateTime->format('s'), $this->dateTime->format('u'));
0 ignored issues
show
Bug introduced by
$this->dateTime->format('u') of type string is incompatible with the type integer expected by parameter $microseconds of Palmtree\Chrono\DateTime::setTime(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

35
        return $this->setTime($hour, $this->dateTime->format('i'), $this->dateTime->format('s'), /** @scrutinizer ignore-type */ $this->dateTime->format('u'));
Loading history...
Bug introduced by
$this->dateTime->format('i') of type string is incompatible with the type integer expected by parameter $minute of Palmtree\Chrono\DateTime::setTime(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

35
        return $this->setTime($hour, /** @scrutinizer ignore-type */ $this->dateTime->format('i'), $this->dateTime->format('s'), $this->dateTime->format('u'));
Loading history...
Bug introduced by
$this->dateTime->format('s') of type string is incompatible with the type integer expected by parameter $second of Palmtree\Chrono\DateTime::setTime(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

35
        return $this->setTime($hour, $this->dateTime->format('i'), /** @scrutinizer ignore-type */ $this->dateTime->format('s'), $this->dateTime->format('u'));
Loading history...
36
    }
37
38
    public function setMinute(int $minute): self
39
    {
40
        return $this->setTime($this->dateTime->format('H'), $minute, $this->dateTime->format('s'), $this->dateTime->format('u'));
0 ignored issues
show
Bug introduced by
$this->dateTime->format('u') of type string is incompatible with the type integer expected by parameter $microseconds of Palmtree\Chrono\DateTime::setTime(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

40
        return $this->setTime($this->dateTime->format('H'), $minute, $this->dateTime->format('s'), /** @scrutinizer ignore-type */ $this->dateTime->format('u'));
Loading history...
Bug introduced by
$this->dateTime->format('s') of type string is incompatible with the type integer expected by parameter $second of Palmtree\Chrono\DateTime::setTime(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

40
        return $this->setTime($this->dateTime->format('H'), $minute, /** @scrutinizer ignore-type */ $this->dateTime->format('s'), $this->dateTime->format('u'));
Loading history...
Bug introduced by
$this->dateTime->format('H') of type string is incompatible with the type integer expected by parameter $hour of Palmtree\Chrono\DateTime::setTime(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

40
        return $this->setTime(/** @scrutinizer ignore-type */ $this->dateTime->format('H'), $minute, $this->dateTime->format('s'), $this->dateTime->format('u'));
Loading history...
41
    }
42
43
    public function setSecond(int $second): self
44
    {
45
        return $this->setTime($this->dateTime->format('H'), $this->dateTime->format('i'), $second, $this->dateTime->format('u'));
0 ignored issues
show
Bug introduced by
$this->dateTime->format('H') of type string is incompatible with the type integer expected by parameter $hour of Palmtree\Chrono\DateTime::setTime(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

45
        return $this->setTime(/** @scrutinizer ignore-type */ $this->dateTime->format('H'), $this->dateTime->format('i'), $second, $this->dateTime->format('u'));
Loading history...
Bug introduced by
$this->dateTime->format('u') of type string is incompatible with the type integer expected by parameter $microseconds of Palmtree\Chrono\DateTime::setTime(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

45
        return $this->setTime($this->dateTime->format('H'), $this->dateTime->format('i'), $second, /** @scrutinizer ignore-type */ $this->dateTime->format('u'));
Loading history...
Bug introduced by
$this->dateTime->format('i') of type string is incompatible with the type integer expected by parameter $minute of Palmtree\Chrono\DateTime::setTime(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

45
        return $this->setTime($this->dateTime->format('H'), /** @scrutinizer ignore-type */ $this->dateTime->format('i'), $second, $this->dateTime->format('u'));
Loading history...
46
    }
47
48
    public function setMicroseconds(int $microseconds): self
49
    {
50
        return $this->setTime($this->dateTime->format('H'), $this->dateTime->format('i'), $this->dateTime->format('s'), $microseconds);
0 ignored issues
show
Bug introduced by
$this->dateTime->format('H') of type string is incompatible with the type integer expected by parameter $hour of Palmtree\Chrono\DateTime::setTime(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

50
        return $this->setTime(/** @scrutinizer ignore-type */ $this->dateTime->format('H'), $this->dateTime->format('i'), $this->dateTime->format('s'), $microseconds);
Loading history...
Bug introduced by
$this->dateTime->format('i') of type string is incompatible with the type integer expected by parameter $minute of Palmtree\Chrono\DateTime::setTime(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

50
        return $this->setTime($this->dateTime->format('H'), /** @scrutinizer ignore-type */ $this->dateTime->format('i'), $this->dateTime->format('s'), $microseconds);
Loading history...
Bug introduced by
$this->dateTime->format('s') of type string is incompatible with the type integer expected by parameter $second of Palmtree\Chrono\DateTime::setTime(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

50
        return $this->setTime($this->dateTime->format('H'), $this->dateTime->format('i'), /** @scrutinizer ignore-type */ $this->dateTime->format('s'), $microseconds);
Loading history...
51
    }
52
53 1
    protected function getFormatFromTimePrecision(?string $precision): string
54
    {
55
        try {
56 1
            $format = TimePeriods::getDateFormat($precision ?? TimePeriods::SECOND);
57 1
        } catch (\InvalidArgumentException $e) {
58 1
            $format = DatePeriods::getDateFormat($precision ?? DatePeriods::DAY);
59
        }
60
61 1
        return $format;
62
    }
63
}
64