Noolite   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 0
cbo 3
dl 0
loc 26
ccs 0
cts 19
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B toggle() 0 23 4
1
<?php
2
3
namespace AppBundle\Action\Executor;
4
5
use AppBundle\Entity\Action;
6
7
class Noolite extends BaseExecutor implements ExecutorInterface
8
{
9
    public function toggle(Action $action)
10
    {
11
        $device = $action->getDevice();
12
13
        $deviceParams = $device->getParams();
14
        $ch = 0;
15
        foreach ($deviceParams as $deviceParam) {
16
            list($param, $value) = explode(':', $deviceParam);
17
            if ($param == 'channel') {
18
                $ch = $value;
19
                break;
20
            }
21
        }
22
23
        if (!$ch) {
24
            throw new \Exception("Found device with undefined param!");
25
        }
26
27
        $actionArgs = json_decode($action->getArguments(), true);
28
        exec('/usr/local/bin/noolite -api -'.$actionArgs['state'].'_ch '.$ch);
29
30
        return "Switched device ".$actionArgs['state'].', channel '.$ch;
31
    }
32
}
33