DaysOfWeekStrategy   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 56
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 15 3
A getDayNames() 0 4 1
A daysMatch() 0 4 1
1
<?php
2
3
namespace Humweb\Features\Strategy;
4
5
use DateTime;
6
7
class DaysOfWeekStrategy extends AbstractStrategy
8
{
9
10
    protected $days = [
11
        1 => ['mon', 'monday'],
12
        2 => ['tue', 'tuesday'],
13
        3 => ['wed', 'wednesday'],
14
        4 => ['thu', 'thursday'],
15
        5 => ['fri', 'friday'],
16
        6 => ['sat', 'saturday'],
17
        7 => ['sun', 'sunday']
18
    ];
19
20
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function handle($args = [])
25
    {
26
27
        $days = (array)$this->argGet($args, 'days', []);
28
29
        $dayNames = $this->getDayNames();
30
31
        foreach ($days as $day) {
32
            if ($this->daysMatch($dayNames, $day)) {
33
                return true;
34
            }
35
        }
36
37
        return false;
38
    }
39
40
41
    /**
42
     * Get day name
43
     *
44
     * @return array
45
     */
46
    protected function getDayNames()
47
    {
48
        return $this->days[(new DateTime())->format('N')];
49
    }
50
51
52
    /**
53
     * @param array  $todayNames
54
     * @param string $matchDay
55
     *
56
     * @return bool
57
     */
58
    protected function daysMatch($todayNames, $matchDay)
59
    {
60
        return in_array(strtolower($matchDay), $todayNames);
61
    }
62
}
63