Completed
Push — feature/moveCommonLogicToTrait ( df8bcc...95b46c )
by Andreas
07:29
created

DateTimeBase   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
cbo 0
dl 0
loc 36
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setTimezone() 0 6 1
A createFromFormat() 0 11 2
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * Copyright Andrea Heigl <[email protected]>
7
 *
8
 * Licenses under the MIT-license. For details see the included file LICENSE.md
9
 */
10
11
namespace UTCDateTime;
12
13
use function date_default_timezone_get;
14
use DateTimeZone;
15
use function trigger_error;
16
17
trait DateTimeBase
18
{
19
    /**
20
     * @param DateTimeZone $timezone
21
     *
22
     * @return self
23
     */
24 4
    public function setTimezone($timezone)
25
    {
26 4
        trigger_error('Setting a timezone on a UTCDateTime-object doesn\'t make sense');
27
28 2
        return $this;
29
    }
30
31
    /**
32
     * Parse a string into a new DateTime object according to the specified format
33
     *
34
     * @param string $format Format accepted by date().
35
     * @param string $time String representing the time.
36
     * @param DateTimeZone $timezone A DateTimeZone object representing the desired time zone.
37
     *
38
     * @link http://php.net/manual/en/datetime.createfromformat.php
39
     * @return self
40
     */
41 4
    public static function createFromFormat($format, $time, DateTimeZone $timezone = null) : self
42
    {
43 4
        if (! $timezone) {
44 2
            $timezone = new DateTimeZone(date_default_timezone_get());
45
        }
46
47 4
        $dateTimeObject = \DateTimeImmutable::createFromFormat($format, $time, $timezone);
48 4
        $dateTimeObject->setTimezone(new DateTimeZone('UTC'));
49
50 4
        return new self($dateTimeObject->format(\DateTime::RFC2822));
0 ignored issues
show
Unused Code introduced by
The call to DateTimeBase::__construct() has too many arguments starting with $dateTimeObject->format(\DateTime::RFC2822).

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
51
    }
52
}
53