Completed
Pull Request — master (#278)
by Pascale
03:06
created

AbstractTimeTable   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 53
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
handleConfiguration() 0 1 ?
A injectTimeTableService() 0 4 1
A buildSingleTimeTableByGroup() 0 4 1
A calculateEntryKey() 0 5 1
1
<?php
2
3
/**
4
 * Abstract time table service.
5
 */
6
declare(strict_types=1);
7
8
namespace HDNET\Calendarize\Service\TimeTable;
9
10
use HDNET\Calendarize\Domain\Model\Configuration;
11
use HDNET\Calendarize\Domain\Model\ConfigurationGroup;
12
use HDNET\Calendarize\Service\AbstractService;
13
use HDNET\Calendarize\Service\TimeTableService;
14
15
/**
16
 * Abstract time table service.
17
 */
18
abstract class AbstractTimeTable extends AbstractService
19
{
20
    /**
21
     * Seconds of 23:59:59 that mark the day end.
22
     */
23
    const DAY_END = 86399;
24
25
    /**
26
     * Time table service.
27
     *
28
     * @var \HDNET\Calendarize\Service\TimeTableService
29
     */
30
    protected $timeTableService;
31
32
    public function injectTimeTableService(TimeTableService $timeTableService)
33
    {
34
        $this->timeTableService = $timeTableService;
35
    }
36
37
    /**
38
     * Modify the given times via the configuration.
39
     *
40
     * @param array         $times
41
     * @param Configuration $configuration
42
     */
43
    abstract public function handleConfiguration(array &$times, Configuration $configuration);
44
45
    /**
46
     * Build a single time table by group.
47
     *
48
     * @param ConfigurationGroup $group
49
     *
50
     * @return array
51
     */
52
    protected function buildSingleTimeTableByGroup(ConfigurationGroup $group)
53
    {
54
        return $this->timeTableService->getTimeTablesByConfigurationIds($group->getConfigurationIds());
55
    }
56
57
    /**
58
     * Calculate a hash for the key of the given entry.
59
     * This prevent double entries in the index.
60
     *
61
     * @param array $entry
62
     *
63
     * @return string
64
     */
65
    protected function calculateEntryKey(array $entry)
66
    {
67
        // crc32 may be faster but have more collision-potential
68
        return \hash('md5', \json_encode($entry));
69
    }
70
}
71