Completed
Push — master ( 99411a...99411a )
by Hugo
30s queued 10s
created

Sounds   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 45
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A list() 0 6 1
A upload() 0 17 3
A delete() 0 10 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yproximite\WannaSpeakBundle\Api;
6
7
use Symfony\Component\Mime\Part\DataPart;
8
use Yproximite\WannaSpeakBundle\HttpClientInterface;
9
10
class Sounds implements SoundsInterface
11
{
12
    private $client;
13
14
    public function __construct(HttpClientInterface $client)
15
    {
16
        $this->client = $client;
17
    }
18
19
    public function list(array $additionalArguments = []): array
20
    {
21
        $response = $this->client->request(self::API, 'list', $additionalArguments);
22
23
        return $response->toArray(); // @phpstan-ignore-line
24
    }
25
26
    public function upload($file, string $name, array $additionalArguments = []): array
27
    {
28
        /** @var string|false $path */
29
        $path = is_string($file) ? $file : $file->getRealPath();
30
        if (false === $path) {
31
            throw new \InvalidArgumentException(sprintf('A string or an instance of "SplInfo" is required for uploading the file.'));
32
        }
33
34
        $arguments = array_merge($additionalArguments, [
35
            'sound' => DataPart::fromPath($path),
36
            'name'  => $name,
37
        ]);
38
39
        $response = $this->client->request(self::API, 'upload', $arguments);
40
41
        return $response->toArray(); // @phpstan-ignore-line
42
    }
43
44
    public function delete(string $name, array $additionalArguments = []): array
45
    {
46
        $arguments = array_merge($additionalArguments, [
47
            'name' => $name,
48
        ]);
49
50
        $response = $this->client->request(self::API, 'delete', $arguments);
51
52
        return $response->toArray(); // @phpstan-ignore-line
53
    }
54
}
55