Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
90.00% covered (success)
90.00%
18 / 20
88.89% covered (warning)
88.89%
8 / 9
CRAP
0.00% covered (danger)
0.00%
0 / 1
AvailabilitySnapShot
90.00% covered (success)
90.00%
18 / 20
88.89% covered (warning)
88.89%
8 / 9
11.12
0.00% covered (danger)
0.00%
0 / 1
 __construct
66.67% covered (warning)
66.67%
4 / 6
0.00% covered (danger)
0.00%
0 / 1
3.33
 hasOutdatedAvailability
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 hasOutdatedScope
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 hasOutdatedDayoff
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 hasBookableDateTime
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getLastBookableDateTime
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isOpenedOnLastBookableDay
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isTimeOpenedOnLastBookableDay
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 hasBookableDateTimeAfter
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace BO\Zmsdb\Helper;
4
5class AvailabilitySnapShot
6{
7    public function __construct(
8        \BO\Zmsentities\Availability $availability,
9        \DateTimeInterface $dateTime
10    ) {
11        if (! $availability->scope instanceof \BO\Zmsentities\Scope) {
12            throw new \Exception("Invalid Scope for AvailabilitySnapShot");
13        }
14        if (! $availability->scope->dayoff instanceof \BO\Zmsentities\Collection\DayoffList) {
15            throw new \Exception("Invalid DayoffList for AvailabilitySnapShot");
16        }
17        $this->availability = clone $availability;
18        $this->dateTime = $dateTime;
19    }
20
21    public function hasOutdatedAvailability()
22    {
23        // Lower compared date by one second to make a "<=" comparision
24        return $this->availability->isNewerThan($this->dateTime->modify("-1 second"));
25    }
26
27    public function hasOutdatedScope()
28    {
29        return $this->availability->scope->isNewerThan($this->dateTime);
30    }
31
32    public function hasOutdatedDayoff()
33    {
34        // It is sufficient to check, if current availability with dateTime is affected
35        // if a proposedChange could be affected, new slots have to be calculated, so checking already calculated slots
36        // is sufficient
37        return $this->availability->scope->dayoff->isNewerThan($this->dateTime, $this->availability, $this->dateTime);
38    }
39
40    public function hasBookableDateTime(\DateTimeInterface $proposedDateTime)
41    {
42        return $this->availability->hasDate($proposedDateTime, $this->dateTime);
43    }
44
45    public function getLastBookableDateTime()
46    {
47        return $this->availability->getBookableEnd($this->dateTime);
48    }
49
50    public function isOpenedOnLastBookableDay()
51    {
52        return $this->availability->isOpenedOnDate($this->availability->getBookableEnd($this->dateTime));
53    }
54
55    public function isTimeOpenedOnLastBookableDay()
56    {
57        return $this->availability->isOpened(
58            $this->availability->getBookableEnd($this->dateTime)->modify($this->dateTime->format('H:i:s'))
59        );
60    }
61
62    public function hasBookableDateTimeAfter(\DateTimeInterface $proposedDateTime)
63    {
64        return $this->availability->hasDateBetween(
65            $proposedDateTime,
66            $this->availability->getBookableEnd($this->dateTime),
67            $this->dateTime
68        );
69    }
70}