Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
27 / 27
100.00% covered (success)
100.00%
8 / 8
CRAP
100.00% covered (success)
100.00%
1 / 1
Slot
100.00% covered (success)
100.00%
27 / 27
100.00% covered (success)
100.00%
8 / 8
15
100.00% covered (success)
100.00%
1 / 1
 getDefaults
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 setTime
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 hasTime
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
 getTimeString
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
3
 removeAppointment
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
3
 withAddedSlot
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
3
 __toString
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 __clone
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace BO\Zmsentities;
4
5class Slot extends Schema\Entity
6{
7    public static $schema = "slot.json";
8
9    /**
10     *  the values represent possible free appointments without confirmed
11     *  appointments
12     *
13     */
14    public const FREE = 'free';
15
16    /**
17     *  the values represent free appointments for a given day. Confirmed and
18     *  reserved appointments on processes are substracted.
19     */
20    public const TIMESLICE = 'timeslice';
21
22    /**
23     * like timeslice, but for more than one scope
24     */
25    public const SUM = 'sum';
26
27    /**
28     * like timeslice, but numbers were reduced due to required slots on a
29     * given request
30     *
31     */
32    public const REDUCED = 'reduced';
33
34    /**
35     * the values represent a unix timestamp to when there are free processes
36     *
37     */
38    public const TIMESTAMP = 'timestamp';
39
40    public function getDefaults()
41    {
42        return [
43            'public' => 0,
44            'intern' => 0,
45            'type' => self::FREE,
46        ];
47    }
48
49    public function setTime(Helper\DateTime $slotTime)
50    {
51        $this->time = $slotTime->format('H:i');
52    }
53
54    public function hasTime()
55    {
56        return ($this->toProperty()->time->get()) ? true : false;
57    }
58
59    public function getTimeString()
60    {
61        if (null === $this->toProperty()->time->get()) {
62            return '0:00';
63        }
64        if ($this->toProperty()->time->get() instanceof \DateTimeInterface) {
65            return $this['time']->format('H:i');
66        }
67        return $this->toProperty()->time->get();
68    }
69
70    public function removeAppointment()
71    {
72        if ($this->intern <= 0) {
73            throw new Exception\SlotFull("Could not remove another appointment from $this");
74        }
75        $this->intern = $this->intern - 1;
76        if ($this->public > 0) {
77            $this->public = $this->public - 1;
78        }
79        return $this;
80    }
81
82    public function withAddedSlot(Slot $slot)
83    {
84        $slot = clone $slot;
85        $slot->type = 'sum';
86        $slot->intern = (($slot->intern > 0) ? $slot->intern : 0) + (($this->intern > 0) ? $this->intern : 0);
87        $slot->public = $slot->public + $this->public;
88        return $slot;
89    }
90
91    public function __toString()
92    {
93        return "slot#{$this->type}@"
94            . "{$this->getTimeString()}"
95            . " p/i={$this->public}/{$this->intern}";
96    }
97
98    /**
99     * Keep empty, no sub-instances
100     * ATTENTION: Keep highly optimized, time critical function
101     */
102    public function __clone()
103    {
104    }
105}