Movement   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
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 33
ccs 0
cts 23
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B analyze() 0 30 4
1
<?php
2
3
namespace AppBundle\Action\Executor;
4
5
use AppBundle\Entity\Action;
6
use AppBundle\Entity\VarHook;
7
use AppBundle\Entity\Variable;
8
9
class Movement extends BaseExecutor implements ExecutorInterface
10
{
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