Lock   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 9
lcom 0
cbo 0
dl 0
loc 93
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A __toString() 0 11 1
A get_task_name() 0 4 1
A get_lock_id() 0 4 1
A get_timeout() 0 4 1
A get_lock_holder() 0 4 1
A get_expires() 0 4 1
A get_locked_at() 0 4 1
1
<?php
2
/**
3
 * Data object for locks.
4
 *
5
 * @author     Matthias Gisder <[email protected]>
6
 * @copyright  2014 inGenerator Ltd
7
 * @licence    BSD
8
 */
9
10
11
namespace Ingenerator\RunSingle;
12
13
14
class Lock
15
{
16
17
    const DATE_FORMAT = 'd/m/Y H:i:s';
18
19
    /**
20
     * @var string
21
     */
22
    protected $task_name;
23
24
    /**
25
     * @var string
26
     */
27
    protected $lock_id;
28
29
    /**
30
     * @var int
31
     */
32
    protected $timeout;
33
34
    /**
35
     * @var string
36
     */
37
    protected $lock_holder;
38
39
    /**
40
     * @var \DateTime
41
     */
42
    protected $expires;
43
44
    /**
45
     * @var \DateTime
46
     */
47
    protected $locked_at;
48
49
    /**
50
     * @param mixed[] $data
51
     */
52
    public function __construct($data)
53
    {
54
        foreach ($data as $key => $value) {
55
            $this->$key = $value;
56
        }
57
    }
58
59
    /**
60
     * Return a description of the lock.
61
     *
62
     * @return string
63
     */
64
    public function __toString()
65
    {
66
        return \sprintf("Lock %s for task %s taken by %s at %s with timeout %s expires at %s.",
67
            $this->get_lock_id(),
68
            $this->get_task_name(),
69
            $this->get_lock_holder(),
70
            $this->get_locked_at()->format(self::DATE_FORMAT),
71
            $this->get_timeout(),
72
            $this->get_expires()->format(self::DATE_FORMAT)
73
        );
74
    }
75
76
    public function get_task_name()
77
    {
78
        return $this->task_name;
79
    }
80
81
    public function get_lock_id()
82
    {
83
        return $this->lock_id;
84
    }
85
86
    public function get_timeout()
87
    {
88
        return $this->timeout;
89
    }
90
91
    public function get_lock_holder()
92
    {
93
        return $this->lock_holder;
94
    }
95
96
    public function get_expires()
97
    {
98
        return $this->expires;
99
    }
100
101
    public function get_locked_at()
102
    {
103
        return $this->locked_at;
104
    }
105
106
}
107