Passed
Push — master ( ae3b0b...26e9e8 )
by Andy
01:17
created

Date::setYear()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Palmtree\Chrono;
4
5
use Palmtree\Chrono\Option\DatePeriods;
6
7
/**
8
 * @method self add(int $value, string $period)
9
 * @method self subtract(int $value, string $period)
10
 */
11
class Date extends DateTime
12
{
13
    /** @var Date */
14
    private static $today;
15
16 13
    public function __construct(string $time = 'now', $timezone = null)
17
    {
18 13
        parent::__construct($time, $timezone);
19
20 13
        $this->dateTime->setTime(0, 0);
21 13
    }
22
23 1
    public function isToday(): bool
24
    {
25 1
        if (self::$today === null) {
26 1
            self::$today = new self('now', $this->dateTime->getTimezone());
27
        }
28
29 1
        return $this->isSame(self::$today, DatePeriods::DAY);
30
    }
31
32
    public function setYear(int $year): self
33
    {
34
        return $this->setDate($year, $this->dateTime->format('m'), $this->dateTime->format('d'));
0 ignored issues
show
Bug introduced by
$this->dateTime->format('m') of type string is incompatible with the type integer expected by parameter $month of Palmtree\Chrono\Date::setDate(). ( Ignorable by Annotation )

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

34
        return $this->setDate($year, /** @scrutinizer ignore-type */ $this->dateTime->format('m'), $this->dateTime->format('d'));
Loading history...
Bug introduced by
$this->dateTime->format('d') of type string is incompatible with the type integer expected by parameter $day of Palmtree\Chrono\Date::setDate(). ( Ignorable by Annotation )

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

34
        return $this->setDate($year, $this->dateTime->format('m'), /** @scrutinizer ignore-type */ $this->dateTime->format('d'));
Loading history...
35
    }
36
37
    public function setMonth(int $month): self
38
    {
39
        return $this->setDate($this->dateTime->format('Y'), $month, $this->dateTime->format('d'));
0 ignored issues
show
Bug introduced by
$this->dateTime->format('Y') of type string is incompatible with the type integer expected by parameter $year of Palmtree\Chrono\Date::setDate(). ( Ignorable by Annotation )

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

39
        return $this->setDate(/** @scrutinizer ignore-type */ $this->dateTime->format('Y'), $month, $this->dateTime->format('d'));
Loading history...
Bug introduced by
$this->dateTime->format('d') of type string is incompatible with the type integer expected by parameter $day of Palmtree\Chrono\Date::setDate(). ( Ignorable by Annotation )

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

39
        return $this->setDate($this->dateTime->format('Y'), $month, /** @scrutinizer ignore-type */ $this->dateTime->format('d'));
Loading history...
40
    }
41
42
    public function setDay(int $day): self
43
    {
44
        return $this->setDate($this->dateTime->format('Y'), $this->dateTime->format('m'), $day);
0 ignored issues
show
Bug introduced by
$this->dateTime->format('m') of type string is incompatible with the type integer expected by parameter $month of Palmtree\Chrono\Date::setDate(). ( Ignorable by Annotation )

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

44
        return $this->setDate($this->dateTime->format('Y'), /** @scrutinizer ignore-type */ $this->dateTime->format('m'), $day);
Loading history...
Bug introduced by
$this->dateTime->format('Y') of type string is incompatible with the type integer expected by parameter $year of Palmtree\Chrono\Date::setDate(). ( Ignorable by Annotation )

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

44
        return $this->setDate(/** @scrutinizer ignore-type */ $this->dateTime->format('Y'), $this->dateTime->format('m'), $day);
Loading history...
45
    }
46
47
    public function setDate(int $year, int $month, int $day): self
48
    {
49
        $this->dateTime->setDate($year, $month, $day);
50
51
        return $this;
52
    }
53
54 10
    protected function getFormatFromTimePrecision(?string $precision): string
55
    {
56 10
        return DatePeriods::getDateFormat($precision ?? DatePeriods::DAY);
57
    }
58
}
59