Api::uploadFile()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 2
b 0
f 0
nc 1
nop 1
dl 0
loc 11
ccs 0
cts 10
cp 0
crap 2
rs 10
1
<?php
2
3
namespace Distilleries\Contentful\Api\Upload;
4
5
use GuzzleHttp\RequestOptions;
6
use Distilleries\Contentful\Api\BaseApi;
7
use Distilleries\Contentful\Api\UploadApi;
8
9
class Api extends BaseApi implements UploadApi
10
{
11
    /**
12
     * {@inheritdoc}
13
     */
14
    protected $baseUrl = 'https://upload.contentful.com';
15
16
    /**
17
     * {@inheritdoc}
18
     */
19
    public function uploadFile(string $file): array
20
    {
21
        $response = $this->client->request('POST', $this->url('uploads'), [
22
            RequestOptions::BODY => file_get_contents($file),
23
            RequestOptions::HEADERS => [
24
                'Content-Type' => 'application/octet-stream',
25
                'Authorization' => 'Bearer ' . $this->config['tokens']['management'],
26
            ],
27
        ]);
28
29
        return $this->decodeResponse($response);
30
    }
31
}
32