Conditions | 4 |
Paths | 6 |
Total Lines | 30 |
Code Lines | 18 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 20 |
Changes | 0 |
1 | <?php |
||
11 | public function analyze(Action $action) |
||
12 | { |
||
13 | $varService = $this->getContainer()->get('vars'); |
||
14 | |||
15 | $params = $action->getDevice()->getParams(); |
||
16 | |||
17 | /** @var Variable $variable */ |
||
18 | $variable = false; |
||
19 | |||
20 | foreach ($params as $param) { |
||
21 | list($p, $v) = explode(':', $param); |
||
22 | if ($p == 'variable') { |
||
23 | $variable = $this-> |
||
24 | getDoctrine()-> |
||
25 | getManager()-> |
||
26 | getRepository('AppBundle:Variable')-> |
||
27 | findOneBy(['name'=>$v]); |
||
28 | break; |
||
29 | } |
||
30 | } |
||
31 | |||
32 | if (!$variable) { |
||
33 | throw new \Exception("Sensor variable for device '".$action->getDevice()->getName()."' not found :("); |
||
34 | } |
||
35 | |||
36 | $lastValue = $varService->getLastValue($variable); |
||
37 | /** @var \DateTime $lastPresence */ |
||
38 | $lastPresence = $lastValue['df']; |
||
39 | $varService->set('room.lastPresence', time() - $lastPresence->getTimestamp()); |
||
40 | } |
||
41 | } |
||
42 |