Saytext   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 43
ccs 0
cts 29
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B say() 0 40 5
1
<?php
2
3
namespace AppBundle\Action\Executor;
4
5
use AppBundle\Entity\Action;
6
use AppBundle\Entity\Variable;
7
8
class Saytext extends BaseExecutor implements ExecutorInterface
9
{
10
    public function say(Action $action)
11
    {
12
        $args = json_decode($action->getArguments(), true);
13
14
        if (isset($this->parameters['text'])) {
15
            $text = $this->parameters['text'];
16
        } else {
17
            $text = $args['text'];
18
        }
19
20
        if (!$text) {
21
            return;
22
        }
23
24
        $textKey = md5($text);
25
26
        if (!file_exists($this->getContainer()->getParameter('kernel.cache_dir').'/voice')) {
27
            mkdir($this->getContainer()->getParameter('kernel.cache_dir').'/voice');
28
        }
29
30
        $file = $this->getContainer()->getParameter('kernel.cache_dir').'/voice/'.$textKey.'.mp3';
31
32
        $result = 'Played from cache';
33
34
        if (!file_exists($file)) {
35
            $res = file_get_contents(
36
                "http://translate.google.com/translate_tts?ie=UTF-8&client=tw-ob&q=".
37
                urlencode($text)."&tl=De_de"
38
            );
39
            file_put_contents($file, $res);
40
41
            $result = 'Saved in cache';
42
        }
43
44
        $res = exec('which mplayer');
45
46
        exec($res." -really-quiet -noconsolecontrols ".$file." >/dev/null 2>&1");
47
48
        return $result;
49
    }
50
}
51