Day   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A isWeekend() 0 4 1
A isHoliday() 0 16 4
1
<?php
2
3
namespace DateRanger\Period;
4
5
use DateRanger\DateRange;
6
use DateTimeImmutable;
7
8
class Day extends DateRange
9
{
10
    public $weekend = [6, 0];
11
    public $holidays = [
12
        '*-01-01', // Año nuevo
13
        '*-01-06', // Reyes
14
        '*-05-01', // Día del trabajador
15
        '*-06-01', // Fiesta local
16
        '*-06-24', // San Juan
17
        '*-08-15', // Asunción de la Virgen
18
        '*-09-11', // Diada
19
        '*-09-24', // La Mercé
20
        '*-10-12', // Dia Hispanidad
21
        '*-11-01', // Tots Sants
22
        '*-12-06', // Dia de la Constitución
23
        '*-12-08', // Immaculada Concepción
24
        '*-12-25', // Navidad
25
        '*-12-26', // San Esteban
26
27
        '2015-04-03', // Viernes Santo
28
        '2015-04-06', // Lunes de Pascua
29
        '2016-03-25', // Viernes Santo
30
        '2016-03-28', // Lunes de Pascua
31
        '2016-05-16', // Segunda Pascua
32
    ];
33
34 14
    public function __construct(?string $date_string = null)
35
    {
36 14
        $date = new DateTimeImmutable($date_string);
37
38 14
        $this->start = $date->setTime(0, 0, 0);
39 14
        $this->end = $date->setTime(23, 59, 59);
40
41 14
        $this->dates = [$date->setTime(0, 0, 0)];
42 14
    }
43
44 2
    public function isWeekend(): bool
45
    {
46 2
        return in_array((int) $this->start()->format('w'), $this->weekend, true);
47
    }
48
49 1
    public function isHoliday(): bool
50
    {
51 1
        if ($this->isWeekend()) {
52 1
            return true;
53
        }
54
55 1
        if (in_array($this->start->format('Y-m-d'), $this->holidays)) {
56 1
            return true;
57
        }
58
59 1
        if (in_array($this->start->format('*-m-d'), $this->holidays)) {
60 1
            return true;
61
        }
62
63 1
        return false;
64
    }
65
}
66