Downloadable   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 1
eloc 10
c 3
b 0
f 0
dl 0
loc 31
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A download() 0 16 1
1
<?php
2
3
namespace Picqer\Financials\Exact\Persistance;
4
5
use GuzzleHttp\Client;
6
use Picqer\Financials\Exact\Connection;
7
8
trait Downloadable
9
{
10
    /**
11
     * @return Connection
12
     */
13
    abstract public function connection();
14
15
    /**
16
     * @return string
17
     */
18
    abstract public function getDownloadUrl();
19
20
    /**
21
     * @return mixed Binary representation of file
22
     */
23
    public function download()
24
    {
25
        $client = new Client();
26
27
        $headers = [
28
            'Accept'        => 'application/json',
29
            'Content-Type'  => 'application/json',
30
            'Prefer'        => 'return=representation',
31
            'Authorization' => 'Bearer ' . $this->connection()->getAccessToken(),
32
        ];
33
34
        $res = $client->get($this->getDownloadUrl(), [
35
            'headers' => $headers,
36
        ]);
37
38
        return $res->getBody();
39
    }
40
}
41