Completed
Push — master ( e9be36...9488e8 )
by Camilo
04:57
created

TelegramDocument   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
c 0
b 0
f 0
lcom 0
cbo 1
dl 0
loc 44
ccs 0
cts 8
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A __toString() 0 4 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace unreal4u\TelegramAPI\InternalFunctionality;
6
7
use Psr\Http\Message\ResponseInterface;
8
9
/**
10
 * Used when we download a file from Telegram, contains some important headers information that else would be lost
11
 */
12
class TelegramDocument
13
{
14
    /**
15
     * The mime type of this file
16
     * @var string
17
     */
18
    public $mime_type = '';
19
20
    /**
21
     * The actual contents of this file
22
     * @var string
23
     */
24
    public $contents = '';
25
26
    /**
27
     * The file size
28
     * @var int
29
     */
30
    public $file_size = 0;
31
32
    /**
33
     * Constructs a representable document
34
     *
35
     * @param ResponseInterface $response
36
     */
37
    public function __construct(ResponseInterface $response)
38
    {
39
        $headers = $response->getHeaders();
40
        // What better to get the mime type than what the Telegram servers already send us?
41
        $this->mime_type = $headers['Content-Type'][0];
42
        // Same with file length
43
        $this->file_size = $headers['Content-Length'][0];
44
        $this->contents = (string)$response->getBody();
45
    }
46
47
    /**
48
     * When called with string-ish functions, assume we want the actual contents of the file
49
     * @return string
50
     */
51
    public function __toString()
52
    {
53
        return $this->contents;
54
    }
55
}
56