Day   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 43
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A days() 0 12 1
A mapDays() 0 4 1
A isValid() 0 4 1
A onDateTime() 0 4 1
A toISO() 0 4 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 41
    public static function days(): array
19
    {
20
        return [
21 41
            static::MONDAY,
22 41
            static::TUESDAY,
23 41
            static::WEDNESDAY,
24 41
            static::THURSDAY,
25 41
            static::FRIDAY,
26 41
            static::SATURDAY,
27 41
            static::SUNDAY,
28
        ];
29
    }
30
31 41
    public static function mapDays(callable $callback): array
32
    {
33 41
        return Arr::map(Arr::mirror(static::days()), $callback);
34
    }
35
36 38
    public static function isValid(string $day): bool
37
    {
38 38
        return in_array($day, static::days());
39
    }
40
41 14
    public static function onDateTime(DateTimeInterface $dateTime): string
42
    {
43 14
        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