VoiceAdapterFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 41
rs 10
c 1
b 0
f 0
ccs 0
cts 21
cp 0
wmc 4
lcom 0
cbo 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 22 3
1
<?php
2
3
namespace App\Actions\Voice;
4
5
use AudioManager\Adapter\Google;
6
use AudioManager\Adapter\Ivona;
7
use Staticus\Config\ConfigInterface;
8
use Staticus\Config\Config;
9
use Staticus\Exceptions\ErrorException;
10
11
class VoiceAdapterFactory
12
{
13
    const VOICE_PROVIDER_GOOGLE = 'google';
14
    const VOICE_PROVIDER_IVONA = 'ivona';
15
    /**
16
     * @var ConfigInterface|Config
17
     */
18
    protected $config;
19
20
    public function __construct(ConfigInterface $config)
21
    {
22
        $this->config = $config;
23
    }
24
25
    /**
26
     * @return \AudioManager\Adapter\AdapterInterface
27
     * @throws RuntimeException
28
     */
29
    public function __invoke()
30
    {
31
        $adapterName = strtolower($this->config->get('voice.provider', self::VOICE_PROVIDER_GOOGLE));
32
        switch ($adapterName) {
33
            case self::VOICE_PROVIDER_GOOGLE:
34
                $adapter = new Google();
35
                $adapter->getOptions()->setLanguage('en');
36
                $adapter->getOptions()->setEncoding('UTF-8');
37
                break;
38
            case self::VOICE_PROVIDER_IVONA:
39
                $secretKey = $this->config->get('voice.' . $adapterName . '.secret_key', '');
40
                $accessKey = $this->config->get('voice.' . $adapterName . '.access_key', '');
41
                $adapter = new Ivona();
42
                $adapter->getOptions()->setSecretKey($secretKey);
43
                $adapter->getOptions()->setAccessKey($accessKey);
44
                break;
45
            default:
46
                throw new ErrorException('Not implemented functionality for voice provider: ' . $adapterName);
47
        }
48
49
        return $adapter;
50
    }
51
}