LogActivity::getDuration()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 5
nc 2
nop 0
1
<?php
2
3
namespace Cothema\Model\User;
4
5
use \Doctrine\ORM\Mapping as ORM;
6
use \Kdyby\Doctrine\Entities;
7
8
/**
9
 * @ORM\Entity
10
 * @ORM\Table(name="log_activity")
11
 */
12
class LogActivity extends Entities\BaseEntity
13
{
14
15
    use Entities\Attributes\Identifier;
16
17
    /**
18
     * @ORM\ManyToOne(targetEntity="User")
19
     * @ORM\JoinColumn(name="user", referencedColumnName="id")
20
     */
21
    public $user;
22
23
    /**
24
     * @ORM\Column(name="time_from", type="datetime")
25
     */
26
    public $timeFrom;
27
28
    /**
29
     * @ORM\Column(name="time_to", type="datetime")
30
     */
31
    public $timeTo;
32
33
    public function getDuration()
34
    {
35
        if (isset($this->timeFrom) && isset($this->timeTo)) {
36
            $diff = $this->timeFrom->diff($this->timeTo);
37
38
            return $diff->format('%h:%I:%S');
39
        }
40
41
        return null;
42
    }
43
}
44