Completed
Push — master ( 289c61...45ac24 )
by Kirill
03:32
created

Movement   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 7
dl 0
loc 29
ccs 0
cts 19
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B analyze() 0 26 4
1
<?php
2
3
namespace AppBundle\Action\Executor;
4
5
use AppBundle\Entity\Action;
6
use AppBundle\Entity\Variable;
7
8
class Movement extends BaseExecutor implements ExecutorInterface
9
{
10
    public function analyze(Action $action)
11
    {
12
        $varService = $this->getContainer()->get('vars');
13
14
        $params = $action->getDevice()->getParams();
15
16
        /** @var Variable $variable */
17
        $variable = false;
18
19
        foreach ($params as $param) {
20
            list($p,$v) = explode(':', $param);
21
            if ($p=='variable') {
22
                $variable = $this->getDoctrine()->getManager()->getRepository('AppBundle:Variable')->findOneBy(['name'=>$v]);
23
                break;
24
            }
25
        }
26
27
        if (!$variable) {
28
            throw new \Exception("Sensor variable for device '".$action->getDevice()->getName()."' not found :(");
29
        }
30
31
        $lastValue = $varService->getLastValue($variable);
32
        /** @var \DateTime $lastPresence */
33
        $lastPresence = $lastValue['df'];
34
        $varService->set('room.lastPresence', time() - $lastPresence->getTimestamp());
35
    }
36
}
37