GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#207)
by Freek
02:49
created

Period::duration()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 3
nc 3
nop 0
1
<?php
2
3
namespace Spatie\UptimeMonitor\Helpers;
4
5
use Carbon\Carbon;
6
use Spatie\UptimeMonitor\Exceptions\InvalidPeriod;
7
8
class Period
9
{
10
    public Carbon $startDateTime;
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_STRING, expecting T_FUNCTION or T_CONST
Loading history...
11
12
    public Carbon $endDateTime;
13
14
    public function __construct(Carbon $startDateTime, Carbon $endDateTime)
15
    {
16
        if ($startDateTime->gt($endDateTime)) {
17
            throw  InvalidPeriod::startDateMustComeBeforeEndDate($startDateTime, $endDateTime);
18
        }
19
20
        $this->startDateTime = $startDateTime;
21
22
        $this->endDateTime = $endDateTime;
23
    }
24
25
    public function duration(): string
26
    {
27
        $interval = $this->startDateTime->diff($this->endDateTime);
28
29
        if (! $this->startDateTime->diffInHours($this->endDateTime)) {
30
            return $interval->format('%im');
31
        }
32
33
        if (! $this->startDateTime->diffInDays($this->endDateTime)) {
34
            return $interval->format('%hh %im');
35
        }
36
37
        return $interval->format('%dd %hh %im');
38
    }
39
40
    public function toText(): string
41
    {
42
        $configuredDateFormat = config('uptime-monitor.notifications.date_format');
43
44
        return
45
            $this->startDateTime->format('H:i').' '
46
            .($this->startDateTime->isToday() ? '' : "on {$this->startDateTime->format($configuredDateFormat)} ")
47
            .'➡️ '
48
            .$this->endDateTime->format('H:i')
49
            .($this->endDateTime->isToday() ? '' : " on {$this->endDateTime->format($configuredDateFormat)}");
50
    }
51
}
52