SpeechApi   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 3
dl 0
loc 40
c 0
b 0
f 0
rs 10
ccs 12
cts 12
cp 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B extractMeaning() 0 15 7
1
<?php
2
3
namespace Tgallice\Wit;
4
5
use Tgallice\Wit\Model\Context;
6
7
class SpeechApi
8
{
9
    use ResponseHandler;
10
11
    /**
12
     * @var Client
13
     */
14
    private $client;
15
16
    /**
17
     * @param Client $client
18
     */
19 6
    public function __construct(Client $client)
20
    {
21 6
        $this->client = $client;
22 6
    }
23
24
    /**
25
     * @param string|resource $file
26
     * @param array|null $context
27
     * @param array $queryParams
28
     *
29
     * @return array|null
30
     */
31 3
    public function extractMeaning($file, Context $context = null, array $queryParams = [])
32
    {
33 3
        if (!$file || (!is_resource($file) && !is_readable($file))) {
34 1
            throw new \InvalidArgumentException('$file argument must be a readable file path or a valid resource');
35
        }
36
37 2
        if (null !== $context && !$context->isEmpty()) {
38 1
            $queryParams['context'] = json_encode($context);
39 1
        }
40
41 2
        $file = is_resource($file) ? $file : fopen($file, 'r');
42 2
        $response = $this->client->send('POST', '/speech', $file, $queryParams);
43
44 2
        return $this->decodeResponse($response);
45
    }
46
}
47