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

Sounds::upload()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.7
c 0
b 0
f 0
cc 3
nc 4
nop 3
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