Booking   A
last analyzed

Complexity

Total Complexity 18

Size/Duplication

Total Lines 217
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 18
c 0
b 0
f 0
lcom 1
cbo 2
dl 0
loc 217
rs 10

17 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getId() 0 8 2
A setUser() 0 5 1
A getUser() 0 4 1
A setDate() 0 5 1
A getDate() 0 4 1
A setStartTime() 0 5 1
A getStartTime() 0 4 1
A setEndTime() 0 5 1
A getEndTime() 0 4 1
A setTotal() 0 5 1
A getTotal() 0 4 1
A setBalance() 0 5 1
A getBalance() 0 4 1
A setNotes() 0 5 1
A getNotes() 0 4 1
A jsonSerialize() 0 13 1
1
<?php
2
3
namespace JhFlexiTime\Entity;
4
5
use Doctrine\ORM\Mapping as ORM;
6
use ZfcUser\Entity\UserInterface;
7
use JhFlexiTime\DateTime\DateTime;
8
use JsonSerializable;
9
10
/**
11
 * Class Booking
12
 * @package JhFlexiTime\Entity
13
 * @author Ben Lill <[email protected]>
14
 *
15
 * @ORM\Entity
16
 * @ORM\Table(name="booking")
17
 */
18
class Booking implements JsonSerializable
19
{
20
21
    /**
22
     * @ORM\Id
23
     * @ORM\ManyToOne(targetEntity="JhUser\Entity\User")
24
     */
25
    protected $user = null;
26
27
    /**
28
     * @var DateTime
29
     *
30
     * @ORM\Id
31
     * @ORM\Column(type="date", name="date", nullable=false)
32
     */
33
    protected $date;
34
35
    /**
36
     * @var DateTime
37
     *
38
     * @ORM\Column(type="time", name="start_time", nullable=false)
39
     */
40
    protected $startTime;
41
42
    /**
43
     * @var DateTime
44
     *
45
     * @ORM\Column(type="time", name="end_time", nullable=false)
46
     */
47
    protected $endTime;
48
49
    /**
50
     * @var int
51
     *
52
     * @ORM\Column(type="string", length=255, nullable=false)
53
     */
54
    protected $total = 0;
55
56
    /**
57
     * @var int
58
     *
59
     * @ORM\Column(type="string", length=255, nullable=false)
60
     */
61
    protected $balance = 0;
62
63
    /** @var string
64
     *
65
     * @ORM\Column(type="string", length=512, nullable=true)
66
     */
67
    protected $notes = null;
68
69
    /**
70
     * Set Defaults
71
     */
72
    public function __construct()
73
    {
74
        $this->date         = new DateTime("today");
75
        $this->startTime    = new DateTime('09:00:00');
76
        $this->endTime      = new DateTime('17:30:00');
77
    }
78
79
    /**
80
     * @return string
81
     */
82
    public function getId()
83
    {
84
        if (!$this->user) {
85
            throw new \RuntimeException("No User is set. Needed to generate ID");
86
        }
87
88
        return $this->date->format('U') . "-" . $this->user->getId();
89
    }
90
91
    /**
92
     *
93
     * @param \ZfcUser\Entity\UserInterface $user
94
     * @return \JhFlexiTime\Entity\Booking
95
     */
96
    public function setUser(UserInterface $user)
97
    {
98
        $this->user = $user;
99
        return $this;
100
    }
101
102
    /**
103
     * @return \ZfcUser\Entity\UserInterface
104
     */
105
    public function getUser()
106
    {
107
        return $this->user;
108
    }
109
110
    /**
111
     * @param DateTime $date
112
     * @return \JhFlexiTime\Entity\Booking
113
     */
114
    public function setDate(DateTime $date)
115
    {
116
        $this->date = $date;
117
        return $this;
118
    }
119
120
    /**
121
     * @return DateTime
122
     */
123
    public function getDate()
124
    {
125
        return $this->date;
126
    }
127
128
    /**
129
     * @param DateTime $startTime
130
     * @return \JhFlexiTime\Entity\Booking
131
     */
132
    public function setStartTime(DateTime $startTime)
133
    {
134
        $this->startTime = $startTime;
135
        return $this;
136
    }
137
138
    /**
139
     * @return DateTime
140
     */
141
    public function getStartTime()
142
    {
143
        return $this->startTime;
144
    }
145
146
    /**
147
     * @param DateTime $endTime
148
     * @return \JhFlexiTime\Entity\Booking
149
     */
150
    public function setEndTime(DateTime $endTime)
151
    {
152
        $this->endTime = $endTime;
153
        return $this;
154
    }
155
156
    /**
157
     * @return DateTime
158
     */
159
    public function getEndTime()
160
    {
161
        return $this->endTime;
162
    }
163
164
    /**
165
     * @param string $total
166
     * @return \JhFlexiTime\Entity\Booking
167
     */
168
    public function setTotal($total)
169
    {
170
        $this->total = $total;
0 ignored issues
show
Documentation Bug introduced by
The property $total was declared of type integer, but $total is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
171
        return $this;
172
    }
173
174
    /**
175
     * @return string
176
     */
177
    public function getTotal()
178
    {
179
        return $this->total;
180
    }
181
182
    /**
183
     * @param int $balance
184
     * @return \JhFlexiTime\Entity\Booking
185
     */
186
    public function setBalance($balance)
187
    {
188
        $this->balance = $balance;
189
        return $this;
190
    }
191
192
    /**
193
     * @return int
194
     */
195
    public function getBalance()
196
    {
197
        return $this->balance;
198
    }
199
200
    /**
201
     * @param string $notes
202
     * @return \JhFlexiTime\Entity\Booking
203
     */
204
    public function setNotes($notes)
205
    {
206
        $this->notes = $notes;
207
        return $this;
208
    }
209
210
    /**
211
     * @return string
212
     */
213
    public function getNotes()
214
    {
215
        return $this->notes;
216
    }
217
218
    /**
219
     * @return array
220
     */
221
    public function jsonSerialize()
222
    {
223
        return [
224
            'id'        => $this->getId(),
225
            'user'      => $this->user->getId(),
226
            'date'      => $this->date->format('d-m-Y'),
227
            'startTime' => $this->startTime->format('H:i'),
228
            'endTime'   => $this->endTime->format('H:i'),
229
            'total'     => $this->total,
230
            'balance'   => $this->balance,
231
            'notes'     => $this->notes,
232
        ];
233
    }
234
}
235