1 | <?php |
||
15 | class DbDriver implements LockDriver |
||
16 | { |
||
17 | |||
18 | const DATE_FORMAT = 'd/m/Y H:i:s'; |
||
19 | /** |
||
20 | * @var \Ingenerator\RunSingle\PdoDatabaseObject |
||
21 | */ |
||
22 | protected $db_object; |
||
23 | |||
24 | /** |
||
25 | * @var callable |
||
26 | */ |
||
27 | protected $timeProvider = 'time'; |
||
28 | |||
29 | /** |
||
30 | * @var \Psr\Log\LoggerInterface |
||
31 | */ |
||
32 | protected $logger; |
||
33 | |||
34 | /** |
||
35 | * @param \Ingenerator\RunSingle\PdoDatabaseObject $db_object |
||
36 | */ |
||
37 | public function __construct(PdoDatabaseObject $db_object) |
||
41 | |||
42 | /** |
||
43 | * @param callable $provider |
||
44 | */ |
||
45 | public function set_time_provider($provider) |
||
49 | |||
50 | /** |
||
51 | * @return int |
||
52 | */ |
||
53 | protected function get_time() |
||
58 | |||
59 | /** |
||
60 | * @param string $task_name |
||
61 | * @param int $timeout |
||
62 | * @param string $lock_holder |
||
63 | * |
||
64 | * @return false|integer |
||
65 | * @throws \Exception |
||
66 | * @throws \PDOException |
||
67 | */ |
||
68 | public function get_lock($task_name, $timeout, $lock_holder) |
||
89 | |||
90 | /** |
||
91 | * @param string $task_name |
||
92 | * |
||
93 | * @return void |
||
94 | */ |
||
95 | public function garbage_collect($task_name) |
||
110 | |||
111 | /** |
||
112 | * @param string $task_name |
||
113 | * @param int $lock_timestamp |
||
114 | * |
||
115 | * @return void |
||
116 | */ |
||
117 | public function release_lock($task_name, $lock_timestamp) |
||
125 | |||
126 | /** |
||
127 | * @param LoggerInterface $logger |
||
128 | */ |
||
129 | public function set_logger(LoggerInterface $logger) |
||
133 | |||
134 | /** |
||
135 | * Log only if logger is set. |
||
136 | * |
||
137 | * @param $level |
||
138 | * @param $message |
||
139 | */ |
||
140 | protected function log($level, $message) |
||
146 | |||
147 | /** |
||
148 | * @param array $result |
||
149 | * |
||
150 | * @return Lock |
||
151 | */ |
||
152 | protected function build_lock_object($result) |
||
166 | |||
167 | /** |
||
168 | * Return a list of locks. |
||
169 | * |
||
170 | * @return array |
||
171 | */ |
||
172 | public function list_locks() |
||
185 | |||
186 | } |
||
187 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.