Passed
Pull Request — master (#407)
by Kirill
05:39
created

DateTimeFactory::now()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 1
1
<?php
2
3
/**
4
 * This file is part of Spiral Framework package.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Distribution\Internal;
13
14
/**
15
 * @internal DateTimeFactory is an internal library class, please do not use it in your code.
16
 * @psalm-internal Spiral\Distribution
17
 */
18
final class DateTimeFactory implements DateTimeFactoryInterface
19
{
20
    /**
21
     * @var string
22
     */
23
    private const DEFAULT_TIMEZONE = 'UTC';
24
25
    /**
26
     * @var string
27
     */
28
    private const DATE_NOW = 'now';
29
30
    /**
31
     * @var string
32
     */
33
    private $timezone;
34
35
    /**
36
     * @param string $timezone
37
     */
38
    public function __construct(string $timezone = self::DEFAULT_TIMEZONE)
39
    {
40
        $this->timezone = new \DateTimeZone($timezone);
0 ignored issues
show
Documentation Bug introduced by
It seems like new DateTimeZone($timezone) of type DateTimeZone is incompatible with the declared type string of property $timezone.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
41
    }
42
43
    /**
44
     * {@inheritDoc}
45
     */
46
    public function now(): \DateTimeImmutable
47
    {
48
        return new \DateTimeImmutable(self::DATE_NOW, $this->timezone);
0 ignored issues
show
Bug introduced by
$this->timezone of type string is incompatible with the type DateTimeZone|null expected by parameter $timezone of DateTimeImmutable::__construct(). ( Ignorable by Annotation )

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

48
        return new \DateTimeImmutable(self::DATE_NOW, /** @scrutinizer ignore-type */ $this->timezone);
Loading history...
49
    }
50
}
51