Passed
Push — master ( a62b41...518ca5 )
by Oliver
03:36
created

Day::onDateTime()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Webfactor\Laravel\OpeningHours\Entities;
4
5
use DateTimeInterface;
6
use Webfactor\Laravel\OpeningHours\Helpers\Arr;
7
8
class Day
9
{
10
    const MONDAY = 'monday';
11
    const TUESDAY = 'tuesday';
12
    const WEDNESDAY = 'wednesday';
13
    const THURSDAY = 'thursday';
14
    const FRIDAY = 'friday';
15
    const SATURDAY = 'saturday';
16
    const SUNDAY = 'sunday';
17
18 29
    public static function days(): array
19
    {
20
        return [
21 29
            static::MONDAY,
22 29
            static::TUESDAY,
23 29
            static::WEDNESDAY,
24 29
            static::THURSDAY,
25 29
            static::FRIDAY,
26 29
            static::SATURDAY,
27 29
            static::SUNDAY,
28
        ];
29
    }
30
31 29
    public static function mapDays(callable $callback): array
32
    {
33 29
        return Arr::map(Arr::mirror(static::days()), $callback);
34
    }
35
36 25
    public static function isValid(string $day): bool
37
    {
38 25
        return in_array($day, static::days());
39
    }
40
41 8
    public static function onDateTime(DateTimeInterface $dateTime): string
42
    {
43 8
        return static::days()[$dateTime->format('N') - 1];
44
    }
45
46 1
    public static function toISO(string $day): int
47
    {
48 1
        return array_search($day, static::days()) + 1;
49
    }
50
}
51